-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsystem-upgrade
executable file
·95 lines (82 loc) · 2.41 KB
/
system-upgrade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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
}
# We need to be root
enforce_root() {
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
while getopts 'hSw' opt; do
case $opt in
S) SCREEN='';;
w) WAIT=1;;
*) 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
exec $SCREEN "$0" -S -w "$@"
fi
# 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 "$@"
# relly do the job
upgrade
if (( $WAIT == 1 )); then
read -r -p "Type enter to quit"
fi
}
main "$@"