Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

upgrade.sh 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/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.
  6. # Depends on: bash, curl, xz, sha256sum. optionally jq, gpg
  7. # See section below for available environment vars.
  8. # When no version is specified, updates to the latest release.
  9. # Examples:
  10. # upgrade.sh 1.15.10
  11. # giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
  12. # apply variables from environment
  13. : "${giteabin:="/usr/local/bin/gitea"}"
  14. : "${giteahome:="/var/lib/gitea"}"
  15. : "${giteaconf:="/etc/gitea/app.ini"}"
  16. : "${giteauser:="git"}"
  17. : "${sudocmd:="sudo"}"
  18. : "${arch:="linux-amd64"}"
  19. : "${service_start:="$sudocmd systemctl start gitea"}"
  20. : "${service_stop:="$sudocmd systemctl stop gitea"}"
  21. : "${service_status:="$sudocmd systemctl status gitea"}"
  22. : "${backupopts:=""}" # see `gitea dump --help` for available options
  23. function giteacmd {
  24. if [[ $sudocmd = "su" ]]; then
  25. # `-c` only accept one string as argument.
  26. "$sudocmd" - "$giteauser" -c "$(printf "%q " "$giteabin" "--config" "$giteaconf" "--work-path" "$giteahome" "$@")"
  27. else
  28. "$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
  29. fi
  30. }
  31. function require {
  32. for exe in "$@"; do
  33. command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
  34. done
  35. }
  36. # parse command line arguments
  37. while true; do
  38. case "$1" in
  39. -v | --version ) giteaversion="$2"; shift 2 ;;
  40. -y | --yes ) no_confirm="yes"; shift ;;
  41. --ignore-gpg) ignore_gpg="yes"; shift ;;
  42. "" | -- ) shift; break ;;
  43. * ) echo "Usage: [<environment vars>] upgrade.sh [-v <version>] [-y] [--ignore-gpg]"; exit 1;;
  44. esac
  45. done
  46. # exit once any command fails. this means that each step should be idempotent!
  47. set -euo pipefail
  48. if [[ -f /etc/os-release ]]; then
  49. os_release=$(cat /etc/os-release)
  50. if [[ "$os_release" =~ "OpenWrt" ]]; then
  51. sudocmd="su"
  52. service_start="/etc/init.d/gitea start"
  53. service_stop="/etc/init.d/gitea stop"
  54. service_status="/etc/init.d/gitea status"
  55. else
  56. require systemctl
  57. fi
  58. fi
  59. require curl xz sha256sum "$sudocmd"
  60. # select version to install
  61. if [[ -z "${giteaversion:-}" ]]; then
  62. require jq
  63. giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
  64. echo "Latest available version is $giteaversion"
  65. fi
  66. # confirm update
  67. echo "Checking currently installed version..."
  68. current=$(giteacmd --version | cut -d ' ' -f 3)
  69. [[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
  70. if [[ -z "${no_confirm:-}" ]]; then
  71. echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
  72. echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
  73. read -r confirm
  74. [[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
  75. fi
  76. echo "Upgrading gitea from $current to $giteaversion ..."
  77. pushd "$(pwd)" &>/dev/null
  78. cd "$giteahome" # needed for gitea dump later
  79. # download new binary
  80. binname="gitea-${giteaversion}-${arch}"
  81. binurl="https://dl.gitea.io/gitea/${giteaversion}/${binname}.xz"
  82. echo "Downloading $binurl..."
  83. curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
  84. # validate checksum & gpg signature
  85. sha256sum -c "${binname}.xz.sha256"
  86. if [[ -z "${ignore_gpg:-}" ]]; then
  87. require gpg
  88. gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
  89. gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
  90. fi
  91. rm "${binname}".xz.{sha256,asc}
  92. # unpack binary + make executable
  93. xz --decompress --force "${binname}.xz"
  94. chown "$giteauser" "$binname"
  95. chmod +x "$binname"
  96. # stop gitea, create backup, replace binary, restart gitea
  97. echo "Flushing gitea queues at $(date)"
  98. giteacmd manager flush-queues
  99. echo "Stopping gitea at $(date)"
  100. $service_stop
  101. echo "Creating backup in $giteahome"
  102. giteacmd dump $backupopts
  103. echo "Updating binary at $giteabin"
  104. cp -f "$giteabin" "$giteabin.bak" && mv -f "$binname" "$giteabin"
  105. $service_start
  106. $service_status
  107. echo "Upgrade to $giteaversion successful!"
  108. popd