aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2024-04-04 15:39:53 -0500
committerSlack Coder <slackcoder@server.ky>2024-04-04 15:39:53 -0500
commit78ae23521d975aa1714b689d572d6119b9cd7558 (patch)
tree97897a679c412be9e23eaec503d135cca9b236ca
parent0148030e54255ee136bd5fdfce4b65a5eea57b08 (diff)
downloadslack-autoupdate-78ae23521d975aa1714b689d572d6119b9cd7558.tar.xz
Help users download from custom sources
Describe in the README how to support downloading from a custom source, and add a source code location for examples.
-rw-r--r--README.md26
-rw-r--r--src/recipes/use-current-kernel.sh89
-rw-r--r--src/slack-autoupdate2
3 files changed, 116 insertions, 1 deletions
diff --git a/README.md b/README.md
index f626dd1..a0aebad 100644
--- a/README.md
+++ b/README.md
@@ -105,6 +105,32 @@ chmod +x /usr/local/sbin/install-kernel
## Source
+### Customizing Update Downloads
+
+You can add a section to the [script](src/slack-autoupdate) to pull updates
+using different tools or sources. The sections use the following structure,
+and some examples are provided in the [recipes](src/recipes) directory.
+
+```
+if ! OUTPUT="$(
+ # Redirect error output to standard output.
+ exec 2>&1
+
+ # Download updates into $STAGING_DIR.
+ #
+ # On failure the command output is appended to the error file.
+ # Update information should be appended to the $UPDATE_INFO file.
+
+)"; then
+ if [ -f "$UPDATE_ERROR" ]; then
+ >>"$UPDATE_ERROR" echo ""
+ >>"$UPDATE_ERROR" echo ""
+ fi
+
+ >>"$UPDATE_ERROR" echo -e "[Update Name]:\n\n$OUTPUT"
+fi
+```
+
### Testing
You can test the project by running the shell files under the 'test' folder.
diff --git a/src/recipes/use-current-kernel.sh b/src/recipes/use-current-kernel.sh
new file mode 100644
index 0000000..2b82a25
--- /dev/null
+++ b/src/recipes/use-current-kernel.sh
@@ -0,0 +1,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
+)
diff --git a/src/slack-autoupdate b/src/slack-autoupdate
index 78501a8..250c678 100644
--- a/src/slack-autoupdate
+++ b/src/slack-autoupdate
@@ -64,7 +64,7 @@ if ! OUTPUT="$(
echo "Checking updates for slackpkg..."
- slackpkg -batch=on -default_answer=n update || exit "$?"
+ yes | slackpkg -batch=on -default_answer=yes update || exit "$?"
CHANGELOG_TXT="$(mktemp /tmp/slack-autoupdate.XXXXXX)"
PACKAGE_UPDATES="$(mktemp /tmp/slack-autoupdate.XXXXXX)"