source: src-sh/pbi-manager/pbime/pbimount @ 4d6c087

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1
Last change on this file since 4d6c087 was 4d6c087, checked in by Kris Moore <kris@…>, 14 months ago

When doing PBI mounting, only do the pauses when an actual mount is happening, and
also make sure system "icons" are available in the container

  • Property mode set to 100755
File size: 4.0 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4
5MNTSLEEP="sleep 0.2"
6
7is_mounted() {
8   if [ ! -d "${1}" ] ; then return 1; fi
9   # Slow down the pace of nullfs mounts, this seems to fix the odd panic / hang
10   mount | grep -q "on ${1} (" 
11   return $?
12}
13
14check_pbidir() {
15  if [ -d "${1}/pbimeta" ] ; then return ; fi
16  echo "Error: Invalid PBI: ${1}"
17  exit 1
18}
19
20get_pdir() {
21  pDir="${1}"
22  if [ ! -d "${pDir}/virtbase" ] ; then
23    mkdir -p ${pDir}/virtbase
24  fi
25  if [ ! -d "${pDir}/run" ] ; then
26    mkdir -p ${pDir}/run
27  fi
28}
29
30mount_pbifile() {
31   if [ ! -d "$pDir" ] ; then
32      mkdir -p "${pDir}"
33   else
34      # Check to see if it is already mounted
35      mount | grep -q "on ${pDir} (ufs,"
36      if [ $? -eq 0 ] ; then return; fi
37   fi
38   MD=`mdconfig -a -t vnode -f ${1}`
39   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
40}
41
42mount_dirs() {
43
44   # Check some of the common items to mount into the PBI container
45   is_mounted "${pDir}/virtbase" || $NULLFS / "${pDir}/virtbase"
46   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
47   is_mounted "${pDir}/virtbase/usr/local" || ($MNTSLEEP ; $NULLFS ${1}/local "${pDir}/virtbase/usr/local" )
48   is_mounted "${pDir}/virtbase/var/run" || ($MNTSLEEP ; $NULLFS ${pDir}/run "${pDir}/virtbase/var/run" )
49   is_mounted "${pDir}/virtbase/compat/linux" || ($MNTSLEEP ; $NULLFS ${1}/linux "${pDir}/virtbase/compat/linux" )
50
51   # Sort out the items to mount into the PBI container
52   for i in `mount | grep -e "(zfs" -e "(smbfs" -e "(nfs" -e "(ufs" -e "(msdos" -e "(ntfs" | grep -e "on /" | grep -v "/usr/jails" | grep -v "/usr/pbi" | grep -v "/usr/local" | awk '{print $3}'`
53   do
54     if [ "$i" = "/" ] ; then continue ; fi
55     is_mounted "${pDir}/virtbase${i}" || ($MNTSLEEP ; $NULLFS ${i} "${pDir}/virtbase${i}" )
56   done
57
58   # Mount any system-wide fonts / cursors / icons into the PBI container
59   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
60      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || ($MNTSLEEP ; $NULLFS /usr/local/etc/fonts "${pDir}/virtbase/usr/local/etc/fonts" )
61   fi
62   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
63      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || ($MNTSLEEP ; $NULLFS /usr/local/lib/X11/fonts "${pDir}/virtbase/usr/local/lib/X11/fonts" )
64   fi
65   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
66      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || ($MNTSLEEP ; $NULLFS /usr/local/lib/X11/icons "${pDir}/virtbase/usr/local/lib/X11/icons" )
67   fi
68   if [ -d "${pDir}/virtbase/usr/local/share/icons" ] ; then
69      is_mounted "${pDir}/virtbase/usr/local/share/icons" || ($MNTSLEEP ; $NULLFS /usr/local/share/icons "${pDir}/virtbase/usr/local/share/icons" )
70   fi
71
72   # Check if we need to mount linprocfs in the PBI container
73   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
74      is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linproc "${pDir}/virtbase/compat/linux/proc"
75   fi
76
77   sync
78
79   sleep 0.1
80   # Copy over the system command
81   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/pbisyscmd"
82   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/openwith"
83   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/xdg-open"
84   chmod 755 "${pDir}/virtbase/usr/local/bin/pbisyscmd" 
85
86   # Copy the custom ldconfig
87   cp /usr/pbi/.ldconfig "${pDir}/virtbase/var/run/ldconfig"
88   chroot "${pDir}/virtbase" /var/run/ldconfig start >/dev/null 2>/dev/null
89   sync
90}
91
92umount_pbidir() {
93   for i in `mount | grep "on ${pDir}" | tail -r | awk '{print $3}'`
94   do
95     #echo "Unmounting ${i}"
96     umount -f ${i}
97     sleep 0.1
98   done
99}
100
101
102# Doing an unmount?
103if [ "$1" = "umount" ] ; then
104   get_pdir "$2"
105   umount_pbidir "$2"
106   exit 0
107fi
108
109if [ -z "$1" -o -z "$2" ] ; then
110   echo "Missing args: mountdir / pbidir"
111   exit 1
112fi
113
114MNTBASEDIR="`dirname $2`"
115
116if [ ! -d "$MNTBASEDIR" ] ; then
117   mkdir -p ${MNTBASEDIR}
118   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
119fi
120
121# Lets begin the mount process
122get_pdir "$1"
123check_pbidir "${2}"
124mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.