slack-autoupdate

Update your Slackware system automatically
git clone git://git.server.ky/slackcoder/slack-autoupdate
Log | Files | Refs | README

use-current-kernel.sh (2636B)


      1 slackware_current_kernel_source() {
      2   # Download kernel updates from Slackware Current for a stable release.
      3   #
      4   # For this to work, make sure the kernel packages are blacklisted in
      5   # /etc/slackpkg/blacklist.
      6   #
      7   #  kernel-generic.*
      8   #  kernel-huge.*
      9   #  kernel-modules.*
     10   #  kernel-source.*
     11   #
     12   # This script uses an unusual pattern for running commands on exit, similar to
     13   # Golang's defer.  These will not be run when the script is stopped with
     14   # Control+c.
     15   #
     16   # D="[command]; $D"; trap "$D" EXIT
     17   #
     18 
     19   local staging_dir="$1"
     20   local update_info="$2"
     21 
     22   # Get the system's Slackware version.
     23   source /etc/os-release
     24 
     25   local mirror=$(sed -n '
     26           # Remove leading and trailing blanks
     27           s/^[[:blank:]]*//
     28           s/[[:blank:]]*$//
     29           # Only one token is allowed per line
     30           /[[:blank:]]/d
     31           # A single solidus should end the URI
     32           s,[/]*$,/,
     33           # Print the lines beginning with one of the URI schemes we look for
     34           \@^file://@p
     35           \@^cdrom://@p
     36           \@^local://@p
     37           \@^https\{0,1\}://@p
     38           \@^ftps\{0,1\}://@p' /etc/slackpkg/mirrors)
     39   mirror="$(echo $mirror | sed "s/-$VERSION/-current/")"
     40 
     41   yes y | slackpkg -mirror="$mirror" -batch=on -default_answer=yes update
     42   D="yes | slackpkg -batch=on -default_answer=yes update"; trap "$D" EXIT
     43 
     44   local package_updates="$(mktemp /tmp/slack-autoupdate.XXXXXX)"
     45   D="rm -f ${package_updates}; $D"; trap "$D" EXIT
     46 
     47   mv /etc/slackpkg/blacklist /etc/slackpkg/blacklist.orig
     48   touch /etc/slackpkg/blacklist
     49   D="mv -f /etc/slackpkg/blacklist.orig /etc/slackpkg/blacklist; $D"; trap "$D" EXIT
     50 
     51   local output="$(slackpkg -batch=on -default_answer=n upgrade kernel)" || exit_code="$?"
     52   # slackpkg has several safe exit codes.
     53   if [ $exit_code -ne 0 ] && [ $exit_code -ne 20 ] && [ $exit_code -ne 100 ]; then
     54     exit exit_code
     55   fi
     56 
     57   echo "$output" \
     58     | grep "\.t.z$" \
     59     | tee "$package_updates"
     60   if [ ! -s "$package_updates" ]; then
     61     # No updates
     62     exit 0
     63   fi
     64 
     65   while read PKG; do
     66     PKG_URL="$(
     67       grep "${PKG}$" /var/lib/slackpkg/CHECKSUMS.md5 \
     68         | tr -s ' ' \
     69         | cut -f 2 -d ' '
     70       )" || exit "$?"
     71 
     72     wget \
     73       --directory-prefix="$STAGING_DIR" \
     74       "${mirror}${PKG_URL}" \
     75       "${mirror}${PKG_URL}.asc" \
     76       || exit 1
     77   done <"$package_updates"
     78 
     79   if ! gpg2 --verify-files "$STAGING_DIR"/kernel-*.asc; then
     80     echo "gpg verification failed"
     81     exit 1
     82   fi
     83 
     84   (
     85     # Redirect this subshell's standard output to info file.
     86     exec 1>>"$update_info"
     87 
     88     while read PKG; do
     89       echo " - $PKG"
     90     done <"$package_updates"
     91   )
     92 }