Satan made me do it

This commit is contained in:
kake26 2024-11-15 22:48:57 -06:00
parent 7c113360c8
commit 795f72db03
Signed by: kake26
GPG key ID: E8AFC43591876B4D
9 changed files with 118 additions and 69 deletions

70
modules/keydb.bash Normal file
View file

@ -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"

47
modules/menu.bash Executable file
View file

@ -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

View file

@ -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"