- 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
121 lines
3.3 KiB
Bash
121 lines
3.3 KiB
Bash
#!/bin/bash
|
|
# Upload macOS Build to Forgejo Packages
|
|
# Usage: ./upload_to_packages.sh -v 1.0.0
|
|
# Uses your Forgejo credentials (same as git)
|
|
# First run will prompt for credentials and save them to this session
|
|
|
|
set -e
|
|
|
|
# Parse arguments
|
|
VERSION=""
|
|
FORGEJO_USER=""
|
|
FORGEJO_PASS=""
|
|
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
|
|
|
|
# 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
|
|
|
|
# Load credentials from environment
|
|
FORGEJO_USER="${FORGEJO_USER}"
|
|
FORGEJO_PASS="${FORGEJO_PASS}"
|
|
|
|
# Verify required parameters
|
|
if [ -z "$VERSION" ]; then
|
|
echo "ERROR: Version parameter required" >&2
|
|
echo "Usage: $0 -v VERSION [-u FORGEJO_URL]" >&2
|
|
echo "Example: $0 -v 1.0.0" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# If no credentials, prompt user interactively
|
|
if [ -z "$FORGEJO_USER" ] || [ -z "$FORGEJO_PASS" ]; then
|
|
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..."
|
|
|
|
# Get file info
|
|
DMG_SIZE=$(du -m "$DMG_PATH" | cut -f1)
|
|
CHECKSUM=$(cat "$CHECKSUM_PATH")
|
|
|
|
echo "File: WebDropBridge.dmg ($DMG_SIZE MB)"
|
|
echo "Checksum: ${CHECKSUM:0:16}..."
|
|
|
|
# Create basic auth header
|
|
BASIC_AUTH=$(echo -n "${FORGEJO_USER}:${FORGEJO_PASS}" | base64)
|
|
|
|
# Upload DMG
|
|
echo ""
|
|
echo "Uploading DMG..."
|
|
DMG_URL="$FORGEJO_URL/api/v1/repos/$REPO/packages/generic/webdrop-bridge/$VERSION/WebDropBridge.dmg"
|
|
|
|
HTTP_CODE=$(curl -s -w "%{http_code}" -X PUT \
|
|
-H "Authorization: Basic $BASIC_AUTH" \
|
|
--data-binary "@$DMG_PATH" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
"$DMG_URL" \
|
|
-o /tmp/curl_response.txt)
|
|
|
|
if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 200 ]; then
|
|
echo "✓ DMG uploaded successfully"
|
|
else
|
|
echo "ERROR uploading DMG (HTTP $HTTP_CODE)"
|
|
cat /tmp/curl_response.txt
|
|
exit 1
|
|
fi
|
|
|
|
# Upload checksum
|
|
echo "Uploading checksum..."
|
|
CHECKSUM_URL="$FORGEJO_URL/api/v1/repos/$REPO/packages/generic/webdrop-bridge/$VERSION/WebDropBridge.dmg.sha256"
|
|
|
|
HTTP_CODE=$(curl -s -w "%{http_code}" -X PUT \
|
|
-H "Authorization: Basic $BASIC_AUTH" \
|
|
-d "$CHECKSUM" \
|
|
-H "Content-Type: text/plain" \
|
|
"$CHECKSUM_URL" \
|
|
-o /tmp/curl_response.txt)
|
|
|
|
if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 200 ]; then
|
|
echo "✓ Checksum uploaded successfully"
|
|
else
|
|
echo "ERROR uploading checksum (HTTP $HTTP_CODE)"
|
|
cat /tmp/curl_response.txt
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "✓ Upload complete!"
|
|
echo "View at: $FORGEJO_URL/$REPO/packages"
|