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

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

Fix some bugs with relative file pathnames in pbifs, and make sure to load
procfs / linprocfs / linsysfs in PBIs

  • Property mode set to 100755
File size: 3.1 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   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
72     is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linprocfs "${pDir}/virtbase/compat/linux/proc"
73   fi
74   if [ -d "${pDir}/virtbase/compat/linux/sys" ] ; then
75     is_mounted "${pDir}/virtbase/compat/linux/sys" || mount -t linsysfs linsysfs "${pDir}/virtbase/compat/linux/sys"
76   fi
77
78   # Check if we need to enable nvidia support for linux
79   check_nvidia_linux "$1"
80
81   # Start devfs to ensure /dev/* get proper permissions
82   chroot "${pDir}/virtbase" /etc/rc.d/devfs start >/dev/null 2>/dev/null
83
84   # Start the ldconfig run
85   chroot "${pDir}/virtbase" /etc/rc.d/ldconfig start >/dev/null 2>/dev/null
86
87   sleep 1
88}
89
90umount_pbidir() {
91   for i in `mount | grep "on ${pDir}/virtbase" | tail -r | awk '{print $3}'`
92   do
93     #echo "Unmounting ${i}"
94     umount ${i}
95     sleep 0.5
96   done
97}
98
99
100# Doing an unmount?
101if [ "$1" = "umount" ] ; then
102   get_pdir "$2"
103   umount_pbidir "$2"
104   exit 0
105fi
106
107if [ -z "$1" -o -z "$2" ] ; then
108   echo "Missing args: mountdir / pbidir"
109   exit 1
110fi
111
112MNTBASEDIR="`dirname $2`"
113
114if [ ! -d "$MNTBASEDIR" ] ; then
115   mkdir -p ${MNTBASEDIR}
116   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
117fi
118
119# Lets begin the mount process
120get_pdir "$1"
121check_pbidir "${2}"
122mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.