aboutsummaryrefslogtreecommitdiff
path: root/src/recipes/use-current-kernel.sh
blob: 2b82a25e5aba26d43ef2eaa8a643e3bbd1a34868 (plain)
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
# Download kernel updates from Slackware Current for a stable release.
#
# For this to work, make sure the kernel packages are blacklisted in
# /etc/slackpkg/blacklist.
#
#  kernel-generic.*
#  kernel-huge.*
#  kernel-modules.*
#  kernel-source.*
#
# This script uses an unusual pattern for running commands on exit, similar to
# Golang's defer.  These will not be run when the script is stopped with
# Control+c.
#
# D="[command]; $D"; trap "$D" EXIT
#

echo "Checking kernel updates from Slackware Current (slackpkg)..."

# Get Slackware version.
source /etc/os-release

SOURCE=$(sed -n '
        # Remove leading and trailing blanks
        s/^[[:blank:]]*//
        s/[[:blank:]]*$//
        # Only one token is allowed per line
        /[[:blank:]]/d
        # A single solidus should end the URI
        s,[/]*$,/,
        # Print the lines beginning with one of the URI schemes we look for
        \@^file://@p
        \@^cdrom://@p
        \@^local://@p
        \@^https\{0,1\}://@p
        \@^ftps\{0,1\}://@p' /etc/slackpkg/mirrors)
SOURCE="$(echo $SOURCE | sed 's/-$VERSION/-current/')"

yes y | slackpkg -mirror="$SOURCE" -batch=on -default_answer=yes update
D="yes | slackpkg -batch=on -default_answer=yes update"; trap "$D" EXIT

PACKAGE_UPDATES="$(mktemp /tmp/slack-autoupdate.XXXXXX)"
D="rm -f ${PACKAGE_UPDATES}; $D"; trap "$D" EXIT

mv /etc/slackpkg/blacklist /etc/slackpkg/blacklist.orig
touch /etc/slackpkg/blacklist
D="mv -f /etc/slackpkg/blacklist.orig /etc/slackpkg/blacklist; $D"; trap "$D" EXIT

slackpkg -batch=on -default_answer=n \
  upgrade kernel \
  | grep "\.t.z$" \
  | tee "$PACKAGE_UPDATES"  \
  || exit "$?"

if [ ! -s "$PACKAGE_UPDATES" ]; then
  # No updates
  exit 0
fi

while read PKG; do
  PKG_URL="$(
    grep "${PKG}$" /var/lib/slackpkg/CHECKSUMS.md5 \
      | tr -s ' ' \
      | cut -f 2 -d ' '
    )" || exit "$?"

  wget \
    --directory-prefix="$STAGING_DIR" \
    "${SOURCE}${PKG_URL}" \
    "${SOURCE}${PKG_URL}.asc" \
    || exit 1
done <"$PACKAGE_UPDATES"

if ! gpg2 --verify-files "$STAGING_DIR"/kernel-*.asc; then
  echo "gpg verification failed"
  exit 1
fi

(
  # Redirect this subshell's standard output to info file.
  exec 1>>"$UPDATE_INFO"

  echo "## Slackware current kernel updates"
  echo
  while read PKG; do
    echo " - $PKG"
  done <"$PACKAGE_UPDATES"
  echo
)