source: src-sh/pbi-manager10/pbime/pbimount @ ee5b2887

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since ee5b2887 was ee5b2887, checked in by Kris Moore <kris@…>, 9 months ago

Run our custom ldconfig script, so that we can execute PBIs as a user

  • Property mode set to 100755
File size: 3.8 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4
5is_mounted() {
6   mount | grep -q "on ${1} (" 
7   return $?
8}
9
10check_pbidir() {
11  if [ -d "${1}/pbimeta" ] ; then return ; fi
12  echo "Error: Invalid PBI: ${1}"
13  exit 1
14}
15
16get_pdir() {
17  pDir="${1}"
18  if [ ! -d "${pDir}/virtbase" ] ; then
19    mkdir -p ${pDir}/virtbase
20  fi
21  if [ ! -d "${pDir}/run" ] ; then
22    mkdir -p ${pDir}/run
23  fi
24}
25
26mount_pbifile() {
27   if [ ! -d "$pDir" ] ; then
28      mkdir -p "${pDir}"
29   else
30      # Check to see if it is already mounted
31      mount | grep -q "on ${pDir} (ufs,"
32      if [ $? -eq 0 ] ; then return; fi
33   fi
34   MD=`mdconfig -a -t vnode -f ${1}`
35   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
36}
37
38mount_dirs() {
39   is_mounted "${pDir}/virtbase" || $NULLFS / ${pDir}/virtbase
40   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs ${pDir}/virtbase/dev
41   is_mounted "${pDir}/virtbase/usr/local" || $NULLFS ${1}/local ${pDir}/virtbase/usr/local
42   is_mounted "${pDir}/virtbase/var/run" || mount -t unionfs -o noatime ${pDir}/run ${pDir}/virtbase/var/run
43   is_mounted "${pDir}/virtbase/usr/local/etc" || mount -t unionfs -o noatime ${1}/etc ${pDir}/virtbase/usr/local/etc
44   is_mounted "${pDir}/virtbase/compat/linux" || $NULLFS ${1}/linux ${pDir}/virtbase/compat/linux
45   if [ -d "${pDir}/virtbase/usr/local/etc/fonts" ] ; then
46      is_mounted "${pDir}/virtbase/usr/local/etc/fonts" || $NULLFS /usr/local/etc/fonts ${pDir}/virtbase/usr/local/etc/fonts
47   fi
48   if [ -d "${pDir}/virtbase/usr/local/lib/X11/fonts" ] ; then
49      is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" || $NULLFS /usr/local/lib/X11/fonts ${pDir}/virtbase/usr/local/lib/X11/fonts
50   fi
51   if [ -d "${pDir}/virtbase/usr/local/lib/X11/icons" ] ; then
52      is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" || $NULLFS /usr/local/lib/X11/icons ${pDir}/virtbase/usr/local/lib/X11/icons
53   fi
54   is_mounted "${pDir}/virtbase/tmp" || $NULLFS /tmp ${pDir}/virtbase/tmp
55   is_mounted "${pDir}/virtbase/usr/home" || $NULLFS /usr/home ${pDir}/virtbase/usr/home
56   for i in `ls -d /usr/home/* 2>/dev/null`
57   do
58      is_mounted "${i}" 
59      if [ $? -eq 0 ] ;then
60         is_mounted "${pDir}/virtbase${i}" || $NULLFS ${i} ${pDir}/virtbase${i}
61      fi
62
63   done
64
65   cp /usr/pbi/.ldconfig ${pDir}/var/run/ldconfig
66   chroot ${pDir}/virtbase /var/run/ldconfig start >/dev/null 2>/dev/null
67}
68
69umount_pbidir() {
70   is_mounted "${pDir}/virtbase/usr/local/etc/fonts" && umount ${pDir}/virtbase/usr/local/etc/fonts
71   is_mounted "${pDir}/virtbase/usr/local/etc" && umount ${pDir}/virtbase/usr/local/etc
72   is_mounted "${pDir}/virtbase/usr/local/lib/X11/fonts" && umount ${pDir}/virtbase/usr/local/lib/X11/fonts
73   is_mounted "${pDir}/virtbase/usr/local/lib/X11/icons" && umount ${pDir}/virtbase/usr/local/lib/X11/icons
74   is_mounted "${pDir}/virtbase/usr/local" && umount ${pDir}/virtbase/usr/local
75   is_mounted "${pDir}/virtbase/tmp" && umount ${pDir}/virtbase/tmp
76   is_mounted "${pDir}/virtbase/dev" && umount ${pDir}/virtbase/dev
77   is_mounted "${pDir}/virtbase/var/run" && umount ${pDir}/virtbase/var/run
78   is_mounted "${pDir}/virtbase/compat/linux" && umount ${pDir}/virtbase/compat/linux
79   for i in `ls -d ${pDir}/virtbase/usr/home/* 2>/dev/null`
80   do
81      is_mounted "${i}" && umount ${i}
82   done
83   is_mounted "${pDir}/virtbase/usr/home" && umount ${pDir}/virtbase/usr/home
84   is_mounted "${pDir}/virtbase" && umount ${pDir}/virtbase
85}
86
87
88# Doing an unmount?
89if [ "$1" = "umount" ] ; then
90   get_pdir "$2"
91   umount_pbidir "$2"
92   exit 0
93fi
94
95if [ -z "$1" -o -z "$2" ] ; then
96   echo "Missing args: mountdir / pbidir"
97   exit 1
98fi
99
100MNTBASEDIR="`dirname $2`"
101
102if [ ! -d "$MNTBASEDIR" ] ; then
103   mkdir -p ${MNTBASEDIR}
104   echo "Do not manually remove this directory!" > ${MNTBASEDIR}/DONOTDELETE
105fi
106
107# Lets begin the mount process
108get_pdir "$1"
109check_pbidir "${2}"
110mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.