/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: 2024-11-02 21:10:35 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241102211035-ev3nfuwqytbdabxd
* Fixed useful.inc.sh
* Fixed if statements not working in do-offline-updates.sh

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 --download-only
 
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
  echo "reboot"
 
77
  eval $__REBOOT_COMMAND
 
78
}
 
79
 
 
80
function __parse_args () {
 
81
 
 
82
  while [[ $# -gt 0 ]]
 
83
  do
 
84
    case $1 in
 
85
      -h|--help)
 
86
         __usage
 
87
         exit
 
88
         shift
 
89
      ;;
 
90
      --no-reboot)
 
91
        __DO_REBOOT=false
 
92
        shift
 
93
        ;;
 
94
      --no-download|--check-updates)
 
95
        __DO_REBOOT=false
 
96
        __DO_DOWNLOAD=false
 
97
        shift
 
98
        ;;
 
99
      *)
 
100
        echo "Unkown argument \"${1}\"."
 
101
        exit 1
 
102
        shift
 
103
      ;;
 
104
      --)
 
105
        shift
 
106
        break
 
107
      ;;
 
108
    esac
 
109
  done
 
110
}
 
111
 
 
112
function __main () {
 
113
  __sanity_check
 
114
  __parse_args $@
 
115
  __check_for_updates
 
116
 
 
117
  if [[ ( "$__DO_DOWNLOAD" == true ) && ( "$__UPDATES_AVAILABLE" == true ) ]]; then
 
118
    __do_download
 
119
  fi
 
120
 
 
121
  if [[ ( "$__DO_REBOOT" == true ) && ( "$__UPDATES_AVAILABLE" == true ) ]]; then
 
122
    __do_reboot
 
123
  fi
 
124
}
 
125
 
 
126
 
 
127
__main $@