|
@ -1,16 +1,28 @@ |
|
|
#!/bin/bash |
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
source "$MIAOU_BASH_DIR"/lib/functions.sh |
|
|
|
|
|
|
|
|
function usage { |
|
|
function usage { |
|
|
local BASECMD |
|
|
local BASECMD |
|
|
BASECMD=$(basename "$0") |
|
|
BASECMD=$(basename "$0") |
|
|
echo "usage: $BASECMD <packages...>" |
|
|
echo "usage: $BASECMD <packages...>" |
|
|
|
|
|
case $(os-release) in |
|
|
|
|
|
debian) |
|
|
echo 'idempotent debian package installation : update if necessary, install only if not yet done' |
|
|
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 |
|
|
exit 1 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 2 |
|
|
[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 2 |
|
|
[[ $# -lt 1 ]] && usage |
|
|
[[ $# -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 |
|
|
if [ "$(date --date='-12 hours' +%s)" -gt "$(date -d "$(stat -c %y /var/lib/apt/lists/partial)" +%s)" ]; then |
|
|
echo "updating repositoring..." |
|
|
echo "updating repositoring..." |
|
|
apt-get update |
|
|
apt-get update |
|
@ -23,3 +35,17 @@ for i in "$@"; do |
|
|
echo "apt package <$i> already installed!" |
|
|
echo "apt package <$i> already installed!" |
|
|
fi |
|
|
fi |
|
|
done |
|
|
done |
|
|
|
|
|
;; |
|
|
|
|
|
arch) |
|
|
|
|
|
for i in "$@"; do |
|
|
|
|
|
if ! pacman -Ql "$i" 2>/dev/null | grep -q ^ii; then |
|
|
|
|
|
sudo pacman -S "$i" |
|
|
|
|
|
elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then |
|
|
|
|
|
echo "pacman package <$i> already installed!" |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
;; |
|
|
|
|
|
*) |
|
|
|
|
|
echo "unknown os release <$(os-release)>!" && exit 2 |
|
|
|
|
|
;; |
|
|
|
|
|
esac |