source: src-sh/pbi-manager/pbime/pbimount @ 58035e0

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

Update pbimount with patch to support other font directories to be
mounted into PBI container. Fixes issues with vlgothic font among others.

Trac:

https://trac.pcbsd.org/ticket/1032

Thanks to: yamajun

  • Property mode set to 100755
File size: 6.4 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4MNTLOCK="/usr/pbi/.mntLock"
5MNTSLEEP="sleep 0.5"
6
7# Grab list of current mounted file-systems
8mntOutput="`mount`"
9
10is_mounted() {
11   if [ ! -d "${1}" ] ; then return 1; fi
12   echo ${mntOutput} | grep -q "on ${1} ("
13   return $?
14}
15
16check_pbidir() {
17  if [ -d "${1}/pbimeta" ] ; then return ; fi
18  echo "Error: Invalid PBI: ${1}"
19  exit 1
20}
21
22get_pdir() {
23  pDir="${1}"
24  if [ ! -d "${pDir}/virtbase" ] ; then
25    mkdir -p ${pDir}/virtbase
26  fi
27  if [ ! -d "${pDir}/run" ] ; then
28    mkdir -p ${pDir}/run
29  fi
30}
31
32mount_pbifile() {
33   if [ ! -d "$pDir" ] ; then
34      mkdir -p "${pDir}"
35   else
36      # Check to see if it is already mounted
37      mount | grep -q "on ${pDir} (ufs,"
38      if [ $? -eq 0 ] ; then return; fi
39   fi
40   MD=`mdconfig -a -t vnode -f ${1}`
41   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
42}
43
44check_nvidia_linux()
45{
46   # Check if this PBI even has a linux compat layer with GL support
47   if [ ! -d "${1}/linux/usr/lib" ] ; then return; fi
48   ls ${1}/linux/usr/lib/libGL* 2>/dev/null >/dev/null
49   if [ $? -ne 0 ] ; then return ; fi
50
51   # Ok, we have linux compat in the PBI, is the system using nvidia?
52   pkg info -e nvidia-driver
53   if [ $? -ne 0 ] ; then return ; fi
54
55   # We have nvidia, lets do our linux lib population now
56   for i in `pkg info -l nvidia-driver 2>/dev/null | grep 'compat/linux/usr/lib' | awk '{print $1}'`
57   do
58      cp ${i} ${1}/linux/usr/lib/
59   done
60}
61
62do_mount_lock() {
63
64   # At this point we have waited 15 seconds, if another mount still hasn't finished
65   # by now then there are other serious problems
66   if [ $1 -gt 10 ] ; then
67      exit 1
68   fi
69
70   # Check if we have another mount going now
71   if [ -e "${MNTLOCK}" ] ; then
72      pgrep -qF ${MNTLOCK} 2>/dev/null
73      if [ $? -ne 0 ] ; then
74         # Expired run it seems
75         rm -f ${MNTLOCK} 2>/dev/null
76      else
77         # Another mount is running, wait a bit for it to finish
78         sleep 1.5
79         do_mount_lock "`expr $1 + 1`"
80         return
81      fi
82   fi
83
84   echo "$$" > ${MNTLOCK}
85}
86
87undo_mount_lock() {
88  rm -f ${MNTLOCK} >/dev/null 2>/dev/null
89}
90
91mount_dirs() {
92
93   do_mount_lock "1"
94
95   # Check some of the common items to mount into the PBI container
96   is_mounted "${pDir}/virtbase" || ( $NULLFS / "${pDir}/virtbase" ; $MNTSLEEP ; check_nvidia_linux "${1}" )
97
98   is_mounted "${pDir}/virtbase/dev" || (mount -t devfs devfs "${pDir}/virtbase/dev" ; $MNTSLEEP )
99   is_mounted "${pDir}/virtbase/usr/local" || ($NULLFS ${1}/local "${pDir}/virtbase/usr/local" ; $MNTSLEEP )
100   is_mounted "${pDir}/virtbase/var/run" || ($NULLFS ${pDir}/run "${pDir}/virtbase/var/run" ; $MNTSLEEP )
101   if [ -d "/var/run/dbus" ] ; then
102     is_mounted "${pDir}/virtbase/var/run/dbus" || ( mkdir ${pDir}/virtbase/var/run/dbus 2>/dev/null ; $NULLFS /var/run/dbus "${pDir}/virtbase/var/run/dbus" ; $MNTSLEEP )
103   fi
104
105   # If the host has Linux compat
106   if [ -d "${pDir}/virtbase/compat/linux" ] ; then
107     is_mounted "${pDir}/virtbase/compat/linux" || ($NULLFS ${1}/linux "${pDir}/virtbase/compat/linux" ; $MNTSLEEP )
108   fi
109
110   # Sort out the items to mount into the PBI container
111   for i in `mount | grep -e "(zfs" -e "(smbfs" -e "(nfs" -e "(ufs" -e "(msdos" -e "(ntfs" -e "(fusefs" | grep -e "on /" | grep -v "/usr/jails" | grep -v "/usr/pbi" | grep -v "/usr/local" | awk '{print $3}'`
112   do
113     if [ "$i" = "/" ] ; then continue ; fi
114     is_mounted "${pDir}/virtbase${i}" || ($NULLFS ${i} "${pDir}/virtbase${i}" ; $MNTSLEEP )
115   done
116
117   # Mount any system-wide fonts / cursors / icons into the PBI container
118   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" -a -d "/usr/local/etc/fonts" ] ; then
119      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || ($NULLFS /usr/local/etc/fonts "${pDir}/virtbase/usr/local/etc/fonts" ; $MNTSLEEP )
120   fi
121   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" -a -d "/usr/local/lib/X11/fonts" ] ; then
122      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || ($NULLFS /usr/local/lib/X11/fonts "${pDir}/virtbase/usr/local/lib/X11/fonts" ; $MNTSLEEP )
123   fi
124   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" -a -d "/usr/local/lib/X11/icons" ] ; then
125      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || ($NULLFS /usr/local/lib/X11/icons "${pDir}/virtbase/usr/local/lib/X11/icons" ; $MNTSLEEP )
126   fi
127   if [ -d "${pDir}/virtbase/usr/local/share/icons" -a -d "/usr/local/share/icons" ] ; then
128      is_mounted "${pDir}/virtbase/usr/local/share/icons" || ($NULLFS /usr/local/share/icons "${pDir}/virtbase/usr/local/share/icons" ; $MNTSLEEP )
129   fi
130
131   # Support for some font packages(example: japanese/font-vlgothic)
132   for fontdir in /usr/local/share/font-*
133   do
134      subdir=`basename $fontdir`
135      if [ ! -d "${pDir}/virtbase/usr/local/share/$subdir" ]; then
136         mkdir "${pDir}/virtbase/usr/local/share/$subdir"
137      fi
138      is_mounted "${pDir}/virtbase/usr/local/share/$subdir" || ($NULLFS /usr/local/share/$subdir "${pDir}/virtbase/usr/local/share/$subdir" ; $MNTSLEEP )
139   done
140
141   # Check if we need to mount linprocfs in the PBI container
142   if [ -d "${pDir}/virtbase/compat/linux/proc" ] ; then
143      is_mounted "${pDir}/virtbase/compat/linux/proc" || (mount -t linprocfs linproc "${pDir}/virtbase/compat/linux/proc" ; $MNTSLEEP )
144   fi
145
146   undo_mount_lock
147
148   sleep 1
149   sync
150
151   # Copy over the system command
152   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/pbisyscmd"
153   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/openwith"
154   cp /usr/pbi/.pbisyscmd "${pDir}/virtbase/usr/local/bin/xdg-open"
155   chmod 755 "${pDir}/virtbase/usr/local/bin/pbisyscmd" 
156
157   # Copy the custom ldconfig
158   cp /usr/pbi/.ldconfig "${pDir}/virtbase/var/run/ldconfig"
159   chroot "${pDir}/virtbase" /var/run/ldconfig start >/dev/null 2>/dev/null
160
161   # Start devfs to ensure /dev/* get proper permissions
162   chroot "${pDir}/virtbase" /etc/rc.d/devfs start >/dev/null 2>/dev/null
163
164   sync
165}
166
167umount_pbidir() {
168   for i in `mount | grep "on ${pDir}/virtbase" | tail -r | awk '{print $3}'`
169   do
170     #echo "Unmounting ${i}"
171     umount ${i}
172     sleep 0.5
173   done
174}
175
176
177# Doing an unmount?
178if [ "$1" = "umount" ] ; then
179   get_pdir "$2"
180   umount_pbidir "$2"
181   exit 0
182fi
183
184if [ -z "$1" -o -z "$2" ] ; then
185   echo "Missing args: mountdir / pbidir"
186   exit 1
187fi
188
189MNTBASEDIR="`dirname $2`"
190
191if [ ! -d "$MNTBASEDIR" ] ; then
192   mkdir -p ${MNTBASEDIR}
193   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
194fi
195
196# Lets begin the mount process
197get_pdir "$1"
198check_pbidir "${2}"
199mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.