Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to select option via arguments #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 67 additions & 59 deletions stop-sauron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
#------------------------#
debugFlag='false'

while getopts 'x' flag; do
while getopts 'xo:' flag; do
case "${flag}" in
x)
debugFlag='true' ;;
o)
if [[ $OPTARG > 0 && $OPTARG < 3 ]]; then
selectedOption="$(($OPTARG-1))"
fi
;;
*)
printGetOptsMenuUsage
exit 1 ;;
Expand Down Expand Up @@ -53,64 +58,67 @@ echo ""
PS3='Please enter your choice: '
options=("Stop Sauron's eye" "Start Sauron's eye" "Clean the logs" "Remove the config" "Create lifesaver" "Exit")
COLUMNS=20
select opt in "${options[@]}"; do
case $opt in
"Stop Sauron's eye")
writeLog "[Select] - 1 --> Disable"
writeEcho "You have chosen to disable 'Sauron' and its minions!"
writeEcho "Processing..."
ACTION="disable"
LOADER="unload"
break
;;
"Start Sauron's eye")
writeLog "[Select] - 2 --> Enable"
writeEcho "You have chosen to enable 'Sauron' and its minions!"
writeEcho "Processing..."
ACTION="enable"
LOADER="load"
break
;;
"Clean the logs")
writeLog "[Select] - 3 --> Clean the logs"
writeEcho "Removing the evidence..."
deleteLogfiles;
writeEcho "Done!"
writeEcho "Bye!"
exit;
break
;;
"Remove the config")
writeLog "[Select] - 4 --> Remove the config"
writeEcho "Starting Sauron's eye to prevent trouble (back to the original state)..."
ACTION="enable"
LOADER="load"
writeEcho "Removing the configuration"
RESET_CONFIG="true"
writeEcho "Done!"
writeEcho "Bye!"
break
;;
"Create lifesaver")
writeLog "[Select] - 5 --> Create lifesaver"
writeEcho "Securing your original configuration in case of the unexpected"
createBackupfiles;
writeEcho "Done!"
writeEcho "Bye!"
exit
break
;;
"Exit")
writeLog "[Select] - 6 --> Exit"
writeEcho "Bye!"
writeLog "[Session] - End"
writeLog "-------------------"
exit
break
;;
*) echo "invalid option $REPLY" ;;
esac
done

# Check for a numeric argument to use as an option; otherwise use select menu
[[ $selectedOption ]] && opt="${options[$selectedOption]}" || select opt in "${options[@]}"; do break; done

case $opt in
"Stop Sauron's eye")
writeLog "[Select] - 1 --> Disable"
writeEcho "You have chosen to disable 'Sauron' and its minions!"
writeEcho "Processing..."
ACTION="disable"
LOADER="unload"
break
;;
"Start Sauron's eye")
writeLog "[Select] - 2 --> Enable"
writeEcho "You have chosen to enable 'Sauron' and its minions!"
writeEcho "Processing..."
ACTION="enable"
LOADER="load"
break
;;
"Clean the logs")
writeLog "[Select] - 3 --> Clean the logs"
writeEcho "Removing the evidence..."
deleteLogfiles;
writeEcho "Done!"
writeEcho "Bye!"
exit;
break
;;
"Remove the config")
writeLog "[Select] - 4 --> Remove the config"
writeEcho "Starting Sauron's eye to prevent trouble (back to the original state)..."
ACTION="enable"
LOADER="load"
writeEcho "Removing the configuration"
RESET_CONFIG="true"
writeEcho "Done!"
writeEcho "Bye!"
break
;;
"Create lifesaver")
writeLog "[Select] - 5 --> Create lifesaver"
writeEcho "Securing your original configuration in case of the unexpected"
createBackupfiles;
writeEcho "Done!"
writeEcho "Bye!"
exit
break
;;
"Exit")
writeLog "[Select] - 6 --> Exit"
writeEcho "Bye!"
writeLog "[Session] - End"
writeLog "-------------------"
exit
break
;;
*) echo "invalid option $REPLY" ;;
esac




Expand Down