source: src-sh/pbi-manager/pbime/pbimount @ 6542c9a

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

Cleanup pbimounter a bit more, pause after doing nullfs mounts, and checking for mount-points

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