source: src-sh/pbi-manager/pbime/pbimount @ 6330d7c

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

Huge update to pbi-managger for 10.0

Welcome our new "pbifs" FUSE launcher. This will replace about a dozen "nullfs" mounts
used to create a virtual "PBI" container with a single fuse mount, which internally does
all the mapping required to create virtual /usr/local namespaces.

This update should hopefully also improve stability going forward

  • Property mode set to 100755
File size: 3.2 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
61do_mount_lock() {
62
63   # At this point we have waited 15 seconds, if another mount still hasn't finished
64   # by now then there are other serious problems
65   if [ $1 -gt 10 ] ; then
66      exit 1
67   fi
68
69   # Check if we have another mount going now
70   if [ -e "${MNTLOCK}" ] ; then
71      pgrep -qF ${MNTLOCK} 2>/dev/null
72      if [ $? -ne 0 ] ; then
73         # Expired run it seems
74         rm -f ${MNTLOCK} 2>/dev/null
75      else
76         # Another mount is running, wait a bit for it to finish
77         sleep 1.5
78         do_mount_lock "`expr $1 + 1`"
79         return
80      fi
81   fi
82
83   echo "$$" > ${MNTLOCK}
84}
85
86undo_mount_lock() {
87  rm -f ${MNTLOCK} >/dev/null 2>/dev/null
88}
89
90mount_dirs() {
91
92   # Mount our FUSE file-system
93   /usr/pbi/.pbifs ${1} ${pDir}/run ${pDir}/virtbase
94
95   # Can't get rid of these nullfs / devfs mounts, needed for unix sockets to work
96   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
97   is_mounted "${pDir}/virtbase/tmp" || mount_nullfs /tmp "${pDir}/virtbase/tmp"
98
99   # Start the ldconfig run
100   chroot "${pDir}/virtbase" /etc/rc.d/ldconfig start >/dev/null 2>/dev/null
101
102   # Start devfs to ensure /dev/* get proper permissions
103   chroot "${pDir}/virtbase" /etc/rc.d/devfs start >/dev/null 2>/dev/null
104}
105
106umount_pbidir() {
107   for i in `mount | grep "on ${pDir}/virtbase" | tail -r | awk '{print $3}'`
108   do
109     #echo "Unmounting ${i}"
110     umount ${i}
111     sleep 0.5
112   done
113}
114
115
116# Doing an unmount?
117if [ "$1" = "umount" ] ; then
118   get_pdir "$2"
119   umount_pbidir "$2"
120   exit 0
121fi
122
123if [ -z "$1" -o -z "$2" ] ; then
124   echo "Missing args: mountdir / pbidir"
125   exit 1
126fi
127
128MNTBASEDIR="`dirname $2`"
129
130if [ ! -d "$MNTBASEDIR" ] ; then
131   mkdir -p ${MNTBASEDIR}
132   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
133fi
134
135# Lets begin the mount process
136get_pdir "$1"
137check_pbidir "${2}"
138mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.