From f370fb67a4537e0cca7695323fe4cf9e1fcf3eba Mon Sep 17 00:00:00 2001 From: Diego Fernandez Diaz Date: Thu, 4 Apr 2024 10:35:01 +0200 Subject: [PATCH] Auth funcionality added --- icons/upload_icon.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/icons/upload_icon.sh b/icons/upload_icon.sh index a5f12ee..1471d1a 100755 --- a/icons/upload_icon.sh +++ b/icons/upload_icon.sh @@ -79,7 +79,7 @@ upload_icon() { curl -L -s -X GET "$GIF_FILE" -o "$TEMP_FILE" if verify_gif "$TEMP_FILE"; then - curl -X POST -F "file=@$TEMP_FILE;filename=/ICONS/$FILE_NAME" "$URL" + curl -X POST -F "file=@$TEMP_FILE;filename=/ICONS/$FILE_NAME" "$URL" $AUTH echo -e "${GREEN}Uploaded icon:${NC} $FILE_NAME${NC}" else echo -e "${RED}Error: File $FILE_NAME does not appear to be a valid GIF file.${NC}" @@ -89,6 +89,19 @@ upload_icon() { rm -f "$TEMP_FILE" } +# Prompt for authentication if required +prompt_for_auth() { + read -rp "Is authentication required on awtrix device? (y/n): " auth_needed + if [[ "$auth_needed" == "y" ]]; then + read -rp "Enter username: " USERNAME + read -rsp "Enter password: " PASSWORD + echo + AUTH="--user \"$USERNAME:$PASSWORD\"" + else + AUTH="" + fi +} + # Prompt for IP address if not provided as a command-line argument prompt_ip_address() { if [ -z "$1" ]; then @@ -112,6 +125,9 @@ main() { # Prompt for IP address prompt_ip_address "$1" + # Prompt for Auth + prompt_for_auth + # List icon directories echo -e "${GREEN}Available icon directories:${NC}" directories=($(list_icon_directories))