source: src-sh/pbi-manager/pbime/pbimount @ c031385

releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since c031385 was c031385, checked in by Kris Moore <kris@…>, 10 months ago

Fix two bugs:

  • Set proper perms on /dev/* entries inside PBI container
  • Add some locking when doing nullfs mounts, since doing two at once seems to deadlock the system
  • Property mode set to 100755
File size: 5.4 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4MNTLOCK="/usr/pbi/.mntLock"
5MNTSLEEP="sleep 0.2"
6
7is_mounted() {
8   if [ ! -d "${1}" ] ; then return 1; fi
9   mount | grep -q "on ${1} (" 
10   return $?
11}
12
13check_pbidir() {
14  if [ -d "${1}/pbimeta" ] ; then return ; fi
15  echo "Error: Invalid PBI: ${1}"
16  exit 1
17}
18
19get_pdir() {
20  pDir="${1}"
21  if [ ! -d "${pDir}/virtbase" ] ; then
22    mkdir -p ${pDir}/virtbase
23  fi
24  if [ ! -d "${pDir}/run" ] ; then
25    mkdir -p ${pDir}/run
26  fi
27}
28
29mount_pbifile() {
30   if [ ! -d "$pDir" ] ; then
31      mkdir -p "${pDir}"
32   else
33      # Check to see if it is already mounted
34      mount | grep -q "on ${pDir} (ufs,"
35      if [ $? -eq 0 ] ; then return; fi
36   fi
37   MD=`mdconfig -a -t vnode -f ${1}`
38   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
39}
40
41check_nvidia_linux()
42{
43   # Check if this PBI even has a linux compat layer with GL support
44   if [ ! -d "${1}/linux/usr/lib" ] ; then return; fi
45   ls ${1}/linux/usr/lib/libGL* 2>/dev/null >/dev/null
46   if [ $? -ne 0 ] ; then return ; fi
47
48   # Ok, we have linux compat in the PBI, is the system using nvidia?
49   pkg info -e nvidia-driver
50   if [ $? -ne 0 ] ; then return ; fi
51
52   # We have nvidia, lets do our linux lib population now
53   for i in `pkg info -l nvidia-driver 2>/dev/null | grep 'compat/linux/usr/lib' | awk '{print $1}'`
54   do
55      cp ${i} ${1}/linux/usr/lib/
56   done
57}
58
59do_mount_lock() {
60
61   # At this point we have waited 15 seconds, if another mount still hasn't finished
62   # by now then there are other serious problems
63   if [ $1 -gt 10 ] ; then
64      exit 1
65   fi
66
67   # Check if we have another mount going now
68   if [ -e "${MNTLOCK}" ] ; then
69      pgrep -qF ${MNTLOCK} 2>/dev/null
70      if [ $? -ne 0 ] ; then
71         # Expired run it seems
72         rm -f ${MNTLOCK} 2>/dev/null
73      else
74         # Another mount is running, wait a bit for it to finish
75         sleep 1.5
76         do_mount_lock "`expr $1 + 1`"
77         return
78      fi
79   fi
80
81   echo "$$" > ${MNTLOCK}
82}
83
84undo_mount_lock() {
85  rm -f ${MNTLOCK} >/dev/null 2>/dev/null
86}
87
88mount_dirs() {
89
90   do_mount_lock "1"
91
92   # Check some of the common items to mount into the PBI container
93   is_mounted "${pDir}/virtbase" || ( $NULLFS / "${pDir}/virtbase" ; check_nvidia_linux "${1}" )
94
95   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
96   is_mounted "${pDir}/virtbase/usr/local" || ($MNTSLEEP ; $NULLFS ${1}/local "${pDir}/virtbase/usr/local" )
97   is_mounted "${pDir}/virtbase/var/run" || ($MNTSLEEP ; $NULLFS ${pDir}/run "${pDir}/virtbase/var/run" )
98   is_mounted "${pDir}/virtbase/compat/linux" || ($MNTSLEEP ; $NULLFS ${1}/linux "${pDir}/virtbase/compat/linux" )
99
100   # Sort out the items to mount into the PBI container
101   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}'`
102   do
103     if [ "$i" = "/" ] ; then continue ; fi
104     is_mounted "${pDir}/virtbase${i}" || ($MNTSLEEP ; $NULLFS ${i} "${pDir}/virtbase${i}" )
105   done
106
107   # Mount any system-wide fonts / cursors / icons into the PBI container
108   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
109      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || ($MNTSLEEP ; $NULLFS /usr/local/etc/fonts "${pDir}/virtbase/usr/local/etc/fonts" )
110   fi
111   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
112      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || ($MNTSLEEP ; $NULLFS /usr/local/lib/X11/fonts "${pDir}/virtbase/usr/local/lib/X11/fonts" )
113   fi
114   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
115      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || ($MNTSLEEP ; $NULLFS /usr/local/lib/X11/icons "${pDir}/virtbase/usr/local/lib/X11/icons" )
116   fi
117   if [ -d "${pDir}/virtbase/usr/local/share/icons" ] ; then
118      is_mounted "${pDir}/virtbase/usr/local/share/icons" || ($MNTSLEEP ; $NULLFS /usr/local/share/icons "${pDir}/virtbase/usr/local/share/icons" )
119   fi
120
121   # Check if we need to mount linprocfs in the PBI container
122   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
123      is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linproc "${pDir}/virtbase/compat/linux/proc"
124   fi
125
126   undo_mount_lock
127
128   sync
129
130   sleep 0.1
131   # Copy over the system command
132   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/pbisyscmd"
133   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/openwith"
134   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/xdg-open"
135   chmod 755 "${pDir}/virtbase/usr/local/bin/pbisyscmd" 
136
137   # Copy the custom ldconfig
138   cp /usr/pbi/.ldconfig "${pDir}/virtbase/var/run/ldconfig"
139   chroot "${pDir}/virtbase" /var/run/ldconfig start >/dev/null 2>/dev/null
140
141   # Start devfs to ensure /dev/* get proper permissions
142   chroot "${pDir}/virtbase" /etc/rc.d/devfs start >/dev/null 2>/dev/null
143
144   sync
145}
146
147umount_pbidir() {
148   for i in `mount | grep "on ${pDir}" | tail -r | awk '{print $3}'`
149   do
150     #echo "Unmounting ${i}"
151     umount -f ${i}
152     sleep 0.1
153   done
154}
155
156
157# Doing an unmount?
158if [ "$1" = "umount" ] ; then
159   get_pdir "$2"
160   umount_pbidir "$2"
161   exit 0
162fi
163
164if [ -z "$1" -o -z "$2" ] ; then
165   echo "Missing args: mountdir / pbidir"
166   exit 1
167fi
168
169MNTBASEDIR="`dirname $2`"
170
171if [ ! -d "$MNTBASEDIR" ] ; then
172   mkdir -p ${MNTBASEDIR}
173   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
174fi
175
176# Lets begin the mount process
177get_pdir "$1"
178check_pbidir "${2}"
179mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.