/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-13 20:18:48 UTC
  • Revision ID: git-v1:df5c8db5509b9612b896bd2a9fc8b50ee5eedb1e
You can use git on Launchpad too.

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
 
####
8
 
 
9
 
__UPDATES_AVAILABLE=false
10
 
__DO_REBOOT=true
11
 
__DO_DOWNLOAD=true
12
 
__REBOOT_COMMAND="systemctl reboot"
13
 
 
14
 
__SANITY=true
15
 
 
16
 
__SCRIPT_ROOT=$(dirname $(readlink -f $0))
17
 
source $__SCRIPT_ROOT/useful.inc.sh
18
 
 
19
 
function __usage () {
20
 
  echo "    do-offline-updates.sh"
21
 
  echo "Perform offline updates, if available."
22
 
  echo ""
23
 
  echo "--help           -h"
24
 
  echo "    Show this help message."
25
 
  echo ""
26
 
  echo "--no-reboot"
27
 
  echo "    Do not perform an reboot."
28
 
  echo ""
29
 
  echo "--no-download    --check-updates"
30
 
  echo "    Do not download updates."
31
 
  echo "    Will show if updates are available."
32
 
  echo "    Implies --no-reboot."
33
 
  echo ""
34
 
}
35
 
 
36
 
function __sanity_check () {
37
 
  # Check that we have the tools needed.
38
 
  __find_tool systemctl
39
 
  __find_tool pkcon
40
 
 
41
 
  if [[ $__SANITY == false ]]; then
42
 
    echo ""
43
 
    echo "Please install the missing tools."
44
 
    echo ""
45
 
    exit 1
46
 
  fi
47
 
48
 
 
49
 
function __check_for_updates () {
50
 
  __silentpkcon get-updates
51
 
  if [[ $? == 0 ]]; then
52
 
    echo "Updates are available!"
53
 
    echo ""
54
 
    __UPDATES_AVAILABLE=true
55
 
  else
56
 
    __UPDATES_AVAILABLE=false
57
 
  fi
58
 
}
59
 
 
60
 
function __download_updates () {
61
 
  pkgcon update --download-only
62
 
  if [[ $? == 0 ]];then
63
 
    __UPDATES_AVAILABLE=true
64
 
  else
65
 
    ## huh?
66
 
    __UPDATES_AVAILABLE=false
67
 
  fi
68
 
 
69
 
}
70
 
 
71
 
function __reboot () {
72
 
  eval $__REBOOT_COMMAND
73
 
}
74
 
 
75
 
function __parse_args () {
76
 
 
77
 
  if [[ -z "$1" ]]
78
 
  then
79
 
    echo "Try --help or -h."
80
 
    exit 1
81
 
  fi
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
 
  __satity_check
115
 
  __parse_args $@
116
 
 
117
 
  if [[ ( __DO_DOWNLOAD == true ) && ( __UPDATE_AVAILABLE == true ) ]]; then
118
 
    __do_download
119
 
  fi
120
 
 
121
 
  if [[ ( __DO_REBOOT == true ) && ( __UPDATE_AVAILABLE == true ) ]]; then
122
 
    __do_reboot
123
 
  fi
124
 
}
125
 
 
126
 
 
127
 
__main $@