Skip to content

Commit d4b6cc4

Browse files
authored
Merge pull request #966 from plexguide/tweaks2
Tweaks2
2 parents 3c0f13b + c6d6b81 commit d4b6cc4

File tree

13 files changed

+429
-235
lines changed

13 files changed

+429
-235
lines changed

mods/scripts/.DS_Store

-2 KB
Binary file not shown.

mods/scripts/apps/deploy.sh

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ NC="\033[0m" # No color
1111
app_name=$1
1212
script_type=$2 # personal or official
1313

14+
# Configuration file paths
15+
dns_provider_config="/pg/config/dns_provider.cfg"
16+
app_config_official="/pg/config/${app_name}.cfg"
17+
app_config_personal="/pg/personal_configs/${app_name}.cfg"
18+
1419
# Name of the Docker network to check or create
1520
network_name="plexguide"
1621

@@ -35,14 +40,56 @@ check_and_create_network() {
3540
# Function to source configuration and functions for the app
3641
appsourcing() {
3742
if [[ "$script_type" == "personal" ]]; then
38-
source "/pg/personal_configs/${app_name}.cfg"
43+
source "$app_config_personal"
3944
source "/pg/p_apps/${app_name}/${app_name}.functions" 2>/dev/null
4045
else
41-
source "/pg/config/${app_name}.cfg"
46+
source "$app_config_official"
4247
source "/pg/apps/${app_name}/${app_name}.functions" 2>/dev/null
4348
fi
4449
}
4550

51+
# Function to update traefik_domain in the app's config
52+
update_traefik_domain() {
53+
# Ensure dns_provider.cfg exists
54+
if [[ ! -f "$dns_provider_config" ]]; then
55+
mkdir -p "$(dirname "$dns_provider_config")"
56+
touch "$dns_provider_config"
57+
fi
58+
59+
# Read domain_name from dns_provider.cfg
60+
if grep -q "^domain_name=" "$dns_provider_config"; then
61+
domain_name=$(grep "^domain_name=" "$dns_provider_config" | cut -d'=' -f2)
62+
else
63+
domain_name=""
64+
fi
65+
66+
# Set traefik_domain value based on domain_name
67+
if [[ -z "$domain_name" ]]; then
68+
# No domain set, use empty value
69+
traefik_domain="traefik_domain=\"\""
70+
else
71+
# Domain exists, use it in the traefik_domain
72+
traefik_domain="traefik_domain=\"$domain_name\""
73+
fi
74+
75+
# Update the app's configuration file
76+
if [[ "$script_type" == "personal" ]]; then
77+
# Overwrite traefik_domain in the personal config file
78+
if grep -q "^traefik_domain=" "$app_config_personal"; then
79+
sed -i "s/^traefik_domain=.*/$traefik_domain/" "$app_config_personal"
80+
else
81+
echo "$traefik_domain" >> "$app_config_personal"
82+
fi
83+
else
84+
# Overwrite traefik_domain in the official config file
85+
if grep -q "^traefik_domain=" "$app_config_official"; then
86+
sed -i "s/^traefik_domain=.*/$traefik_domain/" "$app_config_official"
87+
else
88+
echo "$traefik_domain" >> "$app_config_official"
89+
fi
90+
fi
91+
}
92+
4693
# Function: Deploys / Redploys App
4794
redeploy_app() {
4895
# Check if lspci is installed; detect NVIDIA graphics cards
@@ -56,6 +103,9 @@ redeploy_app() {
56103
check_and_create_network
57104

58105
echo "Deploying $app_name"
106+
107+
# Update traefik_domain based on the domain_name in dns_provider.cfg
108+
update_traefik_domain
59109

60110
# Determine which support script to source
61111
if [[ "$script_type" == "personal" ]]; then

mods/scripts/apps/starter_menu.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ main_menu() {
147147

148148
# Conditionally hide options Q and R if the repo is set to "None"
149149
if [[ "$repo" != "None" ]]; then
150-
printf " Q) Personal: Manage [%d]\n" "$P_COUNT"
150+
# Only display option Q) if there are personal apps deployed (P_COUNT > 0)
151+
if [[ "$P_COUNT" -gt 0 ]]; then
152+
printf " Q) Personal: Manage [%d]\n" "$P_COUNT"
153+
fi
151154
printf " R) Personal: Deploy Apps\n"
152155
fi
153156

@@ -191,8 +194,8 @@ main_menu() {
191194
bash /pg/scripts/apps/personal_select.sh
192195
;;
193196
Q|q)
194-
if [[ "$repo" == "None" ]]; then
195-
echo -e "${RED}Option Q is not available. Please use P to set a User and Repo first.${NC}"
197+
if [[ "$repo" == "None" || "$P_COUNT" -eq 0 ]]; then
198+
echo -e "${RED}Option Q is not available. Please deploy a personal app first.${NC}"
196199
read -p "Press Enter to continue..."
197200
else
198201
bash /pg/scripts/apps/running.sh "personal"
@@ -220,6 +223,5 @@ main_menu() {
220223
done
221224
}
222225

223-
224226
# Call the main menu function
225227
main_menu

mods/scripts/cloud_server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cloud_server_menu() {
2525
echo "" # Space between options and input prompt
2626

2727
# Prompt for user input
28-
read -p "Enter your choice: " choice
28+
read -p "Select an Option > " choice
2929

3030
# Process user input
3131
case ${choice,,} in

mods/scripts/cf_tunnel.sh renamed to mods/scripts/cloudflare/tunnel.sh

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# Configuration file path
44
CONFIG_FILE="/pg/config/cf_tunnel.cfg"
55

6-
# ANSI color codes for green, red, and blue
7-
GREEN="\033[0;32m"
6+
# ANSI color codes for green, hot pink, and others
7+
GREEN="\033[1;32m" # Bold Green
8+
HOT_PINK="\033[1;35m" # Bold Hot Pink
89
RED="\033[0;31m"
910
BLUE="\033[0;34m"
1011
NC="\033[0m" # No color
12+
CYAN="\033[0;36m"
13+
BOLD="\033[1m"
1114

1215
# Clear the screen when the script starts
1316
clear
@@ -39,14 +42,11 @@ container_exists() {
3942
# Function to display the main menu
4043
show_menu() {
4144
clear
42-
echo "PG: CloudFlare Tunnel"
43-
44-
# Display container deployment status
45-
echo -n "Container Deployed: "
45+
echo -n -e "${CYAN}${BOLD}PG: CloudFlare Tunnel${NC} "
4646
if container_running; then
47-
echo -e "${GREEN}Yes${NC}"
47+
echo -e "${GREEN}${BOLD}[Deployed]${NC}"
4848
else
49-
echo -e "${RED}No${NC}"
49+
echo -e "${RED}${BOLD}[Not Deployed]${NC}"
5050
fi
5151

5252
echo
@@ -64,43 +64,19 @@ show_menu() {
6464

6565
# Function to prompt the user with a choice
6666
prompt_choice() {
67-
read -p "Select an option: " choice
67+
read -p "Select an Option > " choice
6868
case ${choice,,} in # Convert input to lowercase for v/V, c/C, d/D, s/S, z/Z handling
6969
v)
7070
clear
7171
view_token
7272
;;
7373
c)
7474
clear
75-
local change_code=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit code
76-
while true; do
77-
read -p "$(echo -e "To change the Cloudflare token, type [${RED}${change_code}${NC}] to proceed or [${GREEN}no${NC}] to cancel: ")" input_code
78-
if [[ "$input_code" == "$change_code" ]]; then
79-
change_token
80-
break
81-
elif [[ "${input_code,,}" == "no" ]]; then
82-
echo "Operation cancelled."
83-
break
84-
else
85-
echo -e "${RED}Invalid response.${NC} Please type [${RED}${change_code}${NC}] or [${GREEN}no${NC}]."
86-
fi
87-
done
75+
change_token
8876
;;
8977
d)
9078
clear
91-
local deploy_code=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit code
92-
while true; do
93-
read -p "$(echo -e "Deploy CF Tunnel? Type [${RED}${deploy_code}${NC}] to proceed or [${GREEN}no${NC}] to cancel: ")" input_code
94-
if [[ "$input_code" == "$deploy_code" ]]; then
95-
deploy_container
96-
break
97-
elif [[ "${input_code,,}" == "no" ]]; then
98-
echo "Operation cancelled."
99-
break
100-
else
101-
echo -e "${RED}Invalid response.${NC} Please type [${RED}${deploy_code}${NC}] or [${GREEN}no${NC}]."
102-
fi
103-
done
79+
deploy_container
10480
;;
10581
s)
10682
clear
@@ -139,13 +115,52 @@ view_token() {
139115

140116
# Function to change the Cloudflare token
141117
change_token() {
142-
clear
143-
read -p "Enter new Cloudflare token: " CLOUDFLARE_TOKEN
144-
save_token_to_config
145-
echo "Cloudflare token has been updated and saved to $CONFIG_FILE."
146-
sleep 2
147-
show_menu
148-
prompt_choice
118+
local proceed_pin cancel_pin
119+
proceed_pin=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit proceed pin
120+
cancel_pin=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit cancel pin
121+
122+
# Ask the user for the new token
123+
echo -e "Enter new Cloudflare token:"
124+
read -p "> " new_token # Get the new token from the user
125+
echo # Echo a blank line for spacing
126+
127+
# Confirmation prompt with hot pink pin for proceed and green for cancel
128+
while true; do
129+
echo -e "To proceed, enter this PIN [${HOT_PINK}${proceed_pin}${NC}]"
130+
echo -e "To cancel, enter this PIN [${GREEN}${cancel_pin}${NC}]"
131+
read -p "Enter PIN > " input_code
132+
133+
if [[ "$input_code" == "$proceed_pin" ]]; then
134+
# Save the token and confirm
135+
CLOUDFLARE_TOKEN="$new_token"
136+
save_token_to_config
137+
echo -e "${GREEN}Cloudflare token has been updated and saved to $CONFIG_FILE.${NC}"
138+
139+
# Check if the container is running, notify the user and stop/remove it
140+
if container_running; then
141+
echo -e "${RED}Note:${NC} The CloudFlare Tunnel container is currently running."
142+
echo "You must redeploy the container for the changes to take effect."
143+
144+
echo "Stopping and removing the running container..."
145+
docker stop cf_tunnel
146+
docker rm cf_tunnel
147+
echo "Container stopped and removed."
148+
fi
149+
150+
sleep 2
151+
show_menu
152+
prompt_choice
153+
break
154+
elif [[ "$input_code" == "$cancel_pin" ]]; then
155+
echo -e "${GREEN}Operation cancelled.${NC}"
156+
sleep 2
157+
show_menu
158+
prompt_choice
159+
break
160+
else
161+
echo -e "${RED}Invalid response.${NC} Please enter [${HOT_PINK}${proceed_pin}${NC}] to proceed or [${GREEN}${cancel_pin}${NC}] to cancel."
162+
fi
163+
done
149164
}
150165

151166
# Function to deploy or redeploy the container

mods/scripts/domain_menu.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ get_port_status() {
3333
display_menu() {
3434
clear
3535
get_port_status # Fetch the port status
36-
echo -e "${CYAN}PG Domain Configuration Interface${NC}"
36+
echo -e "${CYAN}${BOLD}PG Domain Configuration Interface${NC}"
3737
echo
3838
echo -e "[${YELLOW}${BOLD}A${NC}] CloudFlare Tunnel"
3939
echo -e "[${CYAN}${BOLD}B${NC}] CloudFlare Traefik"
@@ -45,14 +45,14 @@ display_menu() {
4545
# Main loop
4646
while true; do
4747
display_menu
48-
read -p "Make a Choice > " choice
48+
read -p "Select an Option > " choice
4949

5050
case $choice in
5151
[Aa])
52-
bash /pg/scripts/cf_tunnel.sh
52+
bash /pg/scripts/cloudflare/tunnel.sh
5353
;;
5454
[Bb])
55-
bash /pg/scripts/traefik/traefik_menu.sh
55+
bash /pg/scripts/traefik/menu.sh
5656
;;
5757
[Pp])
5858
bash /pg/scripts/default_ports.sh

mods/scripts/menu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ main_menu() {
165165
echo "" # Space between options and input prompt
166166

167167
# Prompt for user input
168-
read -p "Choose and Option > " choice
168+
read -p "Select an Option > " choice
169169

170170
# Process user input
171171
case ${choice,,} in

mods/scripts/options.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/bin/bash
22

33
# ANSI color codes
4+
CYAN="\033[0;36m"
45
RED="\033[0;31m"
6+
ORANGE="\033[0;33m"
7+
WHITE="\033[1;37m"
8+
BOLD="\033[1m"
9+
NC="\033[0m" # No color
510
BLUE="\033[0;34m"
6-
NC="\033[0m" # No color
711

812
# Clear the screen at the start
913
clear
@@ -30,7 +34,7 @@ exit_script() {
3034
main_menu() {
3135
while true; do
3236
clear
33-
echo -e "${BLUE}PlexGuide Options Interface${NC}"
37+
echo -e "${CYAN}${BOLD}PG Options Interface${NC}"
3438
echo "" # Blank line for separation
3539
# Display the main menu options
3640
echo "G) Graphics Cards"

mods/scripts/traefik/traefik_deploy.sh renamed to mods/scripts/traefik/deploy.sh

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,23 @@ services:
6262
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
6363
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
6464
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge=true"
65-
- "--certificatesresolvers.mytlschallenge.acme.email=${letsencrypt_email:-example@example.com}"
65+
- "--certificatesresolvers.mytlschallenge.acme.email=${letsencrypt_email}"
6666
- "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
6767
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge.provider=cloudflare"
6868
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge.resolvers=1.1.1.1:53,8.8.8.8:53"
6969
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge.delaybeforecheck=60"
70-
EOF
71-
72-
# Add Cloudflare-specific environment variable
73-
cat <<EOF >> $DOCKER_COMPOSE_FILE
7470
environment:
7571
- CLOUDFLARE_DNS_API_TOKEN=$api_key
76-
EOF
77-
78-
# Finalize Docker Compose file
79-
cat <<EOF >> $DOCKER_COMPOSE_FILE
8072
volumes:
8173
- /var/run/docker.sock:/var/run/docker.sock
8274
- /pg/traefik/letsencrypt:/letsencrypt
8375
labels:
8476
- "traefik.enable=true"
85-
- "traefik.http.routers.traefik.rule=Host(\`traefik.${domain_name}\`)"
8677
- "traefik.http.routers.traefik.entrypoints=websecure"
8778
- "traefik.http.routers.traefik.tls.certresolver=mytlschallenge"
8879
- "traefik.http.routers.traefik.service=api@internal"
8980
- "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_AUTH}"
9081
restart: unless-stopped
91-
92-
networks:
93-
host:
94-
external: true
9582
EOF
9683

9784
echo -e "${GREEN}Docker Compose file for Traefik has been created at $DOCKER_COMPOSE_FILE.${NC}"

0 commit comments

Comments
 (0)