bzr branch
http://gegoxaren.bato24.eu/bzr/useful/trunk-1
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
1 |
#!/usr/bin/env bash
|
2 |
||
3 |
####
|
|
4 |
# FILE NAME do-offline-updates.sh
|
|
5 |
#
|
|
27
by Gustav Hartvigsson
Added copyright information to all files. |
6 |
# Authors:
|
7 |
# Gustav Hartvigsson 2024
|
|
8 |
# Distributed under the Cool Licence 1.1
|
|
9 |
#
|
|
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
10 |
####
|
11 |
||
12 |
__UPDATES_AVAILABLE=false |
|
13 |
__DO_REBOOT=true |
|
14 |
__DO_DOWNLOAD=true |
|
15 |
__REBOOT_COMMAND="systemctl reboot" |
|
16 |
||
17 |
__SANITY=true |
|
18 |
||
19 |
__SCRIPT_ROOT=$(dirname $(readlink -f $0)) |
|
20 |
source $__SCRIPT_ROOT/useful.inc.sh |
|
21 |
||
22 |
function __usage () { |
|
23 |
echo " do-offline-updates.sh" |
|
24 |
echo "Perform offline updates, if available." |
|
25 |
echo "" |
|
26 |
echo "--help -h" |
|
27 |
echo " Show this help message." |
|
28 |
echo "" |
|
29 |
echo "--no-reboot" |
|
30 |
echo " Do not perform an reboot." |
|
31 |
echo "" |
|
32 |
echo "--no-download --check-updates" |
|
33 |
echo " Do not download updates." |
|
34 |
echo " Will show if updates are available." |
|
35 |
echo " Implies --no-reboot." |
|
36 |
echo "" |
|
37 |
}
|
|
38 |
||
39 |
function __sanity_check () { |
|
40 |
# Check that we have the tools needed. |
|
41 |
__find_tool systemctl |
|
42 |
__find_tool pkcon |
|
43 |
||
44 |
if [[ $__SANITY == false ]]; then |
|
45 |
echo "" |
|
46 |
echo "Please install the missing tools." |
|
47 |
echo "" |
|
48 |
exit 1 |
|
49 |
fi |
|
50 |
} |
|
51 |
||
52 |
function __check_for_updates () { |
|
29
by Gustav Hartvigsson
* fixed this... Finally. |
53 |
__silent pkcon get-updates |
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
54 |
if [[ $? == 0 ]]; then |
55 |
echo "Updates are available!" |
|
56 |
echo "" |
|
57 |
__UPDATES_AVAILABLE=true |
|
58 |
else |
|
29
by Gustav Hartvigsson
* fixed this... Finally. |
59 |
echo "No updates available." |
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
60 |
__UPDATES_AVAILABLE=false |
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
61 |
fi |
62 |
}
|
|
63 |
||
64 |
function __download_updates () { |
|
32
by Gustav Hartvigsson
Forgot to trigger the offline update... |
65 |
pkcon update --only-download |
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
66 |
if [[ $? == 0 ]];then |
67 |
__UPDATES_AVAILABLE=true |
|
68 |
else |
|
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
69 |
## huh? |
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
70 |
__UPDATES_AVAILABLE=false |
71 |
fi |
|
72 |
||
73 |
}
|
|
74 |
||
75 |
function __reboot () { |
|
32
by Gustav Hartvigsson
Forgot to trigger the offline update... |
76 |
pkcon offline-trigger |
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
77 |
echo "reboot" |
25
by Gustav Hartvigsson
[do-offline-updates.sh] Woops. |
78 |
eval $__REBOOT_COMMAND |
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
79 |
}
|
80 |
||
81 |
function __parse_args () { |
|
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
82 |
|
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
83 |
while [[ $# -gt 0 ]] |
84 |
do |
|
85 |
case $1 in |
|
86 |
-h|--help) |
|
87 |
__usage
|
|
88 |
exit |
|
89 |
shift |
|
90 |
;; |
|
91 |
--no-reboot) |
|
92 |
__DO_REBOOT=false |
|
93 |
shift |
|
94 |
;; |
|
95 |
--no-download|--check-updates) |
|
96 |
__DO_REBOOT=false |
|
97 |
__DO_DOWNLOAD=false |
|
98 |
shift |
|
99 |
;; |
|
100 |
*) |
|
101 |
echo "Unkown argument \"${1}\"." |
|
102 |
exit 1 |
|
103 |
shift |
|
104 |
;; |
|
105 |
--) |
|
106 |
shift |
|
107 |
break |
|
108 |
;; |
|
109 |
esac |
|
110 |
done |
|
111 |
}
|
|
112 |
||
113 |
function __main () { |
|
29
by Gustav Hartvigsson
* fixed this... Finally. |
114 |
__sanity_check
|
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
115 |
__parse_args $@ |
29
by Gustav Hartvigsson
* fixed this... Finally. |
116 |
__check_for_updates
|
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
117 |
|
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
118 |
if [[ ( "$__DO_DOWNLOAD" == true ) && ( "$__UPDATES_AVAILABLE" == true ) ]]; then |
31
by Gustav Hartvigsson
* That's awkard... |
119 |
__download_updates
|
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
120 |
fi |
121 |
||
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
122 |
if [[ ( "$__DO_REBOOT" == true ) && ( "$__UPDATES_AVAILABLE" == true ) ]]; then |
31
by Gustav Hartvigsson
* That's awkard... |
123 |
__reboot
|
23
by Gustav Hartvigsson
[do-offline-updates.sh] Rewrite to be more inline with the rest of the tools. |
124 |
fi |
125 |
}
|
|
126 |
||
127 |
||
128 |
__main $@ |