Newer
Older
#!/bin/bash
# Copyright © Sébastien Luttringer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Smart way to update your archlinux system
declare SCREEN=screen
declare -i WAIT=0
declare -a PACMAN_OPTS=()
# run system upgrade and checkservices
upgrade() {
if pacman --sync --refresh --sysupgrade "${PACMAN_OPTS[@]}"; then
checkservices
else
printf '\e[7;33;40mcheckservices not run because pacman did not exit zero\e[m\n'
fi
if (( $UID != 0 )); then
if type -P sudo >/dev/null; then
exec sudo -- "$0" "$@"
elif type -P su >/dev/null; then
exec su -c "$0" "$@"
fi
printf '\e[7;31;40mYou need to be root\e[m\n'
exit 1
fi
}
# display application usage and exit 1
usage() {
echo "usage ${0##*/} [options] -- [pacman options]"
echo "description: archlinux system upgrade with checkservices"
echo 'options:'
echo ' -h: this help' >&2
echo " -S: no screen" >&2
exit 1
}
# parse command line arguments
# set options as global vars
argparse() {
local opt
*) usage;;
esac
done
shift $((OPTIND - 1));
PACMAN_OPTS=("$@")
}
# emulated program entry point
main() {
# parse command line options
argparse "$@"
if [[ -z "$STY" && -z "$TMUX" && -n "$SCREEN" ]] && type -P $SCREEN >/dev/null
then
# be root
# -S to never start a screen as root (offer a root shell)
# and sudo strip environment so we loose $STY or $TMUX variables
enforce_root -S "$@"
if (( $WAIT == 1 )); then
read -r -p "Type enter to quit"
fi