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

enter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since f8d250a was f8d250a, checked in by Kris Moore <kris@…>, 16 months ago

Add a check when doing PBI startup for linux compat, and if the PBI includes it, then
check the system for nvidia-driver and if both exist, do some magic to enable linux nvidia
accell

  • Property mode set to 100755
File size: 4.6 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4
5MNTSLEEP="sleep 0.2"
6
7is_mounted() {
8   if [ ! -d "${1}" ] ; then return 1; fi
9   # Slow down the pace of nullfs mounts, this seems to fix the odd panic / hang
10   mount | grep -q "on ${1} (" 
11   return $?
12}
13
14check_pbidir() {
15  if [ -d "${1}/pbimeta" ] ; then return ; fi
16  echo "Error: Invalid PBI: ${1}"
17  exit 1
18}
19
20get_pdir() {
21  pDir="${1}"
22  if [ ! -d "${pDir}/virtbase" ] ; then
23    mkdir -p ${pDir}/virtbase
24  fi
25  if [ ! -d "${pDir}/run" ] ; then
26    mkdir -p ${pDir}/run
27  fi
28}
29
30mount_pbifile() {
31   if [ ! -d "$pDir" ] ; then
32      mkdir -p "${pDir}"
33   else
34      # Check to see if it is already mounted
35      mount | grep -q "on ${pDir} (ufs,"
36      if [ $? -eq 0 ] ; then return; fi
37   fi
38   MD=`mdconfig -a -t vnode -f ${1}`
39   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
40}
41
42check_nvidia_linux()
43{
44   # Check if this PBI even has a linux compat layer with GL support
45   if [ ! -d "${1}/linux/usr/lib" ] ; then return; fi
46   ls ${1}/linux/usr/lib/libGL* 2>/dev/null >/dev/null
47   if [ $? -ne 0 ] ; then return ; fi
48
49   # Ok, we have linux compat in the PBI, is the system using nvidia?
50   pkg info -e nvidia-driver
51   if [ $? -ne 0 ] ; then return ; fi
52
53   # We have nvidia, lets do our linux lib population now
54   for i in `pkg info -l nvidia-driver 2>/dev/null | grep 'compat/linux/usr/lib' | awk '{print $1}'`
55   do
56      cp ${i} ${1}/linux/usr/lib/
57   done
58}
59
60mount_dirs() {
61
62   # Check some of the common items to mount into the PBI container
63   is_mounted "${pDir}/virtbase" || ( $NULLFS / "${pDir}/virtbase" ; check_nvidia_linux "${1}" )
64
65   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs "${pDir}/virtbase/dev"
66   is_mounted "${pDir}/virtbase/usr/local" || ($MNTSLEEP ; $NULLFS ${1}/local "${pDir}/virtbase/usr/local" )
67   is_mounted "${pDir}/virtbase/var/run" || ($MNTSLEEP ; $NULLFS ${pDir}/run "${pDir}/virtbase/var/run" )
68   is_mounted "${pDir}/virtbase/compat/linux" || ($MNTSLEEP ; $NULLFS ${1}/linux "${pDir}/virtbase/compat/linux" )
69
70   # Sort out the items to mount into the PBI container
71   for i in `mount | grep -e "(zfs" -e "(smbfs" -e "(nfs" -e "(ufs" -e "(msdos" -e "(ntfs" | grep -e "on /" | grep -v "/usr/jails" | grep -v "/usr/pbi" | grep -v "/usr/local" | awk '{print $3}'`
72   do
73     if [ "$i" = "/" ] ; then continue ; fi
74     is_mounted "${pDir}/virtbase${i}" || ($MNTSLEEP ; $NULLFS ${i} "${pDir}/virtbase${i}" )
75   done
76
77   # Mount any system-wide fonts / cursors / icons into the PBI container
78   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
79      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || ($MNTSLEEP ; $NULLFS /usr/local/etc/fonts "${pDir}/virtbase/usr/local/etc/fonts" )
80   fi
81   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
82      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || ($MNTSLEEP ; $NULLFS /usr/local/lib/X11/fonts "${pDir}/virtbase/usr/local/lib/X11/fonts" )
83   fi
84   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
85      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || ($MNTSLEEP ; $NULLFS /usr/local/lib/X11/icons "${pDir}/virtbase/usr/local/lib/X11/icons" )
86   fi
87   if [ -d "${pDir}/virtbase/usr/local/share/icons" ] ; then
88      is_mounted "${pDir}/virtbase/usr/local/share/icons" || ($MNTSLEEP ; $NULLFS /usr/local/share/icons "${pDir}/virtbase/usr/local/share/icons" )
89   fi
90
91   # Check if we need to mount linprocfs in the PBI container
92   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
93      is_mounted "${pDir}/virtbase/compat/linux/proc" || mount -t linprocfs linproc "${pDir}/virtbase/compat/linux/proc"
94   fi
95
96   sync
97
98   sleep 0.1
99   # Copy over the system command
100   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/pbisyscmd"
101   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/openwith"
102   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/xdg-open"
103   chmod 755 "${pDir}/virtbase/usr/local/bin/pbisyscmd" 
104
105   # Copy the custom ldconfig
106   cp /usr/pbi/.ldconfig "${pDir}/virtbase/var/run/ldconfig"
107   chroot "${pDir}/virtbase" /var/run/ldconfig start >/dev/null 2>/dev/null
108
109   sync
110}
111
112umount_pbidir() {
113   for i in `mount | grep "on ${pDir}" | tail -r | awk '{print $3}'`
114   do
115     #echo "Unmounting ${i}"
116     umount -f ${i}
117     sleep 0.1
118   done
119}
120
121
122# Doing an unmount?
123if [ "$1" = "umount" ] ; then
124   get_pdir "$2"
125   umount_pbidir "$2"
126   exit 0
127fi
128
129if [ -z "$1" -o -z "$2" ] ; then
130   echo "Missing args: mountdir / pbidir"
131   exit 1
132fi
133
134MNTBASEDIR="`dirname $2`"
135
136if [ ! -d "$MNTBASEDIR" ] ; then
137   mkdir -p ${MNTBASEDIR}
138   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
139fi
140
141# Lets begin the mount process
142get_pdir "$1"
143check_pbidir "${2}"
144mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.