Files
gitea-cli/scripts/archive.sh
timmy faee15bc78 Initial commit
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 13:04:09 +08:00

57 lines
1.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib/common.sh
source "${SCRIPT_DIR}/lib/common.sh"
usage() {
cat >&2 <<'EOF'
Usage: archive.sh <repo> [--unarchive] [-y|--yes]
EOF
exit 1
}
[[ $# -ge 1 ]] || usage
REPO=""
ACTION="archive"
while [[ $# -gt 0 ]]; do
case "$1" in
--unarchive) ACTION="unarchive"; shift ;;
-y|--yes) GITEA_YES=1; shift ;;
-h|--help) usage ;;
-*) log_err "未知參數:$1"; usage ;;
*)
if [[ -z "$REPO" ]]; then REPO="$1"; else log_err "多餘參數:$1"; usage; fi
shift ;;
esac
done
[[ -n "$REPO" ]] || usage
load_config
if [[ "$ACTION" == "archive" ]]; then
confirm_destructive "確定要 archive ${GITEA_USER}/${REPO}"
BODY='{"archived":true}'
MSG="archived"
else
confirm_destructive "確定要 unarchive ${GITEA_USER}/${REPO}"
BODY='{"archived":false}'
MSG="unarchived"
fi
log_info "${ACTION} ${GITEA_USER}/${REPO}"
gitea_api PATCH "/repos/${GITEA_USER}/${REPO}" "$BODY"
case "$HTTP_CODE" in
200|201) log_ok "$MSG" ;;
404) log_err "找不到 repo${GITEA_USER}/${REPO}"; exit 1 ;;
*) log_err "${ACTION} 失敗 (HTTP ${HTTP_CODE})"; { cat "$GITEA_API_RESP_FILE"; echo ""; } >&2; exit 1 ;;
esac
log_done "完成"
echo "${GITEA_URL}/${GITEA_USER}/${REPO}"