/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-09-30 19:22:26 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20240930192226-1pwn3bnp0c09g2za
* fixed this... Finally.

Show diffs side-by-side

added added

removed removed

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