source: src-sh/pbi-manager/pbime/pbimount @ 6d736fb

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

Add a nullfs backed "socket" passthrough layer to pbifs, this allows sockets in
/var/run to be available to PBIs, same as in /tmp

This fixes bugs with CUPS not being able to work in PBIs

  • Property mode set to 100755
File size: 3.4 KB
Line 
1#!/bin/sh
2
3MNTLOCK="/usr/pbi/.mntLock"
4MNTSLEEP="sleep 0.5"
5
6# Grab list of current mounted file-systems
7mntOutput="`mount`"
8
9is_mounted() {
10   if [ ! -d "${1}" ] ; then return 1; fi
11   echo ${mntOutput} | grep -q "on ${1} ("
12   return $?
13}
14
15check_pbidir() {
16  if [ -d "${1}/pbimeta" ] ; then return ; fi
17  echo "Error: Invalid PBI: ${1}"
18  exit 1
19}
20
21get_pdir() {
22  pDir="${1}"
23  if [ ! -d "${pDir}/virtbase" ] ; then
24    mkdir -p ${pDir}/virtbase
25  fi
26  if [ ! -d "${pDir}/run" ] ; then
27    mkdir -p ${pDir}/run
28  fi
29}
30
31mount_pbifile() {
32   if [ ! -d "$pDir" ] ; then
33      mkdir -p "${pDir}"
34   else
35      # Check to see if it is already mounted
36      mount | grep -q "on ${pDir} (ufs,"
37      if [ $? -eq 0 ] ; then return; fi
38   fi
39   MD=`mdconfig -a -t vnode -f ${1}`
40   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
41}
42
43check_nvidia_linux()
44{
45   # Check if this PBI even has a linux compat layer with GL support
46   if [ ! -d "${1}/linux/usr/lib" ] ; then return; fi
47   ls ${1}/linux/usr/lib/libGL* 2>/dev/null >/dev/null
48   if [ $? -ne 0 ] ; then return ; fi
49
50   # Ok, we have linux compat in the PBI, is the system using nvidia?
51   pkg info -e nvidia-driver
52   if [ $? -ne 0 ] ; then return ; fi
53
54   # We have nvidia, lets do our linux lib population now
55   for i in `pkg info -l nvidia-driver 2>/dev/null | grep 'compat/linux/usr/lib' | awk '{print $1}'`
56   do
57      cp ${i} ${1}/linux/usr/lib/
58   done
59}
60
61mount_dirs() {
62
63   # Mount our FUSE file-system
64   is_mounted "${pDir}/virtbase" || /usr/pbi/.pbifs ${1} ${pDir}/run ${pDir}/virtbase
65
66   # Can't get rid of these nullfs / devfs mounts, needed for unix sockets to work
67   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
68   is_mounted "${pDir}/virtbase/proc" || mount -t procfs procfs "${pDir}/virtbase/proc"
69   is_mounted "${pDir}/virtbase/tmp" || mount_nullfs /tmp "${pDir}/virtbase/tmp"
70
71   # Mount our real system /var/run with nullfs, so that sockets are available which tend
72   # to exist there
73   if [ ! -d "/usr/pbi/varrun" ] ; then
74      mkdir /usr/pbi/varrun
75   fi
76   is_mounted "${pDir}/virtbase/usr/pbi/varrun" || mount_nullfs /var/run "${pDir}/virtbase/usr/pbi/varrun"
77
78   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
79     is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linprocfs "${pDir}/virtbase/compat/linux/proc"
80   fi
81   if [ -d "${pDir}/virtbase/compat/linux/sys" ] ; then
82     is_mounted "${pDir}/virtbase/compat/linux/sys" || mount -t linsysfs linsysfs "${pDir}/virtbase/compat/linux/sys"
83   fi
84
85   # Check if we need to enable nvidia support for linux
86   check_nvidia_linux "$1"
87
88   # Start devfs to ensure /dev/* get proper permissions
89   chroot "${pDir}/virtbase" /etc/rc.d/devfs start >/dev/null 2>/dev/null
90
91   # Start the ldconfig run
92   chroot "${pDir}/virtbase" /etc/rc.d/ldconfig start >/dev/null 2>/dev/null
93
94   sleep 1
95}
96
97umount_pbidir() {
98   for i in `mount | grep "on ${pDir}/virtbase" | tail -r | awk '{print $3}'`
99   do
100     #echo "Unmounting ${i}"
101     umount ${i}
102     sleep 0.5
103   done
104}
105
106
107# Doing an unmount?
108if [ "$1" = "umount" ] ; then
109   get_pdir "$2"
110   umount_pbidir "$2"
111   exit 0
112fi
113
114if [ -z "$1" -o -z "$2" ] ; then
115   echo "Missing args: mountdir / pbidir"
116   exit 1
117fi
118
119MNTBASEDIR="`dirname $2`"
120
121if [ ! -d "$MNTBASEDIR" ] ; then
122   mkdir -p ${MNTBASEDIR}
123   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
124fi
125
126# Lets begin the mount process
127get_pdir "$1"
128check_pbidir "${2}"
129mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.