File: lessdisks-chroot

package info (click to toggle)
lessdisks 0.5.3cvs.20040906-16
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,480 kB
  • ctags: 271
  • sloc: sh: 3,058; makefile: 92
file content (62 lines) | stat: -rwxr-xr-x 1,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

# sets up an environment so that daemons don't actually get run,
# and proc is mounted for package installs which may require it.

# copyright 2004 vagrant@freegeek.org, distributed under the terms of the
# GNU General Public License version 2 or any later version.

if [ -r /etc/lessdisks-install.conf ]; then
  . /etc/lessdisks-install.conf
fi

if [ -r /etc/lessdisks/server.config ]; then
  . /etc/lessdisks/server.config
fi

if [ -n "$1" ]; then
  if [ -d $1 ]; then
    # use alternate chroot
    lessdisks_path="$1"
    shift
  fi
fi

if [ -z "$lessdisks_path" ] || [ ! -d "$lessdisks_path" ]; then
  exit 1
fi

mountpoint=$(which mountpoint)

do_chroot_mount() {
  chroot $lessdisks_path mount -t $@
  umounts="$umounts $3"
}

chroot_mount() {
  if [ -z "$mountpoint" ]; then
    do_chroot_mount $@
  else
    mountpoint -q $lessdisks_path/$3 || do_chroot_mount $@
  fi
}

# some package installs make use of /proc, so mount it
chroot_mount proc proc /proc
chroot_mount devpts devpts /dev/pts -o rw,gid=5,mode=620
chroot_mount tmpfs tmpfs /tmp

# set start-stop-daemon to behave like fake daemon
# so that packages which attempt to start servers don't do so while
# in the chroot.
LESSDISKS_START_STOP_DAEMON=fake chroot $lessdisks_path $@
# grab exit code from executed command
status="$?"

# unmount chrooted mountpoints 
for a in $umounts ; do
  umount $lessdisks_path/$a
done

# TODO support exit codes from the various umounts...
exit $status