-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull
executable file
·76 lines (65 loc) · 2.29 KB
/
pull
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
#!/bin/sh
#
# Download & apply the latest kernel binary from a master server.
#
# This eliminates the need to compile the same kernel on all servers instances.
# One master server compiles and offers the kernel, others can pull from there.
#
# NOTE: the kernel on the master domain has to be shared through https as
# https://$DOMAIN/boot/#KERNEL-FILES# (e.g.: ln -s /boot /var/www/)
# Required shared files are generated by the SHARE=y parameter
# during the kernel compilation, see the install script.
#
# (cloux@rote.ch)
exec 2>&1
# We need to be root
if [ $(id -u) -ne 0 ]; then printf 'Need to be root!\n'; exit 1; fi
# use configuration files to override the defaults above
MODULE_PATH=$(realpath "${0%/*}" 2>/dev/null)
[ -r "$MODULE_PATH/conf" ] && . "$MODULE_PATH/conf"
[ -r /etc/default/kernel-update ] && . /etc/default/kernel-update
# get the latest kernel version number from one of the domains
for DOMAIN in $PULL_FROM; do
printf 'Latest kernel on %s: ' "$DOMAIN"
LATEST=$(wget -qO- "https://$DOMAIN/boot/latest" 2>/dev/null)
printf '%s\n' "$LATEST"
[ "$LATEST" ] && break
done
if [ -z "$LATEST" ]; then
printf 'None of the domains share a new kernel.\n'
exit 1
fi
if [ -e "/boot/vmlinuz-$LATEST" ]; then
printf 'This kernel is already installed.\n'
exit
fi
printf 'New Kernel %s is available\n' "$LATEST"
# download the new binary kernel
cd /boot || exit 1
KERNEL_FILES="System.map config vmlinuz modules headers"
for FILE in $KERNEL_FILES; do
printf 'Downloading %s ... ' "$FILE"
NEWFILE="${FILE}-$LATEST"
[ "$FILE" = "modules" ] && NEWFILE="$NEWFILE.tgz"
[ "$FILE" = "headers" ] && NEWFILE="$NEWFILE.tgz"
wget -4 -N -nd --no-verbose "https://$DOMAIN/boot/$NEWFILE" 2>&1 | tr '\n' ' '
printf '\n'
done
# unpack modules
[ -f "/boot/vmlinuz-$LATEST" ] || exit 1
printf 'Unpack modules into /lib/modules ...'
cd /lib/modules || exit 1
mv -f "/boot/modules-$LATEST.tgz" .
tar xzf "modules-$LATEST.tgz" && printf 'OK\n'
rm -f "modules-$LATEST.tgz"
# unpack headers if available
if [ -f "/boot/headers-$LATEST.tgz" ]; then
printf 'Unpack headers into /usr/src ...'
cd /usr/src
mv -f "/boot/headers-$LATEST.tgz" .
tar xzf "headers-$LATEST.tgz" && printf 'OK\n'
rm -f "headers-$LATEST.tgz"
fi
# apply the new kernel
[ -x /usr/sbin/update-grub ] && /usr/sbin/update-grub
printf '\nDONE\n'