-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-kernel.sh
More file actions
executable file
·202 lines (168 loc) · 4.71 KB
/
get-kernel.sh
File metadata and controls
executable file
·202 lines (168 loc) · 4.71 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
##############################################################################
# Written by: Behan Webster
# Licensed under the GPLv2
#
# Install proxmox on new Debian install
#
set -e
VERSION=1.0
RED="\e[0;31m"
GREEN="\e[0;32m"
YELLOW="\e[0;33m"
#CYAN="\e[0;36m"
#BLUE="\e[0;34m"
BACK="\e[0m"
VERBOSE=
DLOADONLY=
MKDIR="verbose mkdir -p"
GIT="verbose git"
#RM="verbose rm -f"
#SED="verbose sed"
##############################################################################
verbose() {
if [[ -n $TEST ]] ; then
echo + "$@" >&2
elif [[ -n $VERBOSE ]] ; then
(set -x; "$@")
else
"$@"
fi
}
##############################################################################
info() {
echo -e "${GREEN}I:" "$@" "$BACK" >&2
}
##############################################################################
banner() {
echo -e "${GREEN}##############################################################################$BACK" >&2
info "$@"
}
##############################################################################
warn() {
echo -e "${YELLOW}W:" "$@" "$BACK" >&2
}
##############################################################################
error() {
echo -e "${RED}E:" "$@" "$BACK" >&2
verbose exit 1
}
################################################################################
in_path() {
command -v "$@" >/dev/null 2>&1
}
##############################################################################
default_config() {
unset LC_TERMINAL
unset LC_CTYPE
LANG=C
TEST="${TEST:+echo}"
NFS="/srv/LFT"
# Fast google kernel.org mirror
KERNELSRC="https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable"
KERNELDIR="$NFS/linux-stable"
}
##############################################################################
read_config() {
default_config
banner "Read Configuration"
local CONF FILES="$HOME/.config/install-proxmox/defaults.conf $HOME/.install-proxmox.conf"
for CONF in $FILES ; do
if [[ -f "$CONF" ]] ; then
# shellcheck disable=SC1090
. "$CONF"
fi
done
}
##############################################################################
run_apt() {
DEBIAN_FRONTEND=noninteractive verbose apt-get --quiet --assume-yes --no-install-recommends "$@"
}
##############################################################################
update_debian() {
banner "Update Debian packages"
run_apt update
run_apt full-upgrade
}
##############################################################################
install_debian_extras() {
banner "Install extra Debian packages"
run_apt install git mosh rsync vim vim-addon-manager vim-youcompleteme
verbose vim-addons install youcompleteme
banner "Install Debian kernel packages"
run_apt install bc bison build-essential flex libelf-dev libssl-dev lz4
}
##############################################################################
check_debian() {
update_debian
install_debian_extras
}
##############################################################################
latest_branch() {
$GIT branch -a | sed -E '/linux-[0-9]/!d; s|^.*/||; s/^.* //;' | sort -n -t - -k2 -k3 | tail -1
}
##############################################################################
latest_tag() {
$GIT tag | sed -E '/^v/!d; /-rc/d; s/^v//;' | sort -n -t . -k1 -k2 -k3 | tail -1 | sed 's/^/v/'
}
##############################################################################
clone_kernel() {
local TAG
$MKDIR "${KERNELDIR%/*}"
if [[ -d $KERNELDIR ]] ; then
banner "Update the linux kernel"
cd "$KERNELDIR"
$GIT fetch
$GIT checkout master
else
banner "Clone the linux kernel"
$GIT clone "$KERNELSRC" "$KERNELDIR"
fi
banner "Checkout the latest tag"
cd "$KERNELDIR"
TAG="$(latest_tag)"
$GIT checkout "$TAG"
banner "Checkout the latest tag: $TAG"
}
##############################################################################
do_the_thing() {
[[ -n $DLOADONLY ]] || check_debian
clone_kernel
}
##############################################################################
usage() {
cat <<END
Version $VERSION
Usage: ${0##*/} [options] [steps]
-n|--dry-run Dry-run of script
-V|--version Version of script
-h|--help This help
END
exit 1
}
##############################################################################
# Read options
read_config
while [[ $1 =~ ^- ]] ; do
# shellcheck disable=SC2086
case "$1" in
--list) sed -n '/^do_the_thing()/,/^\}$/{//!p;}' $0; exit 0;;
--download-only) DLOADONLY=y;;
-n|--dry-run|--test) TEST="echo";;
--trace) set -x;;
-v|--verbose) VERBOSE=1;;
-V|--version) echo $VERSION; exit 0;;
--) break;;
-*) usage;;
esac
shift
done
##############################################################################
if [[ $# -gt 0 ]] ; then
while [[ $# -gt 0 ]] ; do
"$1"
shift
done
else
time do_the_thing
fi