From 1353035ffb560f669a83bc106eeb7d3e327793b1 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 3 Sep 2024 14:31:07 -0400 Subject: [PATCH 1/5] update --- mods/scripts/apps_interface.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mods/scripts/apps_interface.sh b/mods/scripts/apps_interface.sh index f37e2e8b91..72a54206fc 100644 --- a/mods/scripts/apps_interface.sh +++ b/mods/scripts/apps_interface.sh @@ -17,10 +17,21 @@ 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 + if [[ "$config_type" == "personal" ]]; then + config_file="/pg/personal_configs/${app_name}.cfg" + else + config_file="/pg/config/${app_name}.cfg" + fi + + if [[ -f "$config_file" ]]; then + source "$config_file" + fi + local container_status=$(docker ps --filter "name=^/${app_name}$" --format "{{.Names}}") if [[ "$container_status" == "$app_name" ]]; then - echo -e "${GREEN}[Deployed]${NC} $app_name" + echo -e "${GREEN}[Deployed]${NC} $app_name - Port: $port_number" else echo -e "${RED}[Not Deployed]${NC} $app_name" fi From 7934e5a45b959af57131859a5b983b31b93f6982 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 3 Sep 2024 21:23:47 -0400 Subject: [PATCH 2/5] add cloud stuff --- mods/scripts/cloud_hetzner.sh | 218 ++++++++++++++++++++++++++++++++++ mods/scripts/cloud_server.sh | 43 +++++++ mods/scripts/menu.sh | 43 ++++--- 3 files changed, 286 insertions(+), 18 deletions(-) create mode 100644 mods/scripts/cloud_hetzner.sh create mode 100644 mods/scripts/cloud_server.sh diff --git a/mods/scripts/cloud_hetzner.sh b/mods/scripts/cloud_hetzner.sh new file mode 100644 index 0000000000..304c176d3d --- /dev/null +++ b/mods/scripts/cloud_hetzner.sh @@ -0,0 +1,218 @@ +#!/bin/bash + +# Title: PGBlitz (Simplified) +# Description: Script to manage Hetzner Cloud servers using the new hcloud CLI + +# Check if hcloud CLI is installed and install if missing +install_hcloud() { + if ! command -v hcloud &> /dev/null; then + echo "Installing Hetzner CLI..." + curl -o /tmp/hcloud.tar.gz -L https://github.com/hetznercloud/cli/releases/latest/download/hcloud-linux-amd64.tar.gz + tar -xzf /tmp/hcloud.tar.gz -C /tmp + mv /tmp/hcloud /usr/local/bin/hcloud + chmod +x /usr/local/bin/hcloud + rm -rf /tmp/hcloud.tar.gz + fi +} + +# Validate hcloud API token +validate_hcloud_token() { + if ! hcloud server list &> /dev/null; then + echo -e "\nWARNING! Please configure Hetzner API token first!" + echo -e "\nFollow these steps:\n1. Activate a Hetzner Cloud Account\n2. Create a Project\n3. Go to Access (left-hand side)\n4. Click API Tokens\n5. Create a Token and Save It\n" + echo -e "Type 'exit' to cancel and return to the main menu.\n" + read -p 'Paste your API token here (or type exit): ' api_token /dev/null; then + hcloud context delete plexguide + echo -e "\nInvalid token provided. Please try again.\n" + exit 1 + fi + fi +} + +# Ensure necessary directories exist +setup_directories() { + mkdir -p /pg/hcloud +} + +# Main menu +main_menu() { + clear + echo -e "\e[1;36mPG: Hetzner Cloud Manager\e[0m\n" + echo -e "[1] Deploy a New Server" + echo -e "[2] Destroy a Server" + echo -e "[A] List Servers" + echo -e "[B] Show Initial Passwords" + echo -e "[Z] Exit\n" + read -p 'Select an option: ' option "/pg/hcloud/$server_name.info" + echo -e "\nServer information:" + cat "/pg/hcloud/$server_name.info" + read -p 'Press [ENTER] to continue...' 1 {print $2}' + echo "" + read -p 'Press [ENTER] to continue...' 1 {print $2}' + echo "" + read -p 'Enter server name to destroy or [Z] to exit: ' server_name Date: Tue, 3 Sep 2024 21:30:10 -0400 Subject: [PATCH 3/5] update --- mods/scripts/cloud_hetzner.sh | 67 ++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/mods/scripts/cloud_hetzner.sh b/mods/scripts/cloud_hetzner.sh index 304c176d3d..378e660a8d 100644 --- a/mods/scripts/cloud_hetzner.sh +++ b/mods/scripts/cloud_hetzner.sh @@ -1,8 +1,11 @@ #!/bin/bash -# Title: PGBlitz (Simplified) +# Title: OG PlexGuide Script # Description: Script to manage Hetzner Cloud servers using the new hcloud CLI +# Configuration file path for storing the token +TOKEN_FILE="/pg/hcloud/.token" + # Check if hcloud CLI is installed and install if missing install_hcloud() { if ! command -v hcloud &> /dev/null; then @@ -17,27 +20,47 @@ install_hcloud() { # Validate hcloud API token validate_hcloud_token() { - if ! hcloud server list &> /dev/null; then - echo -e "\nWARNING! Please configure Hetzner API token first!" - echo -e "\nFollow these steps:\n1. Activate a Hetzner Cloud Account\n2. Create a Project\n3. Go to Access (left-hand side)\n4. Click API Tokens\n5. Create a Token and Save It\n" - echo -e "Type 'exit' to cancel and return to the main menu.\n" - read -p 'Paste your API token here (or type exit): ' api_token /dev/null; then + echo -e "\nWARNING! The existing token is invalid." + change_token fi + else + change_token + fi +} - # Create a new context with the provided API token - hcloud context create plexguide --token "$api_token" +# Function to change or set the hcloud API token +change_token() { + echo -e "\nPlease provide a valid Hetzner API token." + echo -e "\nFollow these steps:\n1. Activate a Hetzner Cloud Account\n2. Create a Project\n3. Go to Access (left-hand side)\n4. Click API Tokens\n5. Create a Token and Save It\n" + echo -e "Type 'exit' to cancel and return to the main menu.\n" + read -p 'Paste your API token here (or type exit): ' api_token /dev/null; then - hcloud context delete plexguide - echo -e "\nInvalid token provided. Please try again.\n" - exit 1 - fi + # Check if the user typed exit + if [[ "${api_token,,}" == "exit" ]]; then + echo -e "\nToken generation canceled. Returning to the main menu...\n" + main_menu + fi + + # Validate the token format (64 alphanumeric characters) + if [[ ! "$api_token" =~ ^[a-zA-Z0-9]{64}$ ]]; then + echo -e "\nInvalid token format. Please try again." + change_token + fi + + # Save the token to the TOKEN_FILE + echo "$api_token" > "$TOKEN_FILE" + export HCLOUD_TOKEN="$api_token" + + # Verify the token + if ! hcloud server list &> /dev/null; then + echo -e "\nInvalid token provided. Please try again.\n" + rm -f "$TOKEN_FILE" + change_token + else + echo -e "\nToken successfully configured." fi } @@ -54,6 +77,7 @@ main_menu() { echo -e "[2] Destroy a Server" echo -e "[A] List Servers" echo -e "[B] Show Initial Passwords" + echo -e "[T] Change API Token" echo -e "[Z] Exit\n" read -p 'Select an option: ' option Date: Tue, 3 Sep 2024 21:32:32 -0400 Subject: [PATCH 4/5] update --- mods/scripts/cloud_hetzner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/scripts/cloud_hetzner.sh b/mods/scripts/cloud_hetzner.sh index 378e660a8d..75bf511341 100644 --- a/mods/scripts/cloud_hetzner.sh +++ b/mods/scripts/cloud_hetzner.sh @@ -34,7 +34,7 @@ validate_hcloud_token() { # Function to change or set the hcloud API token change_token() { echo -e "\nPlease provide a valid Hetzner API token." - echo -e "\nFollow these steps:\n1. Activate a Hetzner Cloud Account\n2. Create a Project\n3. Go to Access (left-hand side)\n4. Click API Tokens\n5. Create a Token and Save It\n" + echo -e "\nFollow these steps:\n1. Activate a Hetzner Cloud Account\n2. Create a Project\n3. Go to Security (left-hand side)\n4. Select and Click API Tokens\n5. Create a Token and Save It\n" echo -e "Type 'exit' to cancel and return to the main menu.\n" read -p 'Paste your API token here (or type exit): ' api_token Date: Tue, 3 Sep 2024 21:38:02 -0400 Subject: [PATCH 5/5] update --- mods/scripts/cloud_hetzner.sh | 75 ++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/mods/scripts/cloud_hetzner.sh b/mods/scripts/cloud_hetzner.sh index 75bf511341..47cb74f937 100644 --- a/mods/scripts/cloud_hetzner.sh +++ b/mods/scripts/cloud_hetzner.sh @@ -1,12 +1,20 @@ #!/bin/bash -# Title: OG PlexGuide Script +# Title: PG Cloud Hetzner Manager Script # Description: Script to manage Hetzner Cloud servers using the new hcloud CLI # Configuration file path for storing the token TOKEN_FILE="/pg/hcloud/.token" -# Check if hcloud CLI is installed and install if missing +# 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 + +# Function to install hcloud CLI if missing install_hcloud() { if ! command -v hcloud &> /dev/null; then echo "Installing Hetzner CLI..." @@ -18,12 +26,12 @@ install_hcloud() { fi } -# Validate hcloud API token +# Function to validate the Hetzner API token validate_hcloud_token() { if [[ -f "$TOKEN_FILE" ]]; then export HCLOUD_TOKEN=$(cat "$TOKEN_FILE") if ! hcloud server list &> /dev/null; then - echo -e "\nWARNING! The existing token is invalid." + echo -e "\n${RED}WARNING! The existing token is invalid.${NC}" change_token fi else @@ -34,19 +42,24 @@ validate_hcloud_token() { # Function to change or set the hcloud API token change_token() { echo -e "\nPlease provide a valid Hetzner API token." - echo -e "\nFollow these steps:\n1. Activate a Hetzner Cloud Account\n2. Create a Project\n3. Go to Security (left-hand side)\n4. Select and Click API Tokens\n5. Create a Token and Save It\n" + echo -e "\nFollow these steps:" + echo -e "1. Activate a Hetzner Cloud Account" + echo -e "2. Create a Project" + echo -e "3. Go to Security (left-hand side)" + echo -e "4. Select and Click API Tokens" + echo -e "5. Create a Token and Save It\n" echo -e "Type 'exit' to cancel and return to the main menu.\n" read -p 'Paste your API token here (or type exit): ' api_token /dev/null; then - echo -e "\nInvalid token provided. Please try again.\n" + echo -e "\n${RED}Invalid token provided. Please try again.${NC}\n" rm -f "$TOKEN_FILE" change_token else - echo -e "\nToken successfully configured." + echo -e "\n${WHITE}Token successfully configured.${NC}" fi } -# Ensure necessary directories exist +# Function to ensure necessary directories exist setup_directories() { mkdir -p /pg/hcloud } -# Main menu +# Main menu function main_menu() { clear - echo -e "\e[1;36mPG: Hetzner Cloud Manager\e[0m\n" + echo -e "${CYAN}${BOLD}PG: Hetzner Cloud Manager${NC}\n" echo -e "[1] Deploy a New Server" echo -e "[2] Destroy a Server" echo -e "[A] List Servers" @@ -81,24 +94,24 @@ main_menu() { echo -e "[Z] Exit\n" read -p 'Select an option: ' option "/pg/hcloud/$server_name.info" echo -e "\nServer information:" @@ -195,20 +208,20 @@ deploy_server() { main_menu } -# List servers +# Function to list servers list_servers() { clear - echo -e "\e[1;36mHetzner Cloud Servers:\e[0m\n" + echo -e "${CYAN}${BOLD}Hetzner Cloud Servers:${NC}\n" hcloud server list | awk 'NR>1 {print $2}' echo "" read -p 'Press [ENTER] to continue...' 1 {print $2}' echo "" read -p 'Enter server name to destroy or [Z] to exit: ' server_name