WIP generalization of waybar-pkg for all OSes/boxes

This commit is contained in:
John Mertz 2023-04-12 21:43:51 -04:00
parent 59f84d2092
commit 77bf357f50
1 changed files with 21 additions and 5 deletions

View File

@ -1,10 +1,26 @@
#!/bin/bash
# Get OS "ID" (lowercase name) and "VARIANT_ID"
ID="`grep '^ID=' /etc/os-release | cut -d= -f2`-`grep 'VARIANT_ID=' /etc/os-release | cut -d= -f2`"
# Identify OS and Variant
OS="$(grep '^ID=' /etc/os-release | cut -d= -f2)"
VARIANT="$(grep '^VARIANT_ID=' /etc/os-release | cut -d= -f2)"
if [ -n "$VARIANT" ]; then
OS="${OS}-${VARIANT}"
fi
# Trim if no VARIANT exists (eg. 'debian')
ID=`echo $ID | sed -e 's/\-$//'`
# Build log file for upgradeable package counts/errors
COUNT_FILE="$HOME/.spool/upgradeable"
if [ -f "/run/.containerenv" ] || [ -f "/.dockerenv" ]; then
COUNT_FILE="$COUNT_FILE.$(echo "$HOSTNAME" | cut -d'.' -f1)"
fi
# Build command
CMD=${0//pkg/pkg-$OS}
# Log error if command does not exist and exit
if [ ! -f "$CMD" ]; then
echo "ERROR: unsupported OS/variant '$OS' due to missing script: $CMD" > "$COUNT_FILE"
exit
fi
# Run appropriate script from same path as this one
eval `echo $0 $1| sed -e "s/pkg/${ID}/"`
$CMD "$@"