update-slackpkg-template->update-packages-list. Make work on Void too.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-20 18:51:55 +01:00
commit 950a0fb857
3 changed files with 26 additions and 131 deletions

View file

@ -0,0 +1,26 @@
#!/bin/bash
# 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.
. /etc/os-release
# Create package list depending on system type.
case "$ID" in
'slackware')
/usr/sbin/slackpkg -batch=on -default_answer=y generate-template "$(hostname --short)" >/dev/null
;;
'void')
/usr/sbin/xbps-query -l | awk '{ print $2 }' | rev | cut -d- -f2- | rev >/etc/pkglist
;;
*)
printf "%s: %s\\n" "${BASH_SOURCE[0]}" "Unsupported system." >&2
exit 1
;;
esac
exit 0

View file

@ -1,3 +0,0 @@
#!/bin/bash
slackpkg -batch=on -default_answer=y generate-template "$(hostname --short)" >/dev/null

View file

@ -1,128 +0,0 @@
#!/bin/bash
# Version: 0.3.1
# Copyright (c) 2005-2022:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
EXEC=""
ARGS=()
PIDFILE=""
# Allow configuration in /etc/default to override.
# Additional available variables:
# ENVIRONMENT=() # Extra environment passed to $EXEC. Must be an array.
# EXTRA_ARGS=() # Extra arguments passed to $EXEC. Must be an array.
# SLAY_DELAY="" # Delay between the SIGTERM and SIGKILL on a 'stop'. Default: 2s.
# RESTART_DELAY="" # Delay between stopping and starting on a 'restart'. Default: 2s.
# shellcheck disable=SC1090
[[ -e "/etc/default/${0##*rc.}" ]] && { source "/etc/default/${0##*rc.}" || return 1 2>/dev/null || exit 1; }
error() {
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "$*" >&2
}
checkconfigured() {
# This function can be used to perform any pre-start tests; hopfully to insure the daemon
# can start correctly, before actually trying to start it. A return value of 0 means the
# tests were passed and the daemon should be started. Any other value prevents the
# daemon from being started, and an error message will be emitted.
return 0
}
checkstatus() {
# shellcheck disable=SC2155
local RUNPIDS="$({ pgrep -f "$EXEC"; pgrep -F "$PIDFILE" 2>/dev/null; } | sort -u )"
if [[ -n "$RUNPIDS" ]]; then
printf "%s: %s: %s" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "running"
if [[ -n "$PIDFILE" ]]; then
if [[ ! -e "$PIDFILE" ]]; then
printf "%s" ", but .pid file does not exist"
elif ! grep "\<$(<"$PIDFILE")\>" <<<"$RUNPIDS" >/dev/null 2>&1; then
printf "%s" ", but .pid file is stale"
fi
fi
printf "\\n"
else
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "${EXEC##*/}" "stopped"
return 1
fi
return 0
}
startdaemon() {
if [[ ! -e "$EXEC" ]]; then
error "not found"
return 2
elif [[ ! -x "$EXEC" ]]; then
error "not executable"
return 2
elif ! checkconfigured; then
error "not started - pre-start checks failed"
return 2
fi
# shellcheck disable=SC2048,SC2086
${ENVIRONMENT:+declare ${ENVIRONMENT[*]};} "$EXEC" ${ARGS[*]} ${EXTRA_ARGS[*]}
# shellcheck disable=SC2181
if (( $? != 0 )); then
error "error starting daemon"
return 2
else
return 0
fi
}
stopdaemon() {
kill -TERM "$(pgrep -f "$EXEC" | tr $'\n' " ")" >/dev/null 2>&1
[[ -e "$PIDFILE" ]] && {
sleep 0.5
kill -TERM "$(<"$PIDFILE")" >/dev/null 2>&1
}
sleep "${SLAY_DELAY:-2}"
checkstatus >/dev/null && {
error "failed to stop gracefully - slaying"
kill -KILL "$({ cat "$PIDFILE"; pgrep -f "$EXEC"; } 2>/dev/null | sort -u | tr $'\n' " ")" >/dev/null 2>&1
}
return 0
}
case "$1" in
'start')
if checkstatus >/dev/null; then
error "already running"
printf " %s\\n" "Try: ${BASH_SOURCE[0]} status" >&2
RET=1
else
startdaemon
RET=$?
fi
;;
'stop')
if ! checkstatus >/dev/null; then
error "not running"
printf " %s\\n" "Try: ${BASH_SOURCE[0]} status" >&2
RET=1
else
stopdaemon
RET=$?
fi
;;
'restart')
checkstatus >/dev/null
(( $? != 3 )) && {
stopdaemon >/dev/null 2>&1
sleep "${RESTART_DELAY:-2}"
}
startdaemon
RET=$?
;;
'status')
checkstatus
RET=$?
;;
*)
printf "%s\\n" "Usage: ${BASH_SOURCE[0]} <start|stop|restart|status>" >&2
RET=1
;;
esac
return $RET 2>/dev/null || exit $RET