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

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

Update to the PBI startup routine

  • Speed up the startup time of PBIs by about 50%
  • Make sure user-mounted media / dirs are available in the container
  • Cleanup how we umount the container, parse the actual mounted list
  • Property mode set to 100755
File size: 3.7 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4
5is_mounted() {
6   if [ ! -d "${1}" ] ; then return 1; fi
7   # Slow down the pace of nullfs mounts, this seems to fix the odd panic / hang
8   sleep 0.1
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
41mount_dirs() {
42
43   # Check some of the common items to mount into the PBI container
44   is_mounted "${pDir}/virtbase" || $NULLFS / "${pDir}/virtbase"
45   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
46   is_mounted "${pDir}/virtbase/usr/local" || $NULLFS ${1}/local "${pDir}/virtbase/usr/local"
47   is_mounted "${pDir}/virtbase/var/run" || $NULLFS ${pDir}/run "${pDir}/virtbase/var/run"
48   is_mounted "${pDir}/virtbase/compat/linux" || $NULLFS ${1}/linux "${pDir}/virtbase/compat/linux"
49
50   # Sort out the items to mount into the PBI container
51   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}'`
52   do
53     if [ "$i" = "/" ] ; then continue ; fi
54     is_mounted "${pDir}/virtbase${i}" || $NULLFS ${i} "${pDir}/virtbase${i}"
55   done
56
57   # Mount any system-wide fonts / cursors / icons into the PBI container
58   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
59      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || $NULLFS /usr/local/etc/fonts "${pDir}/virtbase/usr/local/etc/fonts"
60   fi
61   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
62      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || $NULLFS /usr/local/lib/X11/fonts "${pDir}/virtbase/usr/local/lib/X11/fonts"
63   fi
64   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
65      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || $NULLFS /usr/local/lib/X11/icons "${pDir}/virtbase/usr/local/lib/X11/icons"
66   fi
67
68   # Check if we need to mount linprocfs in the PBI container
69   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
70      is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linproc "${pDir}/virtbase/compat/linux/proc"
71   fi
72
73   sync
74
75   # Copy over the system command
76   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/pbisyscmd"
77   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/openwith"
78   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/xdg-open"
79   chmod 755 "${pDir}/virtbase/usr/local/bin/pbisyscmd" 
80
81   # Copy the custom ldconfig
82   cp /usr/pbi/.ldconfig "${pDir}/virtbase/var/run/ldconfig"
83   chroot "${pDir}/virtbase" /var/run/ldconfig start >/dev/null 2>/dev/null
84   sleep 0.2
85   sync
86}
87
88umount_pbidir() {
89   for i in `mount | grep "on ${pDir}" | tail -r | awk '{print $3}'`
90   do
91     echo "Unmounting ${i}"
92     umount -f ${i}
93     sleep 0.1
94   done
95}
96
97
98# Doing an unmount?
99if [ "$1" = "umount" ] ; then
100   get_pdir "$2"
101   umount_pbidir "$2"
102   exit 0
103fi
104
105if [ -z "$1" -o -z "$2" ] ; then
106   echo "Missing args: mountdir / pbidir"
107   exit 1
108fi
109
110MNTBASEDIR="`dirname $2`"
111
112if [ ! -d "$MNTBASEDIR" ] ; then
113   mkdir -p ${MNTBASEDIR}
114   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
115fi
116
117# Lets begin the mount process
118get_pdir "$1"
119check_pbidir "${2}"
120mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.