diff --git a/config.ini b/modules/config.ini similarity index 100% rename from config.ini rename to modules/config.ini diff --git a/config.json b/modules/config.json similarity index 100% rename from config.json rename to modules/config.json diff --git a/config_ini.bash b/modules/config_ini.bash similarity index 100% rename from config_ini.bash rename to modules/config_ini.bash diff --git a/config_json.bash b/modules/config_json.bash similarity index 100% rename from config_json.bash rename to modules/config_json.bash diff --git a/modules/keydb.bash b/modules/keydb.bash new file mode 100644 index 0000000..dac0886 --- /dev/null +++ b/modules/keydb.bash @@ -0,0 +1,70 @@ +#!/bin/bash + +dbcmd="keydb-cli" + +# Check if keydb-cli is installed +check_redis_cli() { + if ! command -v $dbcmd &> /dev/null; then + echo "Error: $dbcmd is not installed. Please install keydb package." + exit 1 + fi +} + +# Save data to Redis +# Usage: redis_save key value +redis_save() { + local key="$1" + local value="$2" + + if [[ -z "$key" || -z "$value" ]]; then + echo "Error: Both key and value are required" + echo "Usage: redis_save key value" + return 1 + fi + + if $dbcmd SET "$key" "$value"; then + echo "Successfully saved '$value' with key '$key'" + else + echo "Failed to save data to Redis" + return 1 + fi +} + +# Retrieve data from Redis +# Usage: redis_get key +redis_get() { + local key="$1" + + if [[ -z "$key" ]]; then + echo "Error: Key is required" + echo "Usage: redis_get key" + return 1 + fi + + local value + value=$($dbcmd GET "$key") + if [[ $? -eq 0 ]]; then + if [[ -z "$value" ]]; then + echo "No value found for key '$key'" + return 1 + else + echo "$value" + fi + else + echo "Failed to retrieve data from Redis" + return 1 + fi +} + +# Example usage +check_redis_cli + +# Uncomment these lines to test the functions +# redis_save "mykey" "Hello from Bash!" +# redis_get "mykey" + +# Code goes here + +redis_save "bashini" "new" +redis_get "bashini" + diff --git a/modules/menu.bash b/modules/menu.bash new file mode 100755 index 0000000..58dffd7 --- /dev/null +++ b/modules/menu.bash @@ -0,0 +1,47 @@ +#!/bin/bash + +# Function to display the menu using whiptail +show_menu() { + while true; do + CHOICE=$(whiptail --title "Main Menu" \ + --menu "Choose an option:" 15 60 4 \ + "1" "Option 1" \ + "2" "Option 2" \ + "3" "Option 3" \ + "4" "Exit" 3>&1 1>&2 2>&3) + + exitstatus=$? + if [ $exitstatus != 0 ]; then + echo "Menu cancelled." + exit 1 + fi + + case $CHOICE in + 1) + whiptail --title "Option 1" --msgbox "You selected Option 1" 8 45 + ;; + 2) + whiptail --title "Option 2" --msgbox "You selected Option 2" 8 45 + ;; + 3) + whiptail --title "Option 3" --msgbox "You selected Option 3" 8 45 + ;; + 4) + clear + echo "Goodbye!" + exit 0 + ;; + esac + done +} + +# Check if whiptail is installed +if ! command -v whiptail &> /dev/null; then + echo "Error: whiptail is not installed" + echo "Please install it using: sudo apt-get install whiptail" + exit 1 +fi + +# Clear the screen and show the menu +clear +show_menu \ No newline at end of file diff --git a/ntfy.bash b/modules/ntfy.bash similarity index 100% rename from ntfy.bash rename to modules/ntfy.bash diff --git a/sys.bash b/modules/sys.bash similarity index 100% rename from sys.bash rename to modules/sys.bash diff --git a/script.bash b/script.bash index 789bcd0..669b690 100755 --- a/script.bash +++ b/script.bash @@ -18,75 +18,7 @@ cleanup() { true } -source ./config_json.bash # can be json or ini, I preffer json +source ./modules/config_json.bash # can be json or ini, I preffer json # Keydb / Redis interaction functions, works for both -dbcmd="keydb-cli" - -# Check if keydb-cli is installed -check_redis_cli() { - if ! command -v $dbcmd &> /dev/null; then - echo "Error: $dbcmd is not installed. Please install keydb package." - exit 1 - fi -} - -# Save data to Redis -# Usage: redis_save key value -redis_save() { - local key="$1" - local value="$2" - - if [[ -z "$key" || -z "$value" ]]; then - echo "Error: Both key and value are required" - echo "Usage: redis_save key value" - return 1 - fi - - if $dbcmd SET "$key" "$value"; then - echo "Successfully saved '$value' with key '$key'" - else - echo "Failed to save data to Redis" - return 1 - fi -} - -# Retrieve data from Redis -# Usage: redis_get key -redis_get() { - local key="$1" - - if [[ -z "$key" ]]; then - echo "Error: Key is required" - echo "Usage: redis_get key" - return 1 - fi - - local value - value=$($dbcmd GET "$key") - if [[ $? -eq 0 ]]; then - if [[ -z "$value" ]]; then - echo "No value found for key '$key'" - return 1 - else - echo "$value" - fi - else - echo "Failed to retrieve data from Redis" - return 1 - fi -} - -# Example usage -check_redis_cli - -# Uncomment these lines to test the functions -# redis_save "mykey" "Hello from Bash!" -# redis_get "mykey" - -# Code goes here - -redis_save "bashini" "new" -redis_get "bashini" -