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

releng/10.0
Last change on this file since ec4b304 was ec4b304, checked in by Kris Moore <kris@…>, 7 months ago

Some fixes when removing / unmounting a PBI container on 10.0

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