Skip to main content

Simple Menu in Bash

#!/bin/bash

pause() {
read -p "[INFO] Press [Enter] key for continue..."
clear
return 0
}


display_menu() {
echo "--------------------------"
echo "- WordPress Stack for CT -"
echo "--------------------------"
echo "1. Compile and Setup nginx"
echo "2. Setup php5-fpm (chroot enabled)"
echo "--------------------------"
echo "4. New WordPress Host"
echo "5. Remove Host"
echo "9. (cache) Update WP, Plugins and binaries"
echo "--------------------------"
echo "0. EXIT"
echo "--------------------------"

return 0
}

read_options() {
while
read -n1 -p "Enter your choice: " CHOICE
do
if [[ "${CHOICE}" =~ ^[0-9]+$ ]]; then
break
else
echo -e " [ERROR] Only numbers!"
fi
done

clear
if [ "${CHOICE}" == "0" ]; then
exit 0
else
set -x
if [ -f "./run/${CHOICE}"* ]
then
"./run/${CHOICE}"* 2>&1 | tee -a "./${CHOICE}.log"
fi
set +x
pause
fi

return 0
}

main() {
clear
while true; do
display_menu
read_options
done

exit 0
}

main