diff --git a/colour-changelog b/colour-changelog index 55bf4b4..92e6233 100755 --- a/colour-changelog +++ b/colour-changelog @@ -11,7 +11,7 @@ # Defaults. CHANGELOG_URL="https://ftp.osuosl.org/pub/slackware/slackware64-current/ChangeLog.txt" # CHANGELOG_URL="https://slackware.uk/slackware/slackware64-current/ChangeLog.txt" -REFRESH_INTERVAL="300" +REFRESH_INTERVAL="600" MAX_LINES="10000000" # Should cover the whole ChangeLog. # Colourise at most MAX_LINES of the ChangeLog. diff --git a/cronjob-clean-php b/cronjob-clean-php index 40010a6..b47cc39 100755 --- a/cronjob-clean-php +++ b/cronjob-clean-php @@ -1,5 +1,4 @@ #!/bin/bash -# Clean up the php session and upload directories. [[ -d /var/lib/php/sessions ]] && find /var/lib/php/sessions -mmin +1440 -type f -print0 | xargs -0 rm -f [[ -d /var/tmp/php-uploads ]] && find /var/tmp/php-uploads -mmin +1440 -type f -print0 | xargs -0 rm -f diff --git a/cronjob-dehydrated b/cronjob-dehydrated index 482fc92..7afa21c 100755 --- a/cronjob-dehydrated +++ b/cronjob-dehydrated @@ -1,6 +1,5 @@ #!/bin/bash -# Run dehydrated after a delay. - +# Run this job in the background. ( # Delay the run for 15 hours (from midnight) and then run at a random time within 3 hours after that. sleep $(( 54000 + (RANDOM % 10800) )) /opt/sbin/dehydrated -c >/dev/null ) & diff --git a/cronjob-fix-log-acls b/cronjob-fix-log-acls index 61d2a90..4313f92 100755 --- a/cronjob-fix-log-acls +++ b/cronjob-fix-log-acls @@ -1,5 +1,4 @@ #!/bin/bash -# Set ACLs on /var/log files and directories. # Sleep for up to a couple of minutes to prevent a race condition with other cron jobs. sleep $(( RANDOM % 120 )) diff --git a/cronjob-rotate-logs-today-symlink b/cronjob-rotate-logs-today-symlink index cd54374..f59a139 100755 --- a/cronjob-rotate-logs-today-symlink +++ b/cronjob-rotate-logs-today-symlink @@ -1,5 +1,4 @@ #!/bin/bash -# Create a new symlink to today's logs, for ease of browsing. # Default configuration. LOGS_DIR="/data/logs" @@ -11,28 +10,23 @@ LOGS_DIR="/data/logs" for DIR in "$LOGS_DIR"/*/; do cd "$DIR" 2>/dev/null || { printf "%s: %s\\n" "${0##*/}" "failed to change directory to '$DIR'" >&2 - ERR=1 continue } - # Logs are for root only. - umask 022 - # Create the new days' location. + umask 0755 # shellcheck disable=SC2174 mkdir -p -m 0755 "$LOGS_DIR/$TODAY" 2>/dev/null || { printf "%s: %s\\n" "${0##*/}" "failed to create directory '$LOGS_DIR/$TODAY'" >&2 - ERR=1 continue } # Create the 'today' symlink to the new location. ln -sfn "$TODAY" "today" 2>/dev/null || { printf "%s: %s\\n" "${0##*/}" "updating 'today' symlink failed in '$DIR'" >&2 - ERR=1 continue } done } -exit "${ERR:-0}" +exit 0 diff --git a/cronjob-update-mirrors-search-db b/cronjob-update-mirrors-search-db index b44a3e2..9ade33a 100755 --- a/cronjob-update-mirrors-search-db +++ b/cronjob-update-mirrors-search-db @@ -1,21 +1,16 @@ #!/bin/bash -# Update the 'locate' database used for the search backend on slackware.uk. - -# Default configuration. -SCANDIR="/data/depository" -DBFILE="/data/sites/slackware.uk/files/search.db" RAND="$$$RANDOM" -if ionice -c3 nice -n 19 /opt/bin/updatedb -l no -o "$DBFILE.$RAND" -U "$SCANDIR" >/dev/null 2>&1; then - mv "$DBFILE.$RAND" "$DBFILE" 2>/dev/null || { +if ionice -c3 nice -n 19 /opt/bin/updatedb -l no -o /data/sites/slackware.uk/files/search.db.$RAND -U /data/depository >/dev/null 2>&1; then + mv /data/sites/slackware.uk/files/search.db.$RAND /data/sites/slackware.uk/files/search.db 2>/dev/null || { printf "%s: %s\\n" "${0##*/}" "failed to move mirrors search database into place" >&2 - rm -f "$DBFILE.$RAND" + rm -f /data/sites/slackware.uk/files/search.db.$RAND exit 1 } else printf "%s: %s\\n" "${0##*/}" "mirrors search database update failed" >&2 - rm -f "$DBFILE.$RAND" + rm -f "/data/sites/slackware.uk/files/search.db.$RAND" exit 1 fi diff --git a/cronjob-update-packages-list b/cronjob-update-packages-list index 9a63b92..203c69a 100755 --- a/cronjob-update-packages-list +++ b/cronjob-update-packages-list @@ -1,5 +1,4 @@ #!/bin/bash -# Update the /etc/pkglist file, the record of installed packages on the system. # Check for an /etc/os-release. [[ ! -e /etc/os-release ]] && { diff --git a/cronjob-update-packages-list.new b/cronjob-update-packages-list.new new file mode 100644 index 0000000..5503f68 --- /dev/null +++ b/cronjob-update-packages-list.new @@ -0,0 +1,55 @@ +#!/bin/bash + +# FIXME: This is broken. + +# Check for an /etc/os-release. +[[ ! -e /etc/os-release ]] && { + printf "%s: %s\\n" "${BASH_SOURCE[0]}" "No /etc/os-release to determine system." >&2 + exit 1 +} + +# Source system info. +# shellcheck disable=SC1091 +. /etc/os-release + +PKGLIST_CUR_MD5="$(md5sum /etc/pkglist 2>/dev/null)" +TEMPLATE_CUR_MD5="$(md5sum /etc/slackpkg/templates/$(hostname --short).template 2>/dev/null)" + +# Create package list depending on system type. +case "$ID" in + 'alpine') + apk list -I | cut -d' ' -f1 | rev | cut -d- -f3- | rev >/etc/pkglist || exit 1 + ;; + 'debian'|'devuan'|'ubuntu') + dpkg-query --show --showformat='${Package}\n' >/etc/pkglist || exit 1 + ;; + 'slackware') + [[ -L /etc/pkglist ]] && rm -f /etc/pkglist + printf "%s\\n" /var/log/packages/* | rev | cut -d- -f4- | rev >/etc/pkglist || exit 1 + slackpkg -batch=on -default_answer=y generate-template "$(hostname --short)" >/dev/null || exit 1 + ;; + 'void') + xbps-query -l | awk '{ print $2 }' | rev | cut -d- -f2- | rev >/etc/pkglist || exit 1 + ;; + *) + printf "%s: %s\\n" "${BASH_SOURCE[0]}" "Unsupported system." >&2 + exit 1 + ;; +esac + +cd /etc || exot 1 +git rev-parse --show-toplevel >/dev/null 2>&1 && { + [[ -z "$PKGLIST_CUR_MD5" ]] && [[ -e pkglist ]] && { + git add pkglist >/dev/null || exit 1 + } + [[ -z "$TEMPLATE_CUR_MD5" ]] && [[ -e "slackpkg/templates/$(hostname --short).template" ]] && { + git add "slackpkg/templates/$(hostname --short).template" >/dev/null || exit 1 + } + { [[ -e pkglist ]] && [[ "$(md5sum pkglist 2>/dev/null)" != "$PKGLIST_CUR_MD5" ]]; } || \ + { [[ -e "slackpkg/templates/$(hostname --short).template" ]] && \ + [[ "$(md5sum "slackpkg/templates/$(hostname --short).template" 2>/dev/null)" != "$TEMPLATE_CUR_MD5" ]]; } && { + git commit -m "Update pkglist (and/or." pkglist >/dev/null || exit 1 + } +} + +exit 0 diff --git a/cronjob-updatedb-mirrors b/cronjob-updatedb-mirrors new file mode 100755 index 0000000..f4ea9a3 --- /dev/null +++ b/cronjob-updatedb-mirrors @@ -0,0 +1,26 @@ +#!/bin/bash +# Version: 0.1.0 +# Copyright (c) 2023: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# +# Update the locate database used specifically for the search interface on slackware.uk. + +# Configuration. +DBFILE="/run/mirrors.db" +FILETREE="/storage/md0" +COMMAND="/usr/bin/updatedb" + +# Sanity check. +[[ ! -x "$COMMAND" ]] && { + printf "%s: '%s' %s\\n" "${0##*/}" "$COMMAND" "is not executable" >&2 + exit 1 +} + +# Update the database. +nice -n 19 ionice -c3 "$COMMAND" -l 0 -o "$DBFILE" -U "$FILETREE" || { + printf "%s: %s\\n" "${0##*/}" "failed to update locate database" >&2 + exit 1 +} + +exit 0 diff --git a/cronjob-warn-git-status b/cronjob-warn-git-status index 3a07040..f70fed5 100755 --- a/cronjob-warn-git-status +++ b/cronjob-warn-git-status @@ -1,24 +1,19 @@ #!/bin/bash -# Email the status of various git repositories on the system. # Default configuration. -# This can be overridden in /etc/default/warn-git-status. -EMAIL_FROM="\"Server: ${HOSTNAME%%.*}\" " -EMAIL_TO=("Systems' Administrator ") +CHECK_DIRS=('/') +EMAIL_TO=('sysadmin@slackware.uk') +EMAIL_FROM="\"Server: ${HOSTNAME%%.*}\" " -# Read the default configuration from /etc/default/warn-git-status. -if [[ -e /etc/default/warn-git-status ]]; then +# Allow /etc/default/warn-git-status to override default configuration. +[[ -e /etc/default/warn-git-status ]] && { # shellcheck disable=SC1091 source /etc/default/warn-git-status || { printf "%s: %s\\n" "${0##*/}" "failed reading /etc/default/warn-git-status" >&2 exit 1 } -else - printf "%s: %s\\n" "${0##*/}" "/etc/default/warn-git-status does not exist" >&2 - exit 1 -fi +} -# Temporary output file. OUTPUT_FILE="/tmp/${0##*/}-$$-$RANDOM" # Remove the OUTPUT_FILE when done. @@ -27,10 +22,8 @@ trap 'rm -f "$OUTPUT_FILE"' EXIT # Loop through the list and process. for DIR in "${CHECK_DIRS[@]}"; do [[ ! -e "$DIR" ]] || [[ ! -d "$DIR" ]] && continue - TMP_OUTPUT="$(cd "$DIR" && [[ "$(git rev-parse --show-toplevel)" == "$PWD" ]] && git status | grep -E -ve "^(On branch|Your branch|No commits|nothing|$)" -e "\(use")" [[ -n "$TMP_OUTPUT" ]] && printf "%s:\\n%s\\n\\n" "$DIR" "$TMP_OUTPUT" >>"$OUTPUT_FILE" - unset TMP_OUTPUT done @@ -39,14 +32,24 @@ done exit 0 } -# Send the notification message. -if [[ -n "$EMAIL_FROM" ]] && [[ -n "${EMAIL_TO[*]}" ]]; then - mail -r "$EMAIL_FROM" -s "Git statuses" "${EMAIL_TO[@]}" <"$OUTPUT_FILE" >/dev/null 2>&1 || { - printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2 +# Send the message. +if [[ -n "${EMAIL_TO[*]}" ]]; then + if hash mailx >/dev/null 2>&1; then + mailx -S "from=$EMAIL_FROM" -s "Git statuses" "${EMAIL_TO[@]}" <"$OUTPUT_FILE" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2 + exit 1 + } + elif hash mail >/dev/null 2>&1; then + mail -r "$EMAIL_FROM" -s "Git statuses" "${EMAIL_TO[@]}" <"$OUTPUT_FILE" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2 + exit 1 + } + else + printf "%s: %s\\n" "${0##*/}" "no mailer command found" >&2 exit 1 - } + fi else - printf "%s: %s\\n" "${0##*/}" "no sender and/or recipient configured for mail delivery" >&2 + printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2 exit 1 fi diff --git a/cronjob-warn-smtp-queue b/cronjob-warn-smtp-queue index 859f2e8..f551661 100755 --- a/cronjob-warn-smtp-queue +++ b/cronjob-warn-smtp-queue @@ -1,8 +1,6 @@ #!/bin/bash -# Send an email with the status of the SMTP queue on the system. # Default configuration. -# This can be overridden in /etc/default/warn-smtp-queue. EMAIL_TO=('sysadmin@slackware.uk') EMAIL_FROM="\"Server: ${HOSTNAME%%.*}\" " @@ -26,13 +24,23 @@ hash mailq 2>/dev/null && { [[ -z "$TMP_OUTPUT" ]] && exit 0 # Send the message. - if [[ -n "$EMAIL_FROM" ]] && [[ -n "${EMAIL_TO[*]}" ]]; then - mail -r "$EMAIL_FROM" -s "Mail queue" "${EMAIL_TO[@]}" <<<"$TMP_OUTPUT" >/dev/null 2>&1 || { - printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2 + if [[ -n "${EMAIL_TO[*]}" ]]; then + if hash mailx >/dev/null 2>&1; then + mailx -S "from=$EMAIL_FROM" -s "Mail queue" "${EMAIL_TO[@]}" <<<"$TMP_OUTPUT" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2 + exit 1 + } + elif hash mail >/dev/null 2>&1; then + mail -r "$EMAIL_FROM" -s "Mail queue" "${EMAIL_TO[@]}" <<<"$TMP_OUTPUT" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2 + exit 1 + } + else + printf "%s: %s\\n" "${0##*/}" "no mailer command found" >&2 exit 1 - } + fi else - printf "%s: %s\\n" "${0##*/}" "no sender and/or recipient configured for mail delivery" >&2 + printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2 exit 1 fi } diff --git a/do-backup b/do-backup index d0c8816..0a8e35f 100755 --- a/do-backup +++ b/do-backup @@ -1,4 +1,9 @@ #!/bin/bash +# Version: 0.1.1 +# Copyright (c) 2023: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# # Perform backup tasks in a generic way. # Base configuration. diff --git a/dovecot-service-checksuspended b/dovecot-service-checksuspended index da11b7e..2af1775 100755 --- a/dovecot-service-checksuspended +++ b/dovecot-service-checksuspended @@ -1,4 +1,9 @@ #!/bin/bash +# Version: 0.1.0 +# Copyright (c) 2023: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# # A Dovecot service script to check whether a domain or user has been suspended from being able to use mail. VIRTUAL_DIR="/etc/virtual" diff --git a/firewall-initscript b/firewall-initscript index f19c2f1..25ee3cd 100755 --- a/firewall-initscript +++ b/firewall-initscript @@ -1,5 +1,4 @@ #!/bin/bash -# Restore firewall state at boot, and store it at shutdown. ### BEGIN INIT INFO # Provides: firewall # Required-Start: $network diff --git a/git-auto-merge b/git-auto-merge index a2bac87..b993bf9 100755 --- a/git-auto-merge +++ b/git-auto-merge @@ -1,4 +1,9 @@ #!/bin/bash +# Version: 0.1.0 +# Copyright (c) 2023: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# # Automatically fetch and merge (if possible) upstream changes into a local git repository. # What platform we're running on. diff --git a/mirror b/mirror index a2cafd7..965c594 100755 --- a/mirror +++ b/mirror @@ -1,5 +1,4 @@ #!/bin/bash -# Perform mirroring tasks for slackware.uk. # Version: 0.4.0 # Copyright (c) 2026: # Darren 'Tadgy' Austin diff --git a/mirror-new-slackware-release.gpg b/mirror-new-slackware-release.gpg index 4fda3fd..992a9f4 100644 Binary files a/mirror-new-slackware-release.gpg and b/mirror-new-slackware-release.gpg differ diff --git a/mirror-wrapper b/mirror-wrapper index 812479e..d9de8a5 100755 --- a/mirror-wrapper +++ b/mirror-wrapper @@ -1,4 +1,9 @@ #!/bin/bash +# Version: 0.2.1 +# Copyright (c) 2023-2026: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# # Wrapper around /opt/bin/mirror to keep a log of the mirroring session, and email it. # Configuration. diff --git a/notify-rsync-upload b/notify-rsync-upload deleted file mode 100755 index d271c41..0000000 --- a/notify-rsync-upload +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -# Send an email notification whenever someone pushes an update to rsyncd. - -# Default configuration. -# This can be overridden in /etc/default/notify-rsync-upload. -EMAIL_FROM="\"Server: ${HOSTNAME%%.*}\" " -EMAIL_TO=("Systems' Administrator ") -LOGSDIR="/var/log/duplication/rsync-uploads" - -# Read /etc/default/notify-rsync-upload if it exists. -[[ -e /etc/default/notify-rsync-upload ]] && { - # shellcheck disable=SC1091 - source /etc/default/notify-rsync-upload || { - printf "%s: %s\\n" "${0##*/}" "failed reading /etc/default/notify-rsync-upload" >&2 - exit 1 - } -} - -# Make sure the logs directory exists. -mkdir -p "$LOGSDIR" 2>/dev/null || { - printf "%s: %s\\n" "${0##*/}" "Failed to create logs directory" >&2 - exit 1 -} - -# Update the log with this upload date/time. -printf "%s - %s\\n" "$(printf "%(%c)T")" "{RSYNC_USER_NAME:-(none)}@${RSYNC_HOST_NAME:-$RSYNC_HOST_ADDR}" >>"$LOGSDIR/${RSYNC_MODULE_NAME%%-upload}" - -# Determine the subject of the message. -if (( RSYNC_EXIT_STATUS == 0 )); then - EMAIL_SUBJECT="Upload success: ${RSYNC_MODULE_NAME%%-upload}" -elif (( RSYNC_EXIT_STATUS == -1 )); then - EMAIL_SUBJECT="Upload error: ${RSYNC_MODULE_NAME%%-upload}" -else - EMAIL_SUBJECT="Upload failure: ${RSYNC_MODULE_NAME%%-upload}" -fi - -# Send the message. -if [[ -n "$EMAIL_FROM" ]] && (( "${#EMAIL_TO[@]}" != 0 )); then - printf "%s:\\t%s\\n%s:\\t\\t%s\\n%s:\\t%s\\n%s:\\t\\t%s\\n" "Auth'd user" "$RSYNC_USER_NAME@$RSYNC_HOST_NAME [$RSYNC_HOST_ADDR]" "Module" "$RSYNC_MODULE_NAME ($RSYNC_MODULE_PATH)" "Exit code" "$RSYNC_EXIT_STATUS" "PID" "$RSYNC_PID" | mail -r "$EMAIL_FROM" -s "$EMAIL_SUBJECT" "${EMAIL_TO[@]}" >/dev/null 2>&1 || { - printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2 - exit 1 - } -else - printf "%s: %s\\n" "${0##*/}" "no sender and/or recipient configured for mail delivery" >&2 - exit 1 -fi - -exit 0 diff --git a/rsync-notify-upload b/rsync-notify-upload new file mode 100755 index 0000000..31c536f --- /dev/null +++ b/rsync-notify-upload @@ -0,0 +1,51 @@ +#!/bin/bash +# Version: 0.1.0 +# Copyright (c) 2023: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# +# Send an email notification whenever someone pushes an update to rsync. +# shellcheck disable=SC2154 + +# Configuration. +LOGSDIR="/var/log/suplication/rsync-uploads" + +# Source the mail configuration. +source /etc/mail.conf "notify-upload" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "Failed to source /etc/mail.conf" >&2 + exit 1 +} + +# Make sure the logs directory exists. +mkdir -p "$LOGSDIR" 2>/dev/null || { + printf "%s: %s\\n" "${0##*/}" "Failed to create logs directory" >&2 + exit 1 +} + +# Update the log with this upload date/time. +printf "%s - %s\\n" "$(date)" "{RSYNC_USER_NAME:-(none)}@${RSYNC_HOST_NAME:-$RSYNC_HOST_ADDR}" >>"$LOGSDIR/${RSYNC_MODULE_NAME%%-upload}" + +# Determine the subject of the message. +if (( RSYNC_EXIT_STATUS == 0 )); then + EMAIL_SUBJECT="Upload success: ${RSYNC_MODULE_NAME%%-upload}" +elif (( RSYNC_EXIT_STATUS == -1 )); then + EMAIL_SUBJECT="Upload error: ${RSYNC_MODULE_NAME%%-upload}" +else + EMAIL_SUBJECT="Upload failure: ${RSYNC_MODULE_NAME%%-upload}" +fi + +# Send the message. +if [[ -n "${EMAIL_TO[*]}" ]]; then + mailx "${MAILX_ARGS[@]}" -S "from=$EMAIL_FROM" -s "$EMAIL_SUBJECT" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \ + { printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2; RET=1; } + Auth'd User: $RSYNC_USER_NAME@$RSYNC_HOST_NAME [$RSYNC_HOST_ADDR] + Module: $RSYNC_MODULE_NAME ($RSYNC_MODULE_PATH) + Exit code: $RSYNC_EXIT_STATUS + PID: $RSYNC_PID + EOF +else + printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2 + RET=1 +fi + +exit "${RET:-0}" diff --git a/sbosrcarch-wrapper b/sbosrcarch-wrapper index 9f16a9d..55fe5fa 100755 --- a/sbosrcarch-wrapper +++ b/sbosrcarch-wrapper @@ -1,4 +1,9 @@ #!/bin/bash +# Version: 0.2.0 +# Copyright (c) 2023-2026: +# Darren 'Tadgy' Austin +# Licensed under the terms of the GNU General Public License version 3. +# # Wrapper around /opt/bin/sbosrcarch to keep a log of the session, and email it. # Configuration.