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

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

Add a cool new system callback function to PBIs on 10.x and beyond

This allows PBIs, which run in a container, to use the pbisyscmd, openwith
or xdg-open, and "talk" to applications on the outside of the container.

The use-case for this would be a application like Thunderbird, which may
want to use the "xdg-open" command to open a PDF file with something else
on the system.

It could be used by other apps, such as terminal emulators to run a shell on the system,
even though the GUI is run in the container

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