From d3feab8e0467a0edd764de9a6c87740cfc6dddca Mon Sep 17 00:00:00 2001 From: Brad Cimbura <421012+hpz937@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:19:55 -0600 Subject: [PATCH] add ability to save token --- publish_to_gitea.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/publish_to_gitea.sh b/publish_to_gitea.sh index 3429490..4513f57 100755 --- a/publish_to_gitea.sh +++ b/publish_to_gitea.sh @@ -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" -# Prompt for password securely -read -sp "Enter your Gitea password or token: " PASSWORD -echo +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 -PASSWORD_OR_TOKEN=$(printf '%q' "$PASSWORD") + # 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"