source: src-sh/pbi-manager/pbime/pbimount @ 14b47f0

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

Fix a bug, only mount pbifs a single time

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