/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:03:54 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20240930190354-o57vi8aaqi0ezwz8
Misspelled:  pkcon.

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