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:
parent
a4659d0a92
commit
847692eef6
2 changed files with 57 additions and 23 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
# Upload Windows Build to Forgejo Packages
|
# Upload Windows Build to Forgejo Packages
|
||||||
# Usage: .\upload_to_packages.ps1 -Version 1.0.0
|
# Usage: .\upload_to_packages.ps1 -Version 1.0.0
|
||||||
# Uses your Forgejo credentials (same as git)
|
# 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(
|
param(
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
|
|
@ -13,6 +13,8 @@ param(
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[string]$ForgejoPW,
|
[string]$ForgejoPW,
|
||||||
|
|
||||||
|
[switch]$ClearCredentials,
|
||||||
|
|
||||||
[string]$ForgejoUrl = "https://git.him-tools.de",
|
[string]$ForgejoUrl = "https://git.him-tools.de",
|
||||||
[string]$Repo = "HIM-public/webdrop-bridge",
|
[string]$Repo = "HIM-public/webdrop-bridge",
|
||||||
[string]$ExePath = "build\dist\windows\WebDropBridge.exe",
|
[string]$ExePath = "build\dist\windows\WebDropBridge.exe",
|
||||||
|
|
@ -21,6 +23,14 @@ param(
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$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)
|
# Get credentials from sources (in order of priority)
|
||||||
if (-not $ForgejoUser) {
|
if (-not $ForgejoUser) {
|
||||||
$ForgejoUser = $env:FORGEJO_USER
|
$ForgejoUser = $env:FORGEJO_USER
|
||||||
|
|
@ -30,14 +40,24 @@ if (-not $ForgejoPW) {
|
||||||
$ForgejoPW = $env:FORGEJO_PASS
|
$ForgejoPW = $env:FORGEJO_PASS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If still no credentials, prompt user interactively
|
||||||
if (-not $ForgejoUser -or -not $ForgejoPW) {
|
if (-not $ForgejoUser -or -not $ForgejoPW) {
|
||||||
Write-Host "ERROR: Forgejo credentials not found!" -ForegroundColor Red
|
Write-Host "Forgejo credentials not found. Enter your credentials:" -ForegroundColor Yellow
|
||||||
Write-Host "Set credentials using environment variables:" -ForegroundColor Yellow
|
|
||||||
Write-Host " `$env:FORGEJO_USER = 'your_username'"
|
if (-not $ForgejoUser) {
|
||||||
Write-Host " `$env:FORGEJO_PASS = 'your_password'"
|
$ForgejoUser = Read-Host "Username"
|
||||||
Write-Host "" -ForegroundColor Yellow
|
}
|
||||||
Write-Host "These should match your Forgejo login credentials."
|
|
||||||
exit 1
|
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
|
# Verify Version parameter
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# Upload macOS Build to Forgejo Packages
|
# Upload macOS Build to Forgejo Packages
|
||||||
# Usage: ./upload_to_packages.sh -v 1.0.0
|
# Usage: ./upload_to_packages.sh -v 1.0.0
|
||||||
# Uses your Forgejo credentials (same as git)
|
# 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
|
set -e
|
||||||
|
|
||||||
|
|
@ -14,23 +14,28 @@ FORGEJO_URL="https://git.him-tools.de"
|
||||||
REPO="HIM-public/webdrop-bridge"
|
REPO="HIM-public/webdrop-bridge"
|
||||||
DMG_PATH="build/dist/macos/WebDropBridge.dmg"
|
DMG_PATH="build/dist/macos/WebDropBridge.dmg"
|
||||||
CHECKSUM_PATH="build/dist/macos/WebDropBridge.dmg.sha256"
|
CHECKSUM_PATH="build/dist/macos/WebDropBridge.dmg.sha256"
|
||||||
|
CLEAR_CREDS=false
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-v|--version) VERSION="$2"; shift 2;;
|
-v|--version) VERSION="$2"; shift 2;;
|
||||||
-u|--url) FORGEJO_URL="$2"; shift 2;;
|
-u|--url) FORGEJO_URL="$2"; shift 2;;
|
||||||
|
--clear-credentials) CLEAR_CREDS=true; shift;;
|
||||||
*) echo "Unknown option: $1"; exit 1;;
|
*) echo "Unknown option: $1"; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Load credentials from environment
|
# Handle --clear-credentials flag
|
||||||
if [ -z "$FORGEJO_USER" ]; then
|
if [ "$CLEAR_CREDS" = true ]; then
|
||||||
FORGEJO_USER="$FORGEJO_USER"
|
unset FORGEJO_USER
|
||||||
|
unset FORGEJO_PASS
|
||||||
|
echo "[OK] Credentials cleared from this session"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$FORGEJO_PASS" ]; then
|
# Load credentials from environment
|
||||||
FORGEJO_PASS="$FORGEJO_PASS"
|
FORGEJO_USER="${FORGEJO_USER}"
|
||||||
fi
|
FORGEJO_PASS="${FORGEJO_PASS}"
|
||||||
|
|
||||||
# Verify required parameters
|
# Verify required parameters
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -z "$VERSION" ]; then
|
||||||
|
|
@ -40,15 +45,24 @@ if [ -z "$VERSION" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If no credentials, prompt user interactively
|
||||||
if [ -z "$FORGEJO_USER" ] || [ -z "$FORGEJO_PASS" ]; then
|
if [ -z "$FORGEJO_USER" ] || [ -z "$FORGEJO_PASS" ]; then
|
||||||
echo "ERROR: Forgejo credentials not found!" >&2
|
echo "Forgejo credentials not found. Enter your credentials:"
|
||||||
echo "" >&2
|
|
||||||
echo "Set your credentials using environment variables:" >&2
|
if [ -z "$FORGEJO_USER" ]; then
|
||||||
echo " export FORGEJO_USER='your_username'" >&2
|
read -p "Username: " FORGEJO_USER
|
||||||
echo " export FORGEJO_PASS='your_password'" >&2
|
fi
|
||||||
echo "" >&2
|
|
||||||
echo "These should match your Forgejo login credentials." >&2
|
if [ -z "$FORGEJO_PASS" ]; then
|
||||||
exit 1
|
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
|
fi
|
||||||
|
|
||||||
echo "Uploading WebDropBridge $VERSION to Forgejo Packages..."
|
echo "Uploading WebDropBridge $VERSION to Forgejo Packages..."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue