feat: Add interactive credential prompts to upload scripts

- Scripts now prompt for username/password on first run if not set
- Credentials are saved to session environment variables
- No need to pre-set env vars before running
- Windows: Add -ClearCredentials flag to clear session credentials
- macOS: Add --clear-credentials flag to clear session credentials
- Credentials persist for duration of PowerShell/shell session
- Much simpler UX: just run script and enter credentials when prompted
This commit is contained in:
claudi 2026-01-28 14:49:02 +01:00
parent a4659d0a92
commit 847692eef6
2 changed files with 57 additions and 23 deletions

View file

@ -2,7 +2,7 @@
# Upload macOS Build to Forgejo Packages
# Usage: ./upload_to_packages.sh -v 1.0.0
# Uses your Forgejo credentials (same as git)
# Set via: export FORGEJO_USER="username"; export FORGEJO_PASS="password"
# First run will prompt for credentials and save them to this session
set -e
@ -14,23 +14,28 @@ FORGEJO_URL="https://git.him-tools.de"
REPO="HIM-public/webdrop-bridge"
DMG_PATH="build/dist/macos/WebDropBridge.dmg"
CHECKSUM_PATH="build/dist/macos/WebDropBridge.dmg.sha256"
CLEAR_CREDS=false
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version) VERSION="$2"; shift 2;;
-u|--url) FORGEJO_URL="$2"; shift 2;;
--clear-credentials) CLEAR_CREDS=true; shift;;
*) echo "Unknown option: $1"; exit 1;;
esac
done
# Load credentials from environment
if [ -z "$FORGEJO_USER" ]; then
FORGEJO_USER="$FORGEJO_USER"
# Handle --clear-credentials flag
if [ "$CLEAR_CREDS" = true ]; then
unset FORGEJO_USER
unset FORGEJO_PASS
echo "[OK] Credentials cleared from this session"
exit 0
fi
if [ -z "$FORGEJO_PASS" ]; then
FORGEJO_PASS="$FORGEJO_PASS"
fi
# Load credentials from environment
FORGEJO_USER="${FORGEJO_USER}"
FORGEJO_PASS="${FORGEJO_PASS}"
# Verify required parameters
if [ -z "$VERSION" ]; then
@ -40,15 +45,24 @@ if [ -z "$VERSION" ]; then
exit 1
fi
# If no credentials, prompt user interactively
if [ -z "$FORGEJO_USER" ] || [ -z "$FORGEJO_PASS" ]; then
echo "ERROR: Forgejo credentials not found!" >&2
echo "" >&2
echo "Set your credentials using environment variables:" >&2
echo " export FORGEJO_USER='your_username'" >&2
echo " export FORGEJO_PASS='your_password'" >&2
echo "" >&2
echo "These should match your Forgejo login credentials." >&2
exit 1
echo "Forgejo credentials not found. Enter your credentials:"
if [ -z "$FORGEJO_USER" ]; then
read -p "Username: " FORGEJO_USER
fi
if [ -z "$FORGEJO_PASS" ]; then
read -sp "Password: " FORGEJO_PASS
echo ""
fi
# Export for this session
export FORGEJO_USER
export FORGEJO_PASS
echo "[OK] Credentials saved to this shell session"
echo "Tip: Credentials will persist until you close the terminal or run: $0 --clear-credentials"
fi
echo "Uploading WebDropBridge $VERSION to Forgejo Packages..."