3
3
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
4
4
# Gitea in place.
5
5
# NOTE: This adds the GPG Signing Key of the Gitea maintainers to the keyring.
6
- # Depends on: bash, curl, xz, sha256sum, gpg. optionally jq.
7
- # Usage: [environment vars] upgrade.sh [version]
6
+ # Depends on: bash, curl, xz, sha256sum. optionally jq, gpg
8
7
# See section below for available environment vars.
9
8
# When no version is specified, updates to the latest release.
10
9
# Examples:
11
10
# upgrade.sh 1.15.10
12
11
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
13
12
14
- while true ; do
15
- case " $1 " in
16
- -v | --version ) ver= " $2 " ; shift 2 ;;
17
- -y | --yes ) no_confirm= " yes " ; shift ;;
18
- --ignore-gpg) ignore_gpg= " yes " ; shift ;;
19
- -- ) shift ; break ;;
20
- * ) break ;;
21
- esac
22
- done
23
-
24
- set -euo pipefail
13
+ # apply variables from environment
14
+ : " ${giteabin := " /usr/local/bin/gitea " } "
15
+ : " ${giteahome := " /var/lib/gitea " } "
16
+ : " ${giteaconf := " /etc/gitea/app.ini " } "
17
+ : " ${giteauser := " git " } "
18
+ : " ${sudocmd := " sudo " } "
19
+ : " ${arch := " linux-amd64 " } "
20
+ : " ${service_start := " $sudocmd systemctl start gitea " } "
21
+ : " ${service_stop := " $sudocmd systemctl stop gitea " } "
22
+ : " ${service_status := " $sudocmd systemctl status gitea " } "
23
+ : " ${backupopts := " " } " # see `gitea dump --help` for available options
25
24
25
+ function giteacmd {
26
+ if [[ $sudocmd = " su" ]]; then
27
+ " $sudocmd " - " $giteauser " -c " $giteabin " --config " $giteaconf " --work-path " $giteahome " " $@ "
28
+ else
29
+ " $sudocmd " --user " $giteauser " " $giteabin " --config " $giteaconf " --work-path " $giteahome " " $@ "
30
+ fi
31
+ }
26
32
27
33
function require {
28
34
for exe in " $@ " ; do
29
35
command -v " $exe " & > /dev/null || (echo " missing dependency '$exe '" ; exit 1)
30
36
done
31
37
}
32
38
39
+ # parse command line arguments
40
+ while true ; do
41
+ case " $1 " in
42
+ -v | --version ) giteaversion=" $2 " ; shift 2 ;;
43
+ -y | --yes ) no_confirm=" yes" ; shift ;;
44
+ --ignore-gpg) ignore_gpg=" yes" ; shift ;;
45
+ " " | -- ) shift ; break ;;
46
+ * ) echo " Usage: [<environment vars>] upgrade.sh [-v <version>] [-y] [--ignore-gpg]" ; exit 1;;
47
+ esac
48
+ done
33
49
34
- require curl xz sha256sum gpg
50
+ # exit once any command fails. this means that each step should be idempotent!
51
+ set -euo pipefail
35
52
36
53
if [[ -f /etc/os-release ]]; then
37
54
os_release=$( cat /etc/os-release)
@@ -46,38 +63,17 @@ if [[ -f /etc/os-release ]]; then
46
63
fi
47
64
fi
48
65
49
-
50
- # apply variables from environment
51
- : " ${giteabin:= " /usr/local/bin/gitea" } "
52
- : " ${giteahome:= " /var/lib/gitea" } "
53
- : " ${giteaconf:= " /etc/gitea/app.ini" } "
54
- : " ${giteauser:= " git" } "
55
- : " ${sudocmd:= " sudo" } "
56
- : " ${arch:= " linux-amd64" } "
57
- : " ${service_start:= " $sudocmd systemctl start gitea" } "
58
- : " ${service_stop:= " $sudocmd systemctl stop gitea" } "
59
- : " ${service_status:= " $sudocmd systemctl status gitea" } "
60
- : " ${backupopts:= " " } " # see `gitea dump --help` for available options
61
-
62
-
63
- function giteacmd {
64
- if [[ $sudocmd = " su" ]]; then
65
- " $sudocmd " - " $giteauser " -c " $giteabin " --config " $giteaconf " --work-path " $giteahome " " $@ "
66
- else
67
- " $sudocmd " --user " $giteauser " " $giteabin " --config " $giteaconf " --work-path " $giteahome " " $@ "
68
- fi
69
- }
66
+ require curl xz sha256sum " $sudocmd "
70
67
71
68
# select version to install
72
- if [[ -z " ${ver :- } " ]]; then
69
+ if [[ -z " ${giteaversion :- } " ]]; then
73
70
require jq
74
71
giteaversion=$( curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
75
- else
76
- giteaversion=" $ver "
72
+ echo " Latest available version is $giteaversion "
77
73
fi
78
74
79
-
80
75
# confirm update
76
+ echo " Checking currently installed version..."
81
77
current=$( giteacmd --version | cut -d ' ' -f 3)
82
78
[[ " $current " == " $giteaversion " ]] && echo " $current is already installed, stopping." && exit 1
83
79
if [[ -z " ${no_confirm:- } " ]]; then
@@ -98,22 +94,24 @@ binurl="https://dl.gitea.io/gitea/${giteaversion}/${binname}.xz"
98
94
echo " Downloading $binurl ..."
99
95
curl --connect-timeout 10 --silent --show-error --fail --location -O " $binurl {,.sha256,.asc}"
100
96
101
- # validate checksum & gpg signature (exit script if error)
97
+ # validate checksum & gpg signature
102
98
sha256sum -c " ${binname} .xz.sha256"
103
99
if [[ -z " ${ignore_gpg:- } " ]]; then
100
+ require gpg
104
101
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
105
102
gpg --verify " ${binname} .xz.asc" " ${binname} .xz" || { echo ' Signature does not match' ; exit 1; }
106
103
fi
107
104
rm " ${binname} " .xz.{sha256,asc}
108
105
109
106
# unpack binary + make executable
110
- xz --decompress " ${binname} .xz"
107
+ xz --decompress --force " ${binname} .xz"
111
108
chown " $giteauser " " $binname "
112
109
chmod +x " $binname "
113
110
114
111
# stop gitea, create backup, replace binary, restart gitea
115
- echo " Stopping gitea at $( date) "
112
+ echo " Flushing gitea queues at $( date) "
116
113
giteacmd manager flush-queues
114
+ echo " Stopping gitea at $( date) "
117
115
$service_stop
118
116
echo " Creating backup in $giteahome "
119
117
giteacmd dump $backupopts
0 commit comments