1
1
#! /usr/bin/env bash
2
- set -euo pipefail
3
-
4
2
# This is an update script for gitea installed via the binary distribution
5
3
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
6
4
# Gitea in place.
@@ -13,41 +11,83 @@ set -euo pipefail
13
11
# upgrade.sh 1.15.10
14
12
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
15
13
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
25
+
26
+
27
+ function require {
28
+ for exe in " $@ " ; do
29
+ command -v " $exe " & > /dev/null || (echo " missing dependency '$exe '" ; exit 1)
30
+ done
31
+ }
32
+
33
+
34
+ require curl xz sha256sum gpg
35
+
36
+ if [[ -f /etc/os-release ]]; then
37
+ os_release=$( cat /etc/os-release)
38
+
39
+ if [[ " $os_release " =~ " OpenWrt" ]]; then
40
+ sudocmd=" su"
41
+ service_start=" /etc/init.d/gitea start"
42
+ service_stop=" /etc/init.d/gitea stop"
43
+ service_status=" /etc/init.d/gitea status"
44
+ else
45
+ require systemctl
46
+ fi
47
+ fi
48
+
49
+
16
50
# apply variables from environment
17
51
: " ${giteabin:= " /usr/local/bin/gitea" } "
18
52
: " ${giteahome:= " /var/lib/gitea" } "
19
53
: " ${giteaconf:= " /etc/gitea/app.ini" } "
20
54
: " ${giteauser:= " git" } "
21
55
: " ${sudocmd:= " sudo" } "
22
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" } "
23
60
: " ${backupopts:= " " } " # see `gitea dump --help` for available options
24
61
25
- function giteacmd {
26
- " $sudocmd " --user " $giteauser " " $giteabin " --config " $giteaconf " --work-path " $giteahome " " $@ "
27
- }
28
62
29
- function require {
30
- for exe in " $@ " ; do
31
- command -v " $exe " & > /dev/null || (echo " missing dependency '$exe '" ; exit 1)
32
- done
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
33
69
}
34
- require systemctl curl xz sha256sum gpg " $sudocmd "
35
70
36
71
# select version to install
37
- if [[ -z " ${1 :- } " ]]; then
72
+ if [[ -z " ${ver :- } " ]]; then
38
73
require jq
39
74
giteaversion=$( curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
40
75
else
41
- giteaversion=" $1 "
76
+ giteaversion=" $ver "
42
77
fi
43
78
79
+
44
80
# confirm update
45
- current=$( giteacmd --version | cut --delimiter= ' ' --fields= 3)
81
+ current=$( giteacmd --version | cut -d ' ' -f 3)
46
82
[[ " $current " == " $giteaversion " ]] && echo " $current is already installed, stopping." && exit 1
47
- echo " Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
48
- echo " Are you ready to update Gitea from ${current} to ${giteaversion} ? (y/N)"
49
- read -r confirm
50
- [[ " $confirm " == " y" ]] || [[ " $confirm " == " Y" ]] || exit 1
83
+ if [[ -z " ${no_confirm:- } " ]]; then
84
+ echo " Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
85
+ echo " Are you ready to update Gitea from ${current} to ${giteaversion} ? (y/N)"
86
+ read -r confirm
87
+ [[ " $confirm " == " y" ]] || [[ " $confirm " == " Y" ]] || exit 1
88
+ fi
89
+
90
+ echo " Upgrading gitea from $current to $giteaversion ..."
51
91
52
92
pushd " $( pwd) " & > /dev/null
53
93
cd " $giteahome " # needed for gitea dump later
@@ -59,9 +99,11 @@ echo "Downloading $binurl..."
59
99
curl --connect-timeout 10 --silent --show-error --fail --location -O " $binurl {,.sha256,.asc}"
60
100
61
101
# validate checksum & gpg signature (exit script if error)
62
- sha256sum --check " ${binname} .xz.sha256"
63
- gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
64
- gpg --verify " ${binname} .xz.asc" " ${binname} .xz" || { echo ' Signature does not match' ; exit 1; }
102
+ sha256sum -c " ${binname} .xz.sha256"
103
+ if [[ -z " ${ignore_gpg:- } " ]]; then
104
+ gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
105
+ gpg --verify " ${binname} .xz.asc" " ${binname} .xz" || { echo ' Signature does not match' ; exit 1; }
106
+ fi
65
107
rm " ${binname} " .xz.{sha256,asc}
66
108
67
109
# unpack binary + make executable
@@ -72,12 +114,14 @@ chmod +x "$binname"
72
114
# stop gitea, create backup, replace binary, restart gitea
73
115
echo " Stopping gitea at $( date) "
74
116
giteacmd manager flush-queues
75
- $sudocmd systemctl stop gitea
117
+ $service_stop
76
118
echo " Creating backup in $giteahome "
77
119
giteacmd dump $backupopts
78
120
echo " Updating binary at $giteabin "
79
- mv --force --backup " $binname " " $giteabin "
80
- $sudocmd systemctl start gitea
81
- $sudocmd systemctl status gitea
121
+ cp -f " $giteabin " " $giteabin .bak" && mv -f " $binname " " $giteabin "
122
+ $service_start
123
+ $service_status
124
+
125
+ echo " Upgrade to $giteaversion successful!"
82
126
83
127
popd
0 commit comments