diff options
Diffstat (limited to 'src/autoupdate')
-rw-r--r-- | src/autoupdate | 132 |
1 files changed, 71 insertions, 61 deletions
diff --git a/src/autoupdate b/src/autoupdate index eac1999..397a091 100644 --- a/src/autoupdate +++ b/src/autoupdate @@ -31,21 +31,12 @@ export UPDATE_INFO="${UPDATE_INFO:-$STAGING_DIR/info.txt}" # Information of interest to the admin on failure. export UPDATE_ERROR="${UPDATE_ERROR:-$STAGING_DIR/error.txt}" -# Slackware mirror containing packages. -export SLACKWARE_MIRROR="rsync://mirrors.kernel.org/slackware/slackware64-15.0" - -# A local Slackware mirror with just enough information to support slackpkg. -# -# This step could be skipped if slackpkg supports downloading updates without -# installing them. -export LOCAL_MIRROR=${LOCAL_MIRROR:-"/var/cache/slack-autoupdate/mirror"} - # Avoid concurrently running with another instance. if [ "$(ls /var/lock/autoupdate.* 2>/dev/null)" ]; then echo "Another instance of autoupdate is running. If this is not correct, you can remove /var/lock/autoupdate.* files and run autoupdate again." \ - >>"$PACKAGE_DIR/$(basename $UPDATE_ERROR)" + >>"$PACKAGE_DIR/$(basename "$UPDATE_ERROR")" if [ "$NOTIFY" = "yes" ]; then - cat "$PACKAGE_DIR/$(basename $UPDATE_ERROR)" + cat "$PACKAGE_DIR/$(basename "$UPDATE_ERROR")" fi exit 1 @@ -60,14 +51,6 @@ if [ -n "$(find "$PACKAGE_DIR" -name "*.t*z")" ]; then exit 0 fi -# This is slackpkg's exit code when updates are available. -SLACKPKG_UPDATES_PENDING=100 - -slackpkg -mirror="file:///$LOCAL_MIRROR/" check-updates >/dev/null 2>/dev/null -if [ "$?" -eq "$SLACKPKG_UPDATES_PENDING" ]; then - exit 0 -fi - # Make the set of package updates available atomically by storing them in a # temporary location until completion. rm -fr "$STAGING_DIR" @@ -77,53 +60,77 @@ if ! OUTPUT="$( # Capture this subshell's error output to standard output. exec 2>&1 - ( - echo "downloading updates from $SLACKWARE_MIRROR..." - - # Support slackpkg with the least required files for patches. - # - # Grab the changelog last to avoid slackpkg possibly reporting updates on a - # partially synced mirror. Rsync does not guarantee argument order matches - # download order. - mkdir --parents "$LOCAL_MIRROR/slackware64" && \ - rsync \ - --links --times \ - "$SLACKWARE_MIRROR/slackware64/PACKAGES.TXT" \ - "$LOCAL_MIRROR/slackware64/." \ - && rsync \ - --delete --links --recursive --times \ - "$SLACKWARE_MIRROR/FILELIST.TXT" \ - "$SLACKWARE_MIRROR/GPG-KEY" \ - "$SLACKWARE_MIRROR/extra" \ - --exclude "extra/source" \ - "$SLACKWARE_MIRROR/PACKAGES.TXT" \ - "$SLACKWARE_MIRROR/pasture" \ - --exclude "pasture/source" \ - "$SLACKWARE_MIRROR/patches" \ - --exclude "patches/source" \ - "$SLACKWARE_MIRROR/testing" \ - --exclude "testing/source" \ - "$LOCAL_MIRROR/." \ - && rsync \ - --times \ - "$SLACKWARE_MIRROR/ChangeLog.txt" \ - "$SLACKWARE_MIRROR/CHECKSUMS.md5" \ - "$SLACKWARE_MIRROR/CHECKSUMS.md5.asc" \ - "$LOCAL_MIRROR/." - ) || exit $? - - slackpkg -mirror="file:///$LOCAL_MIRROR/" check-updates - if [ "$?" -ne "$SLACKPKG_UPDATES_PENDING" ]; then + echo "Checking updates for slackpkg..." + + slackpkg -batch=on -default_answer=n update || exit "$?" + + CHANGELOG_TXT="$(mktemp /tmp/slack-autoupdate.XXXXXX)" + PACKAGE_UPDATES="$(mktemp /tmp/slack-autoupdate.XXXXXX)" + trap "rm -f ${CHANGELOG_TXT} ${PACKAGE_UPDATES}" EXIT + + slackpkg -batch=on -default_answer=n upgrade-all \ + | grep "\.t.z$" \ + | tee "$PACKAGE_UPDATES" \ + || exit "$?" + + if [ ! -s "$PACKAGE_UPDATES" ]; then + # No updates exit 0 fi + # + # We need slackpkg to support downloading an exact package file to a provided + # location. The following is a workaround. + # + + 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) + + while read PKG; do + PKG_URL="$( + grep "${PKG}$" /var/lib/slackpkg/CHECKSUMS.md5 \ + | tr -s ' ' \ + | cut -f 2 -d ' ' + )" || exit "$?" + + wget \ + --quiet \ + --directory-prefix="$STAGING_DIR" \ + "${SOURCE}${PKG_URL}" \ + "${SOURCE}${PKG_URL}.asc" \ + || exit "$?" + done <"$PACKAGE_UPDATES" + + gpg2 --verify-files "$STAGING_DIR"/*.asc || exit "$?" + ( + # Provide update information to the user. + # Redirect this subshell's standard output to info file. exec 1>>"$UPDATE_INFO" + LAST_INSTALLED_PACKAGE="$( + grep \ + $(ls /var/log/packages | sed "s/$/\\\|/g" | tr --delete '\n')XXXXX" \ + /var/lib/slackpkg/ChangeLog.txt \ + | head -n 1 + )" + echo "Slackware updates" echo - slackpkg show-changelog | diff - "$LOCAL_MIRROR/ChangeLog.txt" + grep --before-context 10000 "$LAST_INSTALLED_PACKAGE" /var/lib/slackpkg/ChangeLog.txt echo ) )"; then @@ -133,16 +140,19 @@ fi if ! OUTPUT="$( exec 2>&1 + echo "Checking updates for sbotools..." + if [ ! -f /etc/sbotools/sbotools.conf ] \ || [ "$(sed -n 's/PKG_DIR=//p' /etc/sbotools/sbotools.conf)" != "$STAGING_DIR" ]; then # Assume sbotools is disabled. exit 0 fi - UPDATE_INFO=$(mktemp /tmp/sbocheck.XXXXXX) + PACKAGE_UPDATES=$(mktemp /tmp/slack-autoupdate.XXXXXX) + trap "rm -f ${PACKAGE_UPDATES}" EXIT - (sbocheck | tee $UPDATE_INFO) || exit 1 - if grep -i "no updates available" "$UPDATE_INFO"; then + (sbocheck | tee $PACKAGE_UPDATES) || exit 1 + if grep -i "no updates available" "$PACKAGE_UPDATES"; then exit 0 fi @@ -157,7 +167,7 @@ if ! OUTPUT="$( echo "Slackbuild updates" echo - cat "$UPDATE_INFO" + cat "$PACKAGE_UPDATES" echo ) )"; then |