add ability to save token
This commit is contained in:
@@ -6,12 +6,32 @@ USERNAME=$2 # Your Gitea username
|
|||||||
OWNER=$3 # The owner of the package (user or organization)
|
OWNER=$3 # The owner of the package (user or organization)
|
||||||
PROJECT_DIR=$4 # Path to the PHP project directory (not zipped)
|
PROJECT_DIR=$4 # Path to the PHP project directory (not zipped)
|
||||||
VERSION=$5 # Package version (optional)
|
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
|
# Prompt for password securely
|
||||||
read -sp "Enter your Gitea password or token: " PASSWORD
|
read -sp "Enter your Gitea password or token: " PASSWORD
|
||||||
echo
|
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")
|
PASSWORD_OR_TOKEN=$(printf '%q' "$PASSWORD")
|
||||||
|
fi
|
||||||
|
|
||||||
# Create a ZIP file from the project directory
|
# Create a ZIP file from the project directory
|
||||||
ZIP_NAME="package-$(date +%Y%m%d%H%M%S).zip"
|
ZIP_NAME="package-$(date +%Y%m%d%H%M%S).zip"
|
||||||
|
|||||||
Reference in New Issue
Block a user