Skip to content

Commit

Permalink
Optimised logic if no application is selected for installation
Browse files Browse the repository at this point in the history
  • Loading branch information
XternA committed Oct 22, 2024
1 parent 20e3eb7 commit ccab8e2
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions scripts/proxy/proxy-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,43 @@ display_banner() {
}

read_app_data() {
APP_DATA="jq -r '.[] | select(.is_enabled == true) | \"\(.name) \(.alias)\"' \"$JSON_FILE\""
APP_DATA="jq -r '.[] | select(.is_enabled == true) | \"\(.name) \(.alias) \(.is_enabled)\"' \"$JSON_FILE\""
echo "$(eval $APP_DATA)"
}

display_info() {
display_banner
local type="$1"
local is_install="${2-true}"

echo "The following proxy applications will be $type.\n"
echo "Total Proxies: ${RED}$TOTAL_PROXIES${NC}\n"

printf "%-4s %-21s\n" "No." "Name"
printf "%-4s %-21s\n" "---" "--------------------"
printf "%s\n" "$APP_DATA" | awk -v GREEN="$GREEN" -v NC="$NC" '
BEGIN { counter = 1 }
{
printf "%-4s %s%-21s%s\n", counter, GREEN, $1, NC
counter++
}'
can_install="true"

has_apps_services="$(echo "$APP_DATA" | awk '{if ($2 == "true" || $3 == "true") {print "true"; exit}}')"

if [ -z "$has_apps_services" ] && [ "$is_install" = "true" ]; then
echo "No applications selected to install."
can_install="false"
else
echo "The following proxy applications will be $type.\n"
echo "Total Proxies: ${RED}$TOTAL_PROXIES${NC}\n"

printf "%-4s %-21s\n" "No." "Name"
printf "%-4s %-21s\n" "---" "--------------------"
printf "%s\n" "$APP_DATA" | awk -v GREEN="$GREEN" -v NC="$NC" '
BEGIN { counter = 1 }
{
printf "%-4s %s%-21s%s\n", counter, GREEN, $1, NC
counter++
}'
fi

[ "$is_install" = "true" ] && echo "\nOption:\n ${RED}a = select applications${NC}"
printf "\nDo you want to proceed? (Y/N): "; read input

if [ "$can_install" = "false" ]; then
printf "\nSelect applications or press Enter to return: "
else
printf "\nDo you want to proceed? (Y/N): "
fi
read -r input
}

display_proxy_info() {
Expand Down Expand Up @@ -76,16 +90,24 @@ install_proxy_instance() {
display_info installed

case "$input" in
"")
[ "$can_install" = "false" ] && exit 0
printf "\nInvalid option.\n\nPress Enter to continue..."; read -r input
;;
a)
$APP_SELECTION proxy proxy
APP_DATA="$(eval read_app_data)"
;;
[Yy])
break
[ "$can_install" = "true" ] && break
printf "\nInvalid option.\n\nPress Enter to continue..."; read -r input
;;
[Nn])
clear
exit 0
if [ "$can_install" = "true" ]; then
clear
exit 0
fi
printf "\nInvalid option.\n\nPress Enter to continue..."; read -r input
;;
*)
printf "\nInvalid option.\n\nPress Enter to continue..."; read -r input
Expand All @@ -109,7 +131,7 @@ install_proxy_instance() {
display_proxy_info "$proxy_url"
echo "PROXY_URL=$proxy_url" > "$ENV_PROXY_FILE"

echo "$APP_DATA" | while read -r name alias; do
echo "$APP_DATA" | while read -r name alias is_enabled; do
if [ "$alias" = null ]; then
app_name=$(echo "$name" | tr '[:upper:]' '[:lower:]')
else
Expand Down Expand Up @@ -220,7 +242,7 @@ remove_proxy_instance() {
while test "$install_count" -le "$TOTAL_PROXIES"; do
echo "${GREEN}[ ${YELLOW}Removing Proxy Set ${RED}${install_count} ${GREEN}]${NC}"

echo "$APP_DATA" | while read -r name alias; do
echo "$APP_DATA" | while read -r name alias is_enabled; do
if [ "$alias" = null ]; then
app_name=$(echo "$name" | tr '[:upper:]' '[:lower:]')
else
Expand Down

0 comments on commit ccab8e2

Please sign in to comment.