source: src-sh/pbi-manager/pbime/pbimount @ 1fa5bc4

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

We can start devfs before doing ldconfig in pbi container

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