-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlkhh-init
More file actions
executable file
·79 lines (70 loc) · 1.92 KB
/
lkhh-init
File metadata and controls
executable file
·79 lines (70 loc) · 1.92 KB
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
_rootdir=${_rootdir:-"$(dirname "$(readlink -f "$0")")"}
_ver="0.0.1-dev"
#_author="Wei Peng <me@1pengw.com>"
source "${_rootdir}/_shared_prologue"
#
# parameters
#
declare -i instance=${instance:-1}
declare -i download=${download:-0}
#
# getopt processing
#
function my_getopt_cont () {
local n_shift=1 # number of shifts in the outer loop; shift by 1 by default
case "$1" in
-i|--instance)
shift
instance=$1
n_shift=2
;;
-d|--download)
download=1
n_shift=1
;;
esac
return $n_shift
}
my_getopt "i:d" "instance:,download" "my_getopt_cont" "One-time initialization for Linux Kernel Hacking Helper (LKHH)." "$(
cat <<END
[-i|--instance=<instance>] [-d|--download]
END
)" "$(
cat <<END
-i --instance Maximal number of kernel instances to prepare (default: $instance).
-d --download Download an OS image for testing (default: $download).
END
)" "$@"
ret=$?
eval set -- "$_getopt"
shift $ret
# sanity check
vecho 0 <<END
$(
dumpparam <<END1
$(
for name in instance download; do
echo "$name=$(echo $(eval "echo \$$name"))"
done
)
END1
)
END
mkdir -p "$LKHH_ARENA" || die 1 <<END
Fail to create $LKHH_ARENA.
END
eval mkdir -p $LKHH_ARENA/{target,build}/{1..$instance} "$LKHH_ARENA/aux" "$LKHH_IMAGE/mnt" || >/dev/stderr vecho 0 <<END
ERROR: Fail to create certain base directories.
END
if (( download > 0 )); then
pushd $LKHH_IMAGE || die 1 <<END
Fail to cd into $LKHH_IMAGE.
END
if type -p aria2c; then
aria2c -j 10 -x 10 -Z -- https://github.com/pw4ever/linux-kernel-hacking-helper/releases/download/arch-clean/arch-clean.tar.a{a,b,c,d,e,f} && cat arch-clean.tar.a{a,b,c,d,e,f} | tar xvf -
elif type -p wget; then
wget -- https://github.com/pw4ever/linux-kernel-hacking-helper/releases/download/arch-clean/arch-clean.tar.a{a,b,c,d,e,f} && cat arch-clean.tar.a{a,b,c,d,e,f} | tar xvf -
fi
popd
fi