-
Notifications
You must be signed in to change notification settings - Fork 1
/
30_enter_chroot.sh
executable file
·80 lines (55 loc) · 1.79 KB
/
30_enter_chroot.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# This script is expected to be executed as root to get into the chroot
#
# Copyright (C) 2011 onwards by Yury V. Zaytsev
#
# Free to use and distribute under the terms of the MIT license
#
set +u
SCRIPT_TO_RUN="$1"
set -e
set -u
# Read the configuration
#
source 10_environment.sh
# Copy DNS settings from the host
#
cp -f /etc/resolv.conf $WORKING_ROOT/$LIVECD_ROOT/etc
# Mount necessary special-purpose file systems
#
mount --bind /dev $WORKING_ROOT/$LIVECD_ROOT/dev
# Put a preinstall/cleanup script inside the chroot
#
OUR_DIR=`dirname $0`
cp -f $OUR_DIR/$PREINSTALL_SCRIPT $WORKING_ROOT/$LIVECD_ROOT
cp -f $OUR_DIR/$CLEANUP_SCRIPT $WORKING_ROOT/$LIVECD_ROOT
chmod ugo+x $WORKING_ROOT/$LIVECD_ROOT/$PREINSTALL_SCRIPT
chmod ugo+x $WORKING_ROOT/$LIVECD_ROOT/$CLEANUP_SCRIPT
# Run the pre-install script inside the chroot
#
chroot $WORKING_ROOT/$LIVECD_ROOT /$PREINSTALL_SCRIPT
# Either just chroot or also run a script inside
#
if [ -z "$SCRIPT_TO_RUN" ]; then
pause "Changing the root to $LIVECD_ROOT"
chroot $WORKING_ROOT/$LIVECD_ROOT
else
SCRIPT_FULL=$1
SCRIPT_NAME=`basename $1`
cp -f $SCRIPT_FULL $WORKING_ROOT/$LIVECD_ROOT
chmod ugo+x $WORKING_ROOT/$LIVECD_ROOT/$SCRIPT_NAME
echo "Now please make sure that the relevant archives are already in /usr/src, i.e. NEST / NEURON"
pause "Changing the root to $LIVECD_ROOT to run script $SCRIPT_NAME inside..."
chroot $WORKING_ROOT/$LIVECD_ROOT /$SCRIPT_NAME
echo "Cleaning up..."
rm -f $WORKING_ROOT/$LIVECD_ROOT/$SCRIPT_NAME
fi
# Run the cleanup script inside the chroot
#
chroot $WORKING_ROOT/$LIVECD_ROOT /$CLEANUP_SCRIPT
rm -f $WORKING_ROOT/$LIVECD_ROOT/$PREINSTALL_SCRIPT
rm -f $WORKING_ROOT/$LIVECD_ROOT/$CLEANUP_SCRIPT
# Can not do that inside the chroot
#
umount $WORKING_ROOT/$LIVECD_ROOT/dev