summaryrefslogtreecommitdiffstats
path: root/helperscripts/update
blob: 1bdcfc4def36acf5657fa0bf1b030f58cfbc2685 (plain)
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
#!/bin/sh

die()
{
	echo "$*" >&2
	exit 1
}

info()
{
	echo "--- $*"
}

usage()
{
	echo "update [OPTIONS]"
	echo
	echo "Options:"
	echo " -f|--full              Full upgrade"
	echo " -d|--download-only     Download only"
}

full=0
download_only=0

while [ $# -ge 1 ]; do
	case "$1" in
	-f|--full)
		full=1
		;;
	-d|--download-only)
		download_only=1
		;;
	-h|--help)
		usage
		exit 0
		;;
	*)
		die "Unknown parameter: $1"
		;;
	esac
	shift
done

# Be nice
nice=19
renice $nice $$ >/dev/null || echo "Failed to renice to $nice" >&2

if [ $full -eq 0 ]; then
	upgrade_mode="upgrade"
else
	upgrade_mode="full-upgrade"
fi

info "Updating package list"
apt update || die "Update failed"

# Do the download and upgrade.
info "Performing '$upgrade_mode'"
dl_flags=
[ $download_only -ne 0 ] && dl_flags="--download-only"
apt $dl_flags --show-upgraded --verbose-versions "$upgrade_mode" ||\
	die "Upgrade failed"

# Exit here, if download only.
[ $download_only -ne 0 ] && exit 0

# Purge packages, if full upgrade.
if [ $full -ne 0 ]; then
	info "Purging old packages"
	apt-get autoremove --purge || die "Autoremove failed"
fi

info "Cleaning"
apt-get clean || die "Clean failed"

if command -v flatpak >/dev/null 2>&1; then
	info "Updating flatpaks"
	flatpak update || die "flatpak update failed"
	flatpak uninstall --unused || die "flatpak uninstall --unused failed"
fi

if command -v rpi-eeprom-update >/dev/null 2>&1; then
	info "Updating Raspberry Pi EEPROMs"
	rpi-eeprom-update -a || die "Raspberry Pi EEPROM update failed"
fi

exit 0
bues.ch cgit interface