Skip to content

Commit

Permalink
Merge pull request #947 from plexguide/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Admin9705 authored Sep 13, 2024
2 parents b9567f2 + 96fa4d3 commit 4c390ff
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 27 deletions.
23 changes: 18 additions & 5 deletions mods/scripts/apps_interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ config_type=$2 # 'personal' for personal configurations, 'official' for officia

# Function: check_deployment_status
check_deployment_status() {
# Load the configuration file to get the port_number
# Load the configuration file to get the port_number and expose value
if [[ "$config_type" == "personal" ]]; then
config_file="/pg/personal_configs/${app_name}.cfg"
else
Expand All @@ -28,12 +28,25 @@ check_deployment_status() {
source "$config_file"
fi

# Determine port status based on the 'expose' variable
if [[ "$expose" == "127.0.0.1"* ]]; then
port_status="Closed"
else
port_status="Open"
fi

# Check if the app's Docker container is running
local container_status=$(docker ps --filter "name=^/${app_name}$" --format "{{.Names}}")

if [[ "$container_status" == "$app_name" ]]; then
echo -e "${GREEN}[Deployed]${NC} $app_name - Port: $port_number"
echo -e "${GREEN}[Deployed]${NC} $app_name - Port: $port_number/$port_status"
else
echo -e "${RED}[Not Deployed]${NC} $app_name"
# App is not deployed, show potential port status if deployed
if [[ "$port_status" == "Closed" ]]; then
echo -e "${RED}[Not Deployed]${NC} $app_name - Port Closed if Deployed"
else
echo -e "${RED}[Not Deployed]${NC} $app_name - Port Open if Deployed"
fi
fi
}

Expand Down Expand Up @@ -145,7 +158,7 @@ apps_interface() {
echo "Z) Exit"
echo ""

read -p "Choose an option: " choice
read -p "Make a Choice > " choice

case ${choice,,} in # Convert input to lowercase
d)
Expand Down Expand Up @@ -177,4 +190,4 @@ apps_interface() {
}

# Run the interface with the provided app name and type
apps_interface
apps_interface
86 changes: 86 additions & 0 deletions mods/scripts/apps_parse copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# Function to parse default variables and update the config file
parse_and_store_defaults() {
local app_name="$1"
local app_type="$2" # 'personal' for personal apps, 'official' for official apps

# Determine paths based on app type
if [[ "$app_type" == "personal" ]]; then
local config_path="/pg/personal_configs/${app_name}.cfg"
local app_path="/pg/p_apps/${app_name}.app"
else
local config_path="/pg/config/${app_name}.cfg"
local app_path="/pg/apps/${app_name}.app"
fi

# Check if the config file exists, create it if not
[[ ! -f "$config_path" ]] && touch "$config_path"

# Check if the app file exists
if [[ ! -f "$app_path" ]]; then
# echo "Error: App file $app_path does not exist."
return 1
fi

# Source the app's default_variables function
source "$app_path"

# Call the default_variables function for the specific app
default_variables

# Parse the default_variables function and write to config if not exist
declare -f default_variables | while read line; do
if [[ $line =~ ^[[:space:]]*([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$ ]]; then
var="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"

# Remove any existing quotes and semicolons from the value
value=$(echo "$value" | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" -e 's/;$//')

# Check if the variable exists in the config file
if ! grep -q "^${var}=" "$config_path"; then
# Add quotes around the value (without semicolon) and write to config
echo "${var}=\"${value}\"" >> "$config_path"
fi
fi
done

# Add or update traefik_domain
update_traefik_domain "$config_path"
}

# Function to update or add 'traefik_domain' to the end of the config file
add_or_update_traefik_domain() {
local config_path="$1"
local traefik_domain="$2"

# Check if the variable already exists in the config file
if grep -q "^traefik_domain=" "$config_path"; then
# If the variable exists, move it to the end by removing it first, then appending it
sed -i '/^traefik_domain=/d' "$config_path"
echo "traefik_domain=\"$traefik_domain\"" >> "$config_path"
else
# If the variable does not exist, append it to the end of the file
echo "traefik_domain=\"$traefik_domain\"" >> "$config_path"
fi
}

# Function to check the DNS configuration and update 'traefik_domain'
update_traefik_domain() {
local config_path="$1"

# Load DNS configuration
local dns_config_path="/pg/config/dns_provider.cfg"
if [[ -f "$dns_config_path" ]]; then
source "$dns_config_path"
traefik_domain="${domain_name:-nodomain}"
else
traefik_domain="nodomain"
fi

# Now call the function to add or update the 'traefik_domain' variable
add_or_update_traefik_domain "$config_path" "$traefik_domain"
}

parse_and_store_defaults "$app_name" "$app_type"
35 changes: 31 additions & 4 deletions mods/scripts/apps_parse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
parse_and_store_defaults() {
local app_name="$1"
local app_type="$2" # 'personal' for personal apps, 'official' for official apps
local port_default="$3" # The default port to expose

# Determine paths based on app type
if [[ "$app_type" == "personal" ]]; then
Expand All @@ -15,12 +16,14 @@ parse_and_store_defaults() {
fi

# Check if the config file exists, create it if not
[[ ! -f "$config_path" ]] && touch "$config_path"
if [[ ! -f "$config_path" ]]; then
touch "$config_path"
add_expose_variable "$config_path" "$port_default"
fi

# Check if the app file exists
if [[ ! -f "$app_path" ]]; then
# echo "Error: App file $app_path does not exist."
return 1
return 1 # App file does not exist, return with an error
fi

# Source the app's default_variables function
Expand Down Expand Up @@ -50,6 +53,29 @@ parse_and_store_defaults() {
update_traefik_domain "$config_path"
}

# Function to add the 'expose' variable based on default ports status
add_expose_variable() {
local config_path="$1"
local port_default="$2"

# Check the status of the ports from /pg/config/default_ports.cfg
local default_ports_cfg="/pg/config/default_ports.cfg"
if [[ -f "$default_ports_cfg" ]]; then
source "$default_ports_cfg"

# If ports=closed, use 127.0.0.1 for $port_default
if [[ "$ports" == "closed" ]]; then
echo "expose=\"127.0.0.1:$port_default\"" >> "$config_path"
else
# If ports=open, just write expose=
echo "expose=" >> "$config_path"
fi
else
# Default to open if the config file doesn't exist
echo "expose=" >> "$config_path"
fi
}

# Function to update or add 'traefik_domain' to the end of the config file
add_or_update_traefik_domain() {
local config_path="$1"
Expand Down Expand Up @@ -83,4 +109,5 @@ update_traefik_domain() {
add_or_update_traefik_domain "$config_path" "$traefik_domain"
}

parse_and_store_defaults "$app_name" "$app_type"
# Call the function with app name, type, and port default
parse_and_store_defaults "$app_name" "$app_type" "$port_default"
35 changes: 32 additions & 3 deletions mods/scripts/apps_starter_menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@ GREEN="\033[0;32m"
ORANGE="\033[0;33m"
BLUE="\033[0;34m"
WHITE="\033[1;37m"
CYAN="\033[0;36m"
BOLD="\033[1m"
NC="\033[0m" # No color

# Default values for personal apps configuration
DEFAULT_USER="None"
DEFAULT_REPO="None"

# Function to get the Default Port Status from /pg/config/default_ports.cfg
get_port_status() {
config_file="/pg/config/default_ports.cfg"
if [[ -f "$config_file" ]]; then
source "$config_file"
if [[ "$ports" == "open" ]]; then
port_status="Open"
elif [[ "$ports" == "closed" ]]; then
port_status="Closed"
else
port_status="Unknown"
fi
else
port_status="Unknown"
fi
}

# Function to count running Docker containers that match official app names from .app files in /pg/apps
count_docker_apps() {
local all_running_apps=$(docker ps --format '{{.Names}}' | grep -v 'cf_tunnel')
Expand Down Expand Up @@ -102,6 +120,9 @@ main_menu() {
# Load personal apps configuration
load_personal_apps_config

# Get Default Port Status
get_port_status

clear
echo -e "${BLUE}${BOLD}PlexGuide: Applications Interface${NC}"
echo -e "${WHITE}────────────────────────────────────────────────────${NC}"
Expand All @@ -126,15 +147,20 @@ main_menu() {
printf " R) Personal: Deploy Apps\n"
fi

echo "" # Space between options and input prompt
echo "" # Space for separation
else
echo "" # Space for separation
echo -e "${RED}Please select an App Store version by choosing option A.${NC}"
fi

# Default Ports section
echo -e "${CYAN}${BOLD}Default Ports${NC}"
printf " Y) Default Port Status: [%s]\n" "$port_status"

echo "" # Space between options and input prompt
echo -e "${WHITE}────────────────────────────────────────────────────${NC}"
# Display the prompt with colors and capture user input
echo -e "Type a Selection or [${GREEN}Z${NC}] to Exit:${NC} \c"
echo -e "Make a Choice or [${GREEN}Z${NC}] to Exit >${NC} \c"
read -r choice

case $choice in
Expand Down Expand Up @@ -176,6 +202,9 @@ main_menu() {
bash /pg/scripts/apps_stage.sh "personal"
fi
;;
Y|y)
bash /pg/scripts/default_ports.sh
;;
Z|z)
exit 0
;;
Expand All @@ -188,4 +217,4 @@ main_menu() {
}

# Call the main menu function
main_menu
main_menu
2 changes: 1 addition & 1 deletion mods/scripts/cf_tunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ show_menu() {

# Function to prompt the user with a choice
prompt_choice() {
read -p "Select an option: " choice
read -p "Make a Choice > " choice
case ${choice,,} in # Convert input to lowercase for v/V, c/C, d/D, s/S, z/Z handling
v)
clear
Expand Down
2 changes: 1 addition & 1 deletion mods/scripts/cloud_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ cloud_server_menu() {
echo "" # Space between options and input prompt

# Prompt for user input
read -p "Enter your choice: " choice
read -p "Make a Choice > " choice

# Process user input
case ${choice,,} in
Expand Down
Loading

0 comments on commit 4c390ff

Please sign in to comment.