Skip to content

Commit 2109f6c

Browse files
adorakalbearl-warren
authored andcommitted
[BRANDING] adapt forgejo/contrib/upgrade.sh
Reviewed at: https://codeberg.org/forgejo/forgejo/pulls/605 (cherry picked from commit fb14bcd800fea3a780bfb85423dc84651ec44b21) (cherry picked from commit f9d9edb118fec32e564ebcbec29b70d9176be02c) (cherry picked from commit 2831912fc00d0052479e25b96f1a69b4294d1e16)
1 parent 8b99f98 commit 2109f6c

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

contrib/upgrade.sh

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/usr/bin/env bash
2-
# This is an update script for gitea installed via the binary distribution
3-
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
4-
# Gitea in place.
5-
# NOTE: This adds the GPG Signing Key of the Gitea maintainers to the keyring.
2+
# This is an update script for forgejo installed via the binary distribution
3+
# from codeberg.org/forgejo/forgejo on linux as systemd service. It
4+
# performs a backup and updates Forgejo in place.
5+
# NOTE: This adds the GPG Signing Key of the Forgejo maintainers to the keyring.
66
# Depends on: bash, curl, xz, sha256sum. optionally jq, gpg
77
# See section below for available environment vars.
88
# When no version is specified, updates to the latest release.
99
# Examples:
1010
# upgrade.sh 1.15.10
11-
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
11+
# forgejohome=/opt/forgejo forgejoconf=$forgejohome/app.ini upgrade.sh
1212

1313
# apply variables from environment
14-
: "${giteabin:="/usr/local/bin/gitea"}"
15-
: "${giteahome:="/var/lib/gitea"}"
16-
: "${giteaconf:="/etc/gitea/app.ini"}"
17-
: "${giteauser:="git"}"
14+
: "${forgejobin:="/usr/local/bin/forgejo"}"
15+
: "${forgejohome:="/var/lib/forgejo"}"
16+
: "${forgejoconf:="/etc/forgejo/app.ini"}"
17+
: "${forgejouser:="git"}"
1818
: "${sudocmd:="sudo"}"
1919
: "${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
20+
: "${service_start:="$sudocmd systemctl start forgejo"}"
21+
: "${service_stop:="$sudocmd systemctl stop forgejo"}"
22+
: "${service_status:="$sudocmd systemctl status forgejo"}"
23+
: "${backupopts:=""}" # see `forgejo dump --help` for available options
2424

25-
function giteacmd {
25+
function forgejocmd {
2626
if [[ $sudocmd = "su" ]]; then
2727
# `-c` only accept one string as argument.
28-
"$sudocmd" - "$giteauser" -c "$(printf "%q " "$giteabin" "--config" "$giteaconf" "--work-path" "$giteahome" "$@")"
28+
"$sudocmd" - "$forgejouser" -c "$(printf "%q " "$forgejobin" "--config" "$forgejoconf" "--work-path" "$forgejohome" "$@")"
2929
else
30-
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
30+
"$sudocmd" --user "$forgejouser" "$forgejobin" --config "$forgejoconf" --work-path "$forgejohome" "$@"
3131
fi
3232
}
3333

@@ -40,7 +40,7 @@ function require {
4040
# parse command line arguments
4141
while true; do
4242
case "$1" in
43-
-v | --version ) giteaversion="$2"; shift 2 ;;
43+
-v | --version ) forgejoversion="$2"; shift 2 ;;
4444
-y | --yes ) no_confirm="yes"; shift ;;
4545
--ignore-gpg) ignore_gpg="yes"; shift ;;
4646
"" | -- ) shift; break ;;
@@ -56,9 +56,9 @@ if [[ -f /etc/os-release ]]; then
5656

5757
if [[ "$os_release" =~ "OpenWrt" ]]; then
5858
sudocmd="su"
59-
service_start="/etc/init.d/gitea start"
60-
service_stop="/etc/init.d/gitea stop"
61-
service_status="/etc/init.d/gitea status"
59+
service_start="/etc/init.d/forgejo start"
60+
service_stop="/etc/init.d/forgejo stop"
61+
service_status="/etc/init.d/forgejo status"
6262
else
6363
require systemctl
6464
fi
@@ -67,60 +67,60 @@ fi
6767
require curl xz sha256sum "$sudocmd"
6868

6969
# select version to install
70-
if [[ -z "${giteaversion:-}" ]]; then
70+
if [[ -z "${forgejoversion:-}" ]]; then
7171
require jq
72-
giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
73-
echo "Latest available version is $giteaversion"
72+
forgejoversion=$(curl --connect-timeout 10 -sL 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases?draft=false&pre-release=false&limit=1' -H 'accept: application/json' | jq -r '.[0].tag_name | sub("v"; "")')
73+
echo "Latest available version is $forgejoversion"
7474
fi
7575

7676
# confirm update
7777
echo "Checking currently installed version..."
78-
current=$(giteacmd --version | cut -d ' ' -f 3)
79-
[[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
78+
current=$(forgejocmd --version | cut -d ' ' -f 3)
79+
[[ "$current" == "$forgejoversion" ]] && echo "$current is already installed, stopping." && exit 1
8080
if [[ -z "${no_confirm:-}" ]]; then
81-
echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
82-
echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
81+
echo "Make sure to read the changelog first: https://codeberg.org/forgejo/forgejo/src/branch/forgejo/CHANGELOG.md"
82+
echo "Are you ready to update forgejo from ${current} to ${forgejoversion}? (y/N)"
8383
read -r confirm
8484
[[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
8585
fi
8686

87-
echo "Upgrading gitea from $current to $giteaversion ..."
87+
echo "Upgrading forgejo from $current to $forgejoversion ..."
8888

8989
pushd "$(pwd)" &>/dev/null
90-
cd "$giteahome" # needed for gitea dump later
90+
cd "$forgejohome" # needed for forgejo dump later
9191

9292
# download new binary
93-
binname="gitea-${giteaversion}-${arch}"
94-
binurl="https://dl.gitea.io/gitea/${giteaversion}/${binname}.xz"
93+
binname="forgejo-${forgejoversion}-${arch}"
94+
binurl="https://codeberg.org/forgejo/forgejo/releases/download/v${forgejoversion}/${binname}.xz"
9595
echo "Downloading $binurl..."
9696
curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
9797

9898
# validate checksum & gpg signature
9999
sha256sum -c "${binname}.xz.sha256"
100100
if [[ -z "${ignore_gpg:-}" ]]; then
101101
require gpg
102-
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
102+
gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
103103
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
104104
fi
105105
rm "${binname}".xz.{sha256,asc}
106106

107107
# unpack binary + make executable
108108
xz --decompress --force "${binname}.xz"
109-
chown "$giteauser" "$binname"
109+
chown "$forgejouser" "$binname"
110110
chmod +x "$binname"
111111

112-
# stop gitea, create backup, replace binary, restart gitea
113-
echo "Flushing gitea queues at $(date)"
114-
giteacmd manager flush-queues
115-
echo "Stopping gitea at $(date)"
112+
# stop forgejo, create backup, replace binary, restart forgejo
113+
echo "Flushing forgejo queues at $(date)"
114+
forgejocmd manager flush-queues
115+
echo "Stopping forgejo at $(date)"
116116
$service_stop
117-
echo "Creating backup in $giteahome"
118-
giteacmd dump $backupopts
119-
echo "Updating binary at $giteabin"
120-
cp -f "$giteabin" "$giteabin.bak" && mv -f "$binname" "$giteabin"
117+
echo "Creating backup in $forgejohome"
118+
forgejocmd dump $backupopts
119+
echo "Updating binary at $forgejobin"
120+
cp -f "$forgejobin" "$forgejobin.bak" && mv -f "$binname" "$forgejobin"
121121
$service_start
122122
$service_status
123123

124-
echo "Upgrade to $giteaversion successful!"
124+
echo "Upgrade to $forgejoversion successful!"
125125

126126
popd

0 commit comments

Comments
 (0)