update.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # ---------------------------------------------------------------------------
  3. # WeBrake updater — pulls the latest app.py and index.html (and this script)
  4. # directly from the repo and restarts the service.
  5. #
  6. # token.json is local-only: it is never fetched from the repo and never
  7. # overwritten by this script.
  8. #
  9. # /opt/webrake/update.sh
  10. # ---------------------------------------------------------------------------
  11. set -eu
  12. REPO_RAW="${WEBRAKE_REPO:-https://gogs.av2x.dev/av2x/WeBrake/raw/main}"
  13. APP_DIR="/opt/webrake"
  14. say() { printf '\033[1;33m[WeBrake]\033[0m %s\n' "$*"; }
  15. die() { printf '\033[1;31m[WeBrake]\033[0m %s\n' "$*" >&2; exit 1; }
  16. [ "$(id -u)" = "0" ] || die "Run as root inside the Alpine container."
  17. [ -d "$APP_DIR" ] || die "WeBrake is not installed at $APP_DIR — run install.sh first."
  18. changed=0
  19. for f in app.py index.html update.sh; do
  20. say "Fetching $f ..."
  21. wget -q -O "$APP_DIR/$f.new" "$REPO_RAW/$f" || die "Failed to fetch $f from the repo."
  22. if [ -f "$APP_DIR/$f" ] && cmp -s "$APP_DIR/$f" "$APP_DIR/$f.new"; then
  23. rm -f "$APP_DIR/$f.new"
  24. say " $f unchanged."
  25. else
  26. # Keep one backup of the previous version.
  27. [ -f "$APP_DIR/$f" ] && cp "$APP_DIR/$f" "$APP_DIR/$f.bak"
  28. mv "$APP_DIR/$f.new" "$APP_DIR/$f"
  29. say " $f updated (previous copy at $f.bak)."
  30. changed=1
  31. fi
  32. done
  33. chmod +x "$APP_DIR/update.sh"
  34. if [ "$changed" = "1" ]; then
  35. say "Restarting WeBrake service..."
  36. rc-service webrake restart || say "Could not restart via OpenRC — restart manually."
  37. say "Update complete. token.json was left untouched."
  38. else
  39. say "Already up to date."
  40. fi