diff --git a/build/scripts/upload_to_packages.ps1 b/build/scripts/upload_to_packages.ps1 index 9a0cbac..8bad813 100644 --- a/build/scripts/upload_to_packages.ps1 +++ b/build/scripts/upload_to_packages.ps1 @@ -1,7 +1,7 @@ # Upload Windows Build to Forgejo Packages # Usage: .\upload_to_packages.ps1 -Version 1.0.0 # Uses your Forgejo credentials (same as git) -# Set via: $env:FORGEJO_USER = "username"; $env:FORGEJO_PASS = "password" +# First run will prompt for credentials and save them to this session param( [Parameter(Mandatory=$false)] @@ -13,6 +13,8 @@ param( [Parameter(Mandatory=$false)] [string]$ForgejoPW, + [switch]$ClearCredentials, + [string]$ForgejoUrl = "https://git.him-tools.de", [string]$Repo = "HIM-public/webdrop-bridge", [string]$ExePath = "build\dist\windows\WebDropBridge.exe", @@ -21,6 +23,14 @@ param( $ErrorActionPreference = "Stop" +# Handle --ClearCredentials flag +if ($ClearCredentials) { + Remove-Item env:FORGEJO_USER -ErrorAction SilentlyContinue + Remove-Item env:FORGEJO_PASS -ErrorAction SilentlyContinue + Write-Host "[OK] Credentials cleared from this session" -ForegroundColor Green + exit 0 +} + # Get credentials from sources (in order of priority) if (-not $ForgejoUser) { $ForgejoUser = $env:FORGEJO_USER @@ -30,14 +40,24 @@ if (-not $ForgejoPW) { $ForgejoPW = $env:FORGEJO_PASS } +# If still no credentials, prompt user interactively if (-not $ForgejoUser -or -not $ForgejoPW) { - Write-Host "ERROR: Forgejo credentials not found!" -ForegroundColor Red - Write-Host "Set credentials using environment variables:" -ForegroundColor Yellow - Write-Host " `$env:FORGEJO_USER = 'your_username'" - Write-Host " `$env:FORGEJO_PASS = 'your_password'" - Write-Host "" -ForegroundColor Yellow - Write-Host "These should match your Forgejo login credentials." - exit 1 + Write-Host "Forgejo credentials not found. Enter your credentials:" -ForegroundColor Yellow + + if (-not $ForgejoUser) { + $ForgejoUser = Read-Host "Username" + } + + if (-not $ForgejoPW) { + $securePass = Read-Host "Password" -AsSecureString + $ForgejoPW = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($securePass)) + } + + # Save credentials to environment for this session + $env:FORGEJO_USER = $ForgejoUser + $env:FORGEJO_PASS = $ForgejoPW + Write-Host "[OK] Credentials saved to this PowerShell session" -ForegroundColor Green + Write-Host "Tip: Credentials will persist until you close PowerShell or run: .\upload_to_packages.ps1 -ClearCredentials" -ForegroundColor Gray } # Verify Version parameter diff --git a/build/scripts/upload_to_packages.sh b/build/scripts/upload_to_packages.sh index 2575b8b..64be0ef 100644 --- a/build/scripts/upload_to_packages.sh +++ b/build/scripts/upload_to_packages.sh @@ -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..."