You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
#!/bin/bash
|
|
|
|
function usage {
|
|
local BASECMD
|
|
BASECMD=$(basename "$0")
|
|
echo "usage: $BASECMD <packages...>"
|
|
case $(os-release) in
|
|
debian)
|
|
echo 'idempotent debian package installation : update if necessary, install only if not yet done'
|
|
;;
|
|
arch)
|
|
echo 'idempotent archlinux package installation : update if necessary, install only if not yet done'
|
|
;;
|
|
esac
|
|
|
|
exit 1
|
|
}
|
|
|
|
BASEDIR=$(dirname "$0")
|
|
source "$BASEDIR"/../lib/functions.sh
|
|
|
|
[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 2
|
|
[[ $# -lt 1 ]] && usage
|
|
|
|
case $(os-release) in
|
|
debian)
|
|
if [ "$(date --date='-12 hours' +%s)" -gt "$(date -d "$(stat -c %y /var/lib/apt/lists/partial)" +%s)" ]; then
|
|
echo "updating repositoring..."
|
|
apt-get update
|
|
fi
|
|
|
|
for i in "$@"; do
|
|
if ! dpkg -l "$i" 2>/dev/null | grep -q ^ii; then
|
|
sudo apt-get install -y "$i"
|
|
elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
|
|
echo "apt package <$i> already installed!"
|
|
fi
|
|
done
|
|
;;
|
|
arch)
|
|
sudo pacman -Syyu --noconfirm
|
|
for i in "$@"; do
|
|
if ! pacman -Ql "$i" &>/dev/null; then
|
|
sudo pacman -S --noconfirm "$i"
|
|
elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
|
|
echo "pacman package <$i> already installed!"
|
|
fi
|
|
done
|
|
;;
|
|
*)
|
|
echo "unknown os release <$(os-release)>!" && exit 2
|
|
;;
|
|
esac
|