Tuesday, December 21, 2010

sysupd.sh

System update script. Syncs pacman databases, optionally lists available updates, upgrades, prompts for abs sync, and updates mlocate database. Flags to download the updates without installing, list available updates, no-confirm, and force sync.

#!/bin/bash

# make sure the script is being run as root
/usr/local/bin/chkroot && [[ $? = 0 ]] || exit 1

# define script variables
dlonly=
fsync=
noconf=
list=0

# get optoins
args=`getopt dlny $*`

set -- $args
for i; do
    case "$1" in
        -d) dlonly="-w"                        ; shift ;;
        -l) list=1                                ; shift ;;
        -n) noconf="--noconfirm"    ; shift ;;
        -y)    fsync="-y"                        ; shift ;;
        --) shift                                    ; break ;;
    esac
done

pacman -Sy $fsync
[[ "$?" = "0" ]] || exit 1

if [[ "$list" = "1" ]]; then
    pacman -Qu --dbpath /var/lib/pacman
    exit 0
fi

pacman -Su $dlonly $noconf
echo "Sync ABS? [Y/n]"
read sync_abs
if [[ "$sync_abs" != {"N","n"} ]]; then
    abs
fi

echo; echo "updating mlocate database"
updatedb

exit 0

No comments:

Post a Comment