add ability to save token

This commit is contained in:
Brad Cimbura
2024-02-16 12:19:55 -06:00
parent 58a3be83fe
commit d3feab8e04

View File

@@ -6,12 +6,32 @@ USERNAME=$2 # Your Gitea username
OWNER=$3 # The owner of the package (user or organization)
PROJECT_DIR=$4 # Path to the PHP project directory (not zipped)
VERSION=$5 # Package version (optional)
CONFIG_DIR="$HOME/.config/gitea-cli-tools"
TOKEN_FILE="$CONFIG_DIR/${USERNAME}_token"
echo "$TOKEN_FILE"
# Check if the token file exists and use it
if [ -f "$TOKEN_FILE" ]; then
echo "Using stored token..."
PASSWORD_OR_TOKEN=$(base64 --decode < "$TOKEN_FILE")
else
# Prompt for password securely
read -sp "Enter your Gitea password or token: " PASSWORD
echo
# Ask if the user wants to store the password/token
read -p "Do you want to store the token for future use? (y/n): " STORE_RESPONSE
if [[ $STORE_RESPONSE =~ ^[Yy]$ ]]; then
# Ensure the configuration directory exists
mkdir -p "$CONFIG_DIR"
# Encode and save the token/password
echo "$PASSWORD" | base64 > "$TOKEN_FILE"
echo "Token stored."
fi
PASSWORD_OR_TOKEN=$(printf '%q' "$PASSWORD")
fi
# Create a ZIP file from the project directory
ZIP_NAME="package-$(date +%Y%m%d%H%M%S).zip"