-
Notifications
You must be signed in to change notification settings - Fork 7
/
rebuild.sh
executable file
·116 lines (103 loc) · 3.66 KB
/
rebuild.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# μCernVM initial ramdisk image generator
#
# μCernVM tools is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# μCernVM tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with μCernVM tools. If not, see <http://www.gnu.org/licenses/>.
#
# Developed by Ioannis Charalampidis 2012 at PH/SFT, CERN
# Contact: <ioannis.charalampidis[at]cern.ch>
#
die() {
echo "[ERR] $1"
exit 1
}
# Setup environment
export DESTDIR=$(mktemp -d)
export SCRIPTS="scripts.d"
export BASEDIR=$(pwd)
# Externally provided versions
[ -z $UCERNVM_STRONG_VERSION ] && die "UCERNVM_STRONG_VERSION missing"
[ -z $KERNEL_STRONG_VERSION ] && die "KERNEL_STRONG_VERSION missing"
[ -z $BB_STRONG_VERSION ] && die "BB_STRONG_VERSION missing"
[ -z $CURL_STRONG_VERSION ] && die "CURL_STRONG_VERSION missing"
[ -z $DROPBEAR_STRONG_VERSION ] && die "DROPBEAR_STRONG_VERSION missing"
[ -z $NTPCLIENT_STRONG_VERSION ] && die "NTPCLIENT_STRONG_VERSION missing"
[ -z $E2FSPROGS_STRONG_VERSION ] && die "E2FSPROGS_STRONG_VERSION missing"
[ -z $KEXEC_STRONG_VERSION ] && die "KEXEC_STRONG_VERSION missing"
[ -z $SFDISK_STRONG_VERSION ] && die "SFDISK_STRONG_VERSION missing"
[ -z $CVMFS_STRONG_VERSION ] && die "CVMFS_STRONG_VERSION missing"
[ -z $GPTFDISK_STRONG_VERSION ] && die "GPTFDISK_STRONG_VERSION missing"
[ -z $EXTRAS_STRONG_VERSION ] && die "EXTRAS_STRONG_VERSION missing"
export KERNEL_STRONG_VERSION
export BB_STRONG_VERSION
export UCERNVM_STRONG_VERSION
export CURL_STRONG_VERSION
export DROPBEAR_STRONG_VERSION
export NTPCLIENT_STRONG_VERSION
export E2FSPROGS_STRONG_VERSION
export KEXEC_STRONG_VERSION
export SFDISK_STRONG_VERSION
export CVMFS_STRONG_VERSION
export GPTFDISK_STRONG_VERSION
export EXTRAS_STRONG_VERSION
TARGET=initrd.$UCERNVM_STRONG_VERSION
[ $(echo "$TARGET" | grep -c '^/') -eq 0 ] && TARGET=$(pwd)/$TARGET
echo "[INF] Generating $TARGET"
# Include functions
. ${BASEDIR}/include/functions.sh
# Create an empty filesystem
[ -z "${DESTDIR}" ] && echo "[ERR] Invalid destination directory specified!" && exit 1
create_empty "${DESTDIR}"
# Generate init from runtime
cp "${BASEDIR}/include/runtime-init.sh" "${DESTDIR}/init"
chmod +x "${DESTDIR}/init"
# Run generation scripts
for F in $(find scripts.d -maxdepth 1 -type f -name '[0-9]*' | sort); do
echo ${F}
process_file ${F}
done
# Copy kernel modules
echo "[INF] Generating kernel modules"
mkdir -p ${DESTDIR}/lib/modules
cp -a ${BASEDIR}/kernel/cernvm-kernel-${KERNEL_STRONG_VERSION}/lib/modules/* ${DESTDIR}/lib/modules/
# Gather library dependencies
echo "[INF] Gathering dependend libraries"
libs_missing=1
while [ $libs_missing -eq 1 ]; do
libs_missing=0
for f in $(find ${DESTDIR} -type f); do
libs=
if ldd $f >/dev/null 2>&1; then
libs=$(ldd $f | awk '{print $3}' | grep -v 0x | grep -v '^$')
fi
[ -z "$libs" ] && continue
for l in $libs; do
if [ ! -f ${DESTDIR}$l ]; then
libs_missing=1
cp -v $l ${DESTDIR}$l
fi
done
done
done
# Finalize
echo "[INF] Running ldconfig and depmod in ${DESTDIR}"
ldconfig -r "${DESTDIR}"
depmod -a -b "${DESTDIR}" $KERNEL_STRONG_VERSION
# Build initrd
echo "[INF] Compressing init ramdisk"
cd "${DESTDIR}"
find . | cpio -H newc -o | xz -9 --check=crc32 > ${TARGET}
# Remove temporary dir
echo $DESTDIR
#rm -rf "${DESTDIR}"