mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 16:44:26 +00:00
Fix script compatiable with OpenWrt (#19000)
* Fix compatibility of upgrade.sh in openwrt and add service init script for openwrt. * Apply suggestions from code review Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: zeripath <art27@cantab.net> * Update contrib/upgrade.sh Co-authored-by: Norwin <noerw@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Norwin <noerw@users.noreply.github.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
eceab9e26f
commit
ddf7f1319f
35
contrib/init/openwrt/gitea
Normal file
35
contrib/init/openwrt/gitea
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
USE_PROCD=1
|
||||||
|
|
||||||
|
# PROCD_DEBUG=1
|
||||||
|
|
||||||
|
START=90
|
||||||
|
STOP=10
|
||||||
|
|
||||||
|
PROG=/opt/gitea/gitea
|
||||||
|
GITEA_WORK_DIR=/opt/gitea
|
||||||
|
CONF_FILE=$GITEA_WORK_DIR/app.ini
|
||||||
|
|
||||||
|
start_service(){
|
||||||
|
procd_open_instance gitea
|
||||||
|
procd_set_param env GITEA_WORK_DIR=$GITEA_WORK_DIR
|
||||||
|
procd_set_param env HOME=$GITEA_WORK_DIR
|
||||||
|
procd_set_param command $PROG web -c $CONF_FILE
|
||||||
|
procd_set_param file $CONF_FILE
|
||||||
|
procd_set_param user git
|
||||||
|
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} # respawn automatically if something died, be careful if you have an alternative process supervisor
|
||||||
|
procd_close_instance
|
||||||
|
}
|
||||||
|
|
||||||
|
start(){
|
||||||
|
service_start $PROG
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(){
|
||||||
|
service_stop $PROG
|
||||||
|
}
|
||||||
|
|
||||||
|
reload(){
|
||||||
|
service_reload $PROG
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# This is an update script for gitea installed via the binary distribution
|
# This is an update script for gitea installed via the binary distribution
|
||||||
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
|
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
|
||||||
# Gitea in place.
|
# Gitea in place.
|
||||||
@ -13,6 +11,42 @@ set -euo pipefail
|
|||||||
# upgrade.sh 1.15.10
|
# upgrade.sh 1.15.10
|
||||||
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
|
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-v | --version ) ver="$2"; shift 2 ;;
|
||||||
|
-y | --yes ) no_confirm="yes"; shift ;;
|
||||||
|
--ignore-gpg) ignore_gpg="yes"; shift ;;
|
||||||
|
-- ) shift; break ;;
|
||||||
|
* ) break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
|
||||||
|
function require {
|
||||||
|
for exe in "$@"; do
|
||||||
|
command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
require curl xz sha256sum gpg
|
||||||
|
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
os_release=$(cat /etc/os-release)
|
||||||
|
|
||||||
|
if [[ "$os_release" =~ "OpenWrt" ]]; then
|
||||||
|
sudocmd="su"
|
||||||
|
service_start="/etc/init.d/gitea start"
|
||||||
|
service_stop="/etc/init.d/gitea stop"
|
||||||
|
service_status="/etc/init.d/gitea status"
|
||||||
|
else
|
||||||
|
require systemctl
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# apply variables from environment
|
# apply variables from environment
|
||||||
: "${giteabin:="/usr/local/bin/gitea"}"
|
: "${giteabin:="/usr/local/bin/gitea"}"
|
||||||
: "${giteahome:="/var/lib/gitea"}"
|
: "${giteahome:="/var/lib/gitea"}"
|
||||||
@ -20,34 +54,40 @@ set -euo pipefail
|
|||||||
: "${giteauser:="git"}"
|
: "${giteauser:="git"}"
|
||||||
: "${sudocmd:="sudo"}"
|
: "${sudocmd:="sudo"}"
|
||||||
: "${arch:="linux-amd64"}"
|
: "${arch:="linux-amd64"}"
|
||||||
|
: "${service_start:="$sudocmd systemctl start gitea"}"
|
||||||
|
: "${service_stop:="$sudocmd systemctl stop gitea"}"
|
||||||
|
: "${service_status:="$sudocmd systemctl status gitea"}"
|
||||||
: "${backupopts:=""}" # see `gitea dump --help` for available options
|
: "${backupopts:=""}" # see `gitea dump --help` for available options
|
||||||
|
|
||||||
function giteacmd {
|
|
||||||
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function require {
|
function giteacmd {
|
||||||
for exe in "$@"; do
|
if [[ $sudocmd = "su" ]]; then
|
||||||
command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
|
"$sudocmd" - "$giteauser" -c "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
|
||||||
done
|
else
|
||||||
|
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
require systemctl curl xz sha256sum gpg "$sudocmd"
|
|
||||||
|
|
||||||
# select version to install
|
# select version to install
|
||||||
if [[ -z "${1:-}" ]]; then
|
if [[ -z "${ver:-}" ]]; then
|
||||||
require jq
|
require jq
|
||||||
giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
|
giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
|
||||||
else
|
else
|
||||||
giteaversion="$1"
|
giteaversion="$ver"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# confirm update
|
# confirm update
|
||||||
current=$(giteacmd --version | cut --delimiter=' ' --fields=3)
|
current=$(giteacmd --version | cut -d ' ' -f 3)
|
||||||
[[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
|
[[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
|
||||||
echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
|
if [[ -z "${no_confirm:-}" ]]; then
|
||||||
echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
|
echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
|
||||||
read -r confirm
|
echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
|
||||||
[[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
|
read -r confirm
|
||||||
|
[[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Upgrading gitea from $current to $giteaversion ..."
|
||||||
|
|
||||||
pushd "$(pwd)" &>/dev/null
|
pushd "$(pwd)" &>/dev/null
|
||||||
cd "$giteahome" # needed for gitea dump later
|
cd "$giteahome" # needed for gitea dump later
|
||||||
@ -59,9 +99,11 @@ echo "Downloading $binurl..."
|
|||||||
curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
|
curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
|
||||||
|
|
||||||
# validate checksum & gpg signature (exit script if error)
|
# validate checksum & gpg signature (exit script if error)
|
||||||
sha256sum --check "${binname}.xz.sha256"
|
sha256sum -c "${binname}.xz.sha256"
|
||||||
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
|
if [[ -z "${ignore_gpg:-}" ]]; then
|
||||||
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
|
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
|
||||||
|
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
|
||||||
|
fi
|
||||||
rm "${binname}".xz.{sha256,asc}
|
rm "${binname}".xz.{sha256,asc}
|
||||||
|
|
||||||
# unpack binary + make executable
|
# unpack binary + make executable
|
||||||
@ -72,12 +114,14 @@ chmod +x "$binname"
|
|||||||
# stop gitea, create backup, replace binary, restart gitea
|
# stop gitea, create backup, replace binary, restart gitea
|
||||||
echo "Stopping gitea at $(date)"
|
echo "Stopping gitea at $(date)"
|
||||||
giteacmd manager flush-queues
|
giteacmd manager flush-queues
|
||||||
$sudocmd systemctl stop gitea
|
$service_stop
|
||||||
echo "Creating backup in $giteahome"
|
echo "Creating backup in $giteahome"
|
||||||
giteacmd dump $backupopts
|
giteacmd dump $backupopts
|
||||||
echo "Updating binary at $giteabin"
|
echo "Updating binary at $giteabin"
|
||||||
mv --force --backup "$binname" "$giteabin"
|
cp -f "$giteabin" "$giteabin.bak" && mv -f "$binname" "$giteabin"
|
||||||
$sudocmd systemctl start gitea
|
$service_start
|
||||||
$sudocmd systemctl status gitea
|
$service_status
|
||||||
|
|
||||||
|
echo "Upgrade to $giteaversion successful!"
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
Loading…
Reference in New Issue
Block a user