Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/plexguide/PlexGuide.com into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
Admin9705 committed Sep 29, 2024
2 parents eae4ed1 + d4b6cc4 commit 4128b6a
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 235 deletions.
Binary file modified mods/scripts/.DS_Store
Binary file not shown.
54 changes: 52 additions & 2 deletions mods/scripts/apps/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ NC="\033[0m" # No color
app_name=$1
script_type=$2 # personal or official

# Configuration file paths
dns_provider_config="/pg/config/dns_provider.cfg"
app_config_official="/pg/config/${app_name}.cfg"
app_config_personal="/pg/personal_configs/${app_name}.cfg"

# Name of the Docker network to check or create
network_name="plexguide"

Expand All @@ -35,14 +40,56 @@ check_and_create_network() {
# Function to source configuration and functions for the app
appsourcing() {
if [[ "$script_type" == "personal" ]]; then
source "/pg/personal_configs/${app_name}.cfg"
source "$app_config_personal"
source "/pg/p_apps/${app_name}/${app_name}.functions" 2>/dev/null
else
source "/pg/config/${app_name}.cfg"
source "$app_config_official"
source "/pg/apps/${app_name}/${app_name}.functions" 2>/dev/null
fi
}

# Function to update traefik_domain in the app's config
update_traefik_domain() {
# Ensure dns_provider.cfg exists
if [[ ! -f "$dns_provider_config" ]]; then
mkdir -p "$(dirname "$dns_provider_config")"
touch "$dns_provider_config"
fi

# Read domain_name from dns_provider.cfg
if grep -q "^domain_name=" "$dns_provider_config"; then
domain_name=$(grep "^domain_name=" "$dns_provider_config" | cut -d'=' -f2)
else
domain_name=""
fi

# Set traefik_domain value based on domain_name
if [[ -z "$domain_name" ]]; then
# No domain set, use empty value
traefik_domain="traefik_domain=\"\""
else
# Domain exists, use it in the traefik_domain
traefik_domain="traefik_domain=\"$domain_name\""
fi

# Update the app's configuration file
if [[ "$script_type" == "personal" ]]; then
# Overwrite traefik_domain in the personal config file
if grep -q "^traefik_domain=" "$app_config_personal"; then
sed -i "s/^traefik_domain=.*/$traefik_domain/" "$app_config_personal"
else
echo "$traefik_domain" >> "$app_config_personal"
fi
else
# Overwrite traefik_domain in the official config file
if grep -q "^traefik_domain=" "$app_config_official"; then
sed -i "s/^traefik_domain=.*/$traefik_domain/" "$app_config_official"
else
echo "$traefik_domain" >> "$app_config_official"
fi
fi
}

# Function: Deploys / Redploys App
redeploy_app() {
# Check if lspci is installed; detect NVIDIA graphics cards
Expand All @@ -56,6 +103,9 @@ redeploy_app() {
check_and_create_network

echo "Deploying $app_name"

# Update traefik_domain based on the domain_name in dns_provider.cfg
update_traefik_domain

# Determine which support script to source
if [[ "$script_type" == "personal" ]]; then
Expand Down
10 changes: 6 additions & 4 deletions mods/scripts/apps/starter_menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ main_menu() {

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

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


# Call the main menu function
main_menu
2 changes: 1 addition & 1 deletion mods/scripts/cloud_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cloud_server_menu() {
echo "" # Space between options and input prompt

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

# Process user input
case ${choice,,} in
Expand Down
99 changes: 57 additions & 42 deletions mods/scripts/cf_tunnel.sh → mods/scripts/cloudflare/tunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# Configuration file path
CONFIG_FILE="/pg/config/cf_tunnel.cfg"

# ANSI color codes for green, red, and blue
GREEN="\033[0;32m"
# ANSI color codes for green, hot pink, and others
GREEN="\033[1;32m" # Bold Green
HOT_PINK="\033[1;35m" # Bold Hot Pink
RED="\033[0;31m"
BLUE="\033[0;34m"
NC="\033[0m" # No color
CYAN="\033[0;36m"
BOLD="\033[1m"

# Clear the screen when the script starts
clear
Expand Down Expand Up @@ -39,14 +42,11 @@ container_exists() {
# Function to display the main menu
show_menu() {
clear
echo "PG: CloudFlare Tunnel"

# Display container deployment status
echo -n "Container Deployed: "
echo -n -e "${CYAN}${BOLD}PG: CloudFlare Tunnel${NC} "
if container_running; then
echo -e "${GREEN}Yes${NC}"
echo -e "${GREEN}${BOLD}[Deployed]${NC}"
else
echo -e "${RED}No${NC}"
echo -e "${RED}${BOLD}[Not Deployed]${NC}"
fi

echo
Expand All @@ -64,43 +64,19 @@ show_menu() {

# Function to prompt the user with a choice
prompt_choice() {
read -p "Select an option: " choice
read -p "Select an Option > " choice
case ${choice,,} in # Convert input to lowercase for v/V, c/C, d/D, s/S, z/Z handling
v)
clear
view_token
;;
c)
clear
local change_code=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit code
while true; do
read -p "$(echo -e "To change the Cloudflare token, type [${RED}${change_code}${NC}] to proceed or [${GREEN}no${NC}] to cancel: ")" input_code
if [[ "$input_code" == "$change_code" ]]; then
change_token
break
elif [[ "${input_code,,}" == "no" ]]; then
echo "Operation cancelled."
break
else
echo -e "${RED}Invalid response.${NC} Please type [${RED}${change_code}${NC}] or [${GREEN}no${NC}]."
fi
done
change_token
;;
d)
clear
local deploy_code=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit code
while true; do
read -p "$(echo -e "Deploy CF Tunnel? Type [${RED}${deploy_code}${NC}] to proceed or [${GREEN}no${NC}] to cancel: ")" input_code
if [[ "$input_code" == "$deploy_code" ]]; then
deploy_container
break
elif [[ "${input_code,,}" == "no" ]]; then
echo "Operation cancelled."
break
else
echo -e "${RED}Invalid response.${NC} Please type [${RED}${deploy_code}${NC}] or [${GREEN}no${NC}]."
fi
done
deploy_container
;;
s)
clear
Expand Down Expand Up @@ -139,13 +115,52 @@ view_token() {

# Function to change the Cloudflare token
change_token() {
clear
read -p "Enter new Cloudflare token: " CLOUDFLARE_TOKEN
save_token_to_config
echo "Cloudflare token has been updated and saved to $CONFIG_FILE."
sleep 2
show_menu
prompt_choice
local proceed_pin cancel_pin
proceed_pin=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit proceed pin
cancel_pin=$(printf "%04d" $((RANDOM % 10000))) # Generate a 4-digit cancel pin

# Ask the user for the new token
echo -e "Enter new Cloudflare token:"
read -p "> " new_token # Get the new token from the user
echo # Echo a blank line for spacing

# Confirmation prompt with hot pink pin for proceed and green for cancel
while true; do
echo -e "To proceed, enter this PIN [${HOT_PINK}${proceed_pin}${NC}]"
echo -e "To cancel, enter this PIN [${GREEN}${cancel_pin}${NC}]"
read -p "Enter PIN > " input_code

if [[ "$input_code" == "$proceed_pin" ]]; then
# Save the token and confirm
CLOUDFLARE_TOKEN="$new_token"
save_token_to_config
echo -e "${GREEN}Cloudflare token has been updated and saved to $CONFIG_FILE.${NC}"

# Check if the container is running, notify the user and stop/remove it
if container_running; then
echo -e "${RED}Note:${NC} The CloudFlare Tunnel container is currently running."
echo "You must redeploy the container for the changes to take effect."

echo "Stopping and removing the running container..."
docker stop cf_tunnel
docker rm cf_tunnel
echo "Container stopped and removed."
fi

sleep 2
show_menu
prompt_choice
break
elif [[ "$input_code" == "$cancel_pin" ]]; then
echo -e "${GREEN}Operation cancelled.${NC}"
sleep 2
show_menu
prompt_choice
break
else
echo -e "${RED}Invalid response.${NC} Please enter [${HOT_PINK}${proceed_pin}${NC}] to proceed or [${GREEN}${cancel_pin}${NC}] to cancel."
fi
done
}

# Function to deploy or redeploy the container
Expand Down
8 changes: 4 additions & 4 deletions mods/scripts/domain_menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ get_port_status() {
display_menu() {
clear
get_port_status # Fetch the port status
echo -e "${CYAN}PG Domain Configuration Interface${NC}"
echo -e "${CYAN}${BOLD}PG Domain Configuration Interface${NC}"
echo
echo -e "[${YELLOW}${BOLD}A${NC}] CloudFlare Tunnel"
echo -e "[${CYAN}${BOLD}B${NC}] CloudFlare Traefik"
Expand All @@ -45,14 +45,14 @@ display_menu() {
# Main loop
while true; do
display_menu
read -p "Make a Choice > " choice
read -p "Select an Option > " choice

case $choice in
[Aa])
bash /pg/scripts/cf_tunnel.sh
bash /pg/scripts/cloudflare/tunnel.sh
;;
[Bb])
bash /pg/scripts/traefik/traefik_menu.sh
bash /pg/scripts/traefik/menu.sh
;;
[Pp])
bash /pg/scripts/default_ports.sh
Expand Down
2 changes: 1 addition & 1 deletion mods/scripts/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ main_menu() {
echo "" # Space between options and input prompt

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

# Process user input
case ${choice,,} in
Expand Down
8 changes: 6 additions & 2 deletions mods/scripts/options.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/bash

# ANSI color codes
CYAN="\033[0;36m"
RED="\033[0;31m"
ORANGE="\033[0;33m"
WHITE="\033[1;37m"
BOLD="\033[1m"
NC="\033[0m" # No color
BLUE="\033[0;34m"
NC="\033[0m" # No color

# Clear the screen at the start
clear
Expand All @@ -30,7 +34,7 @@ exit_script() {
main_menu() {
while true; do
clear
echo -e "${BLUE}PlexGuide Options Interface${NC}"
echo -e "${CYAN}${BOLD}PG Options Interface${NC}"
echo "" # Blank line for separation
# Display the main menu options
echo "G) Graphics Cards"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,23 @@ services:
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge=true"
- "--certificatesresolvers.mytlschallenge.acme.email=${letsencrypt_email:-example@example.com}"
- "--certificatesresolvers.mytlschallenge.acme.email=${letsencrypt_email}"
- "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge.provider=cloudflare"
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge.resolvers=1.1.1.1:53,8.8.8.8:53"
- "--certificatesresolvers.mytlschallenge.acme.dnschallenge.delaybeforecheck=60"
EOF

# Add Cloudflare-specific environment variable
cat <<EOF >> $DOCKER_COMPOSE_FILE
environment:
- CLOUDFLARE_DNS_API_TOKEN=$api_key
EOF

# Finalize Docker Compose file
cat <<EOF >> $DOCKER_COMPOSE_FILE
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /pg/traefik/letsencrypt:/letsencrypt
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(\`traefik.${domain_name}\`)"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.routers.traefik.tls.certresolver=mytlschallenge"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_AUTH}"
restart: unless-stopped
networks:
host:
external: true
EOF

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

0 comments on commit 4128b6a

Please sign in to comment.