source: src-sh/pbi-manager10/pbime/pbimount @ 7e583de

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

Don't try to mount dirs which don't exist for PBIS

  • Property mode set to 100755
File size: 3.7 KB
Line 
1#!/bin/sh
2
3NULLFS="/usr/pbi/.mount_nullfs"
4
5is_mounted() {
6   if [ ! -d "${1}" ] ; then return 0; fi
7   mount | grep -q "on ${1} (" 
8   return $?
9}
10
11check_pbidir() {
12  if [ -d "${1}/pbimeta" ] ; then return ; fi
13  echo "Error: Invalid PBI: ${1}"
14  exit 1
15}
16
17get_pdir() {
18  pDir="${1}"
19  if [ ! -d "${pDir}/virtbase" ] ; then
20    mkdir -p ${pDir}/virtbase
21  fi
22  if [ ! -d "${pDir}/run" ] ; then
23    mkdir -p ${pDir}/run
24  fi
25}
26
27mount_pbifile() {
28   if [ ! -d "$pDir" ] ; then
29      mkdir -p "${pDir}"
30   else
31      # Check to see if it is already mounted
32      mount | grep -q "on ${pDir} (ufs,"
33      if [ $? -eq 0 ] ; then return; fi
34   fi
35   MD=`mdconfig -a -t vnode -f ${1}`
36   mount -r -t ufs /dev/${MD}.uzip "${pDir}"
37}
38
39mount_dirs() {
40   is_mounted "${pDir}/virtbase" || $NULLFS / ${pDir}/virtbase
41   is_mounted "${pDir}/virtbase/dev" || mount -t devfs devfs ${pDir}/virtbase/dev
42   is_mounted "${pDir}/virtbase/usr/local" || $NULLFS ${1}/local ${pDir}/virtbase/usr/local
43   is_mounted "${pDir}/virtbase/var/run" || $NULLFS ${pDir}/run ${pDir}/virtbase/var/run
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}/virtbase/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}"
111mount_dirs "${2}"
Note: See TracBrowser for help on using the repository browser.