-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaintain
More file actions
executable file
·76 lines (61 loc) · 1.32 KB
/
maintain
File metadata and controls
executable file
·76 lines (61 loc) · 1.32 KB
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
#!/bin/bash
usage() {
printf '%s\n' "Usage: maintain [-h] [-y]
Keep apt packages up-to-date.
where:
-h, --help - show this help text
-y, --yes - perform all steps w/o confirmation"
}
maintain() {
local auto_accept="$1"
if [[ "${auto_accept}" == 'true' ]]; then
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
else
sudo apt update
read -p 'List?'
sudo apt list --upgradeable
read -p 'Upgrade?'
sudo apt upgrade
read -p 'Autoremove?'
sudo apt autoremove
if [ -x purge-residual-config ] ; then
read -p 'Purge residual config?'
purge-residual-config
fi
fi
}
# Option parsing
declare PARAMS=""
declare AUTO_ACCEPT='false'
while (( "$#" )); do
case "$1" in
-h|--help) # display help message
usage
exit 1
;;
-y|--yes) # set autoaccept policy
AUTO_ACCEPT='true'
break
;;
--) # End argument parsing
shift
break
;;
-*|--*) # unsupported flags
echo "Unsupported flag: $1" >&2
usage
exit 1
;;
*) # preserve positional arguments
PARAMS="${PARAMS} maintain"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "${PARAMS}"
# Freeze configuration flags
readonly AUTO_ACCEPT
maintain "${AUTO_ACCEPT}"