-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchroot-installation.sh
executable file
·101 lines (82 loc) · 1.96 KB
/
chroot-installation.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -x
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cd "$SCRIPT_DIR"
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <DISTRO> [RELEASE]"
exit 1
fi
#################
# Configuration #
#################
DEBUG=false
MIRROR=https://mirrors.zju.edu.cn/
PROXY=http://172.25.4.253:7890
CACHE_PROXY=http://trafficserver:8080
CHROOT_BASE=/pxe/rootfs
# TODO: change private file into modules
PRIVATE_BASE=/pxe/private/
DISTRO=$1
RELEASE=$2
TIMESTAMP=$(date +%Y%m%dT%H%M%S%Z)
if [ ! -f "distro/$DISTRO.sh" ]; then
echo "Unsupported distro."
exit 1
fi
. common-functions.sh
# shellcheck disable=SC1090
. "distro/$DISTRO.sh"
check_release || {
echo "unsupported release."
exit 1
}
common_init "$@"
####################
# Bootstrap System #
####################
CHROOT_BASE=$CHROOT_BASE/$DISTRO/$RELEASE
CHROOT_TARGET=$CHROOT_BASE.$TIMESTAMP
echo "Bootstraping $DISTRO $RELEASE into $CHROOT_TARGET now."
mkdir -p "$CHROOT_TARGET"
# workaround #844220 / #872812
chmod +x "$CHROOT_TARGET"
make_rootfs
# trust the certificate from cache proxy
# need to do in 00-bootstrap.sh
cp /usr/local/share/ca-certificates/bump.crt "$CHROOT_TARGET"/root/bump.crt
###################
# Modular Scripts #
###################
trap cleanup_all INT TERM EXIT
set -e
# use these settings in the scripts in the (s)chroots too
export MODULE_HEADER="#!/bin/bash
if $DEBUG ; then
set -x
fi
set -e
export CHROOT_METHOD=$CHROOT_METHOD
export DEBUG=$DEBUG
export DISTRO=$DISTRO
export RELEASE=$RELEASE
export TIMESTAMP=$TIMESTAMP
export ARCH=$ARCH
export LC_ALL=$LC_ALL
export LC_CTYPE=$LC_CTYPE
export LANG=$LANG
export MIRROR=$MIRROR
export PROXY=$PROXY
export CACHE_PROXY=$CACHE_PROXY
export http_proxy=$CACHE_PROXY
export https_proxy=$CACHE_PROXY
"
MODULES=(modules/*)
for script in "${MODULES[@]}"; do
echo "Debug: Running $script."
prepare_module "$script"
execute_module
done
# private files
rsync -a "$PRIVATE_BASE"/ "$CHROOT_TARGET"/
echo "Debug: Cleanup fine"
cleanup_all fine