/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1

« back to all changes in this revision

Viewing changes to scripts/do-offline-updates.sh

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-14 11:47:07 UTC
  • Revision ID: git-v1:8ab298a55bc6629f1bf4fc1660469a59f4ebf0cf
General fixup.

* Removed unused ARGS declarations.

* Made all variabels start with two underlines

* Expilitly declared functions as such.

* Expilitly declared strings (file names and such) as strings
  at the start of the files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env bash
2
 
 
3
 
####
4
 
# FILE NAME do-offline-updates.sh
5
 
#
6
 
# Authors:
7
 
#    Gustav Hartvigsson 2024
8
 
#    Distributed under the Cool Licence 1.1
9
 
#
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 () {
53
 
  __silent pkcon get-updates
54
 
  if [[ $? == 0 ]]; then
55
 
    echo "Updates are available!"
56
 
    echo ""
57
 
    __UPDATES_AVAILABLE=true
58
 
  else
59
 
    echo "No updates available."
60
 
    __UPDATES_AVAILABLE=false
61
 
  fi
62
 
}
63
 
 
64
 
function __download_updates () {
65
 
  pkcon update --only-download
66
 
  if [[ $? == 0 ]];then
67
 
    __UPDATES_AVAILABLE=true
68
 
  else
69
 
    ## huh?
70
 
    __UPDATES_AVAILABLE=false
71
 
  fi
72
 
 
73
 
}
74
 
 
75
 
function __reboot () {
76
 
  pkcon offline-trigger
77
 
  echo "reboot"
78
 
  eval $__REBOOT_COMMAND
79
 
}
80
 
 
81
 
function __parse_args () {
82
 
 
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 () {
114
 
  __sanity_check
115
 
  __parse_args $@
116
 
  __check_for_updates
117
 
 
118
 
  if [[ ( "$__DO_DOWNLOAD" == true ) && ( "$__UPDATES_AVAILABLE" == true ) ]]; then
119
 
    __download_updates
120
 
  fi
121
 
 
122
 
  if [[ ( "$__DO_REBOOT" == true ) && ( "$__UPDATES_AVAILABLE" == true ) ]]; then
123
 
    __reboot
124
 
  fi
125
 
}
126
 
 
127
 
 
128
 
__main $@