You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upgrade.sh 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # This is an update script for gitea installed via the binary distribution
  4. # from dl.gitea.io on linux as systemd service. It performs a backup and updates
  5. # Gitea in place.
  6. # NOTE: This adds the GPG Signing Key of the Gitea maintainers to the keyring.
  7. # Depends on: bash, curl, xz, sha256sum, gpg. optionally jq.
  8. # Usage: [environment vars] upgrade.sh [version]
  9. # See section below for available environment vars.
  10. # When no version is specified, updates to the latest release.
  11. # Examples:
  12. # upgrade.sh 1.15.10
  13. # giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
  14. # apply variables from environment
  15. : "${giteabin:="/usr/local/bin/gitea"}"
  16. : "${giteahome:="/var/lib/gitea"}"
  17. : "${giteaconf:="/etc/gitea/app.ini"}"
  18. : "${giteauser:="git"}"
  19. : "${sudocmd:="sudo"}"
  20. : "${arch:="linux-amd64"}"
  21. : "${backupopts:=""}" # see `gitea dump --help` for available options
  22. function giteacmd {
  23. "$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
  24. }
  25. function require {
  26. for exe in "$@"; do
  27. command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
  28. done
  29. }
  30. require systemctl curl xz sha256sum gpg "$sudocmd"
  31. # select version to install
  32. if [[ -z "${1:-}" ]]; then
  33. require jq
  34. giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
  35. else
  36. giteaversion="$1"
  37. fi
  38. # confirm update
  39. current=$(giteacmd --version | cut --delimiter=' ' --fields=3)
  40. [[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
  41. echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
  42. echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
  43. read -r confirm
  44. [[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
  45. pushd "$(pwd)" &>/dev/null
  46. cd "$giteahome" # needed for gitea dump later
  47. # download new binary
  48. binname="gitea-${giteaversion}-${arch}"
  49. binurl="https://dl.gitea.io/gitea/${giteaversion}/${binname}.xz"
  50. echo "Downloading $binurl..."
  51. curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
  52. # validate checksum & gpg signature (exit script if error)
  53. sha256sum --check "${binname}.xz.sha256"
  54. gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
  55. gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
  56. rm "${binname}".xz.{sha256,asc}
  57. # unpack binary + make executable
  58. xz --decompress "${binname}.xz"
  59. chown "$giteauser" "$binname"
  60. chmod +x "$binname"
  61. # stop gitea, create backup, replace binary, restart gitea
  62. echo "Stopping gitea at $(date)"
  63. giteacmd manager flush-queues
  64. $sudocmd systemctl stop gitea
  65. echo "Creating backup in $giteahome"
  66. giteacmd dump $backupopts
  67. echo "Updating binary at $giteabin"
  68. mv --force --backup "$binname" "$giteabin"
  69. $sudocmd systemctl start gitea
  70. $sudocmd systemctl status gitea
  71. popd