From ced170609efb6d8f04fe62f775865897ea5a8161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAdmin9705=E2=80=9D?= <9705@duck.com> Date: Mon, 16 Sep 2024 09:57:09 -0400 Subject: [PATCH 1/7] update --- mods/scripts/apps/deploy.sh | 31 +++++++++++++++++++++++++++++-- mods/scripts/apps/support.sh | 35 ----------------------------------- 2 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 mods/scripts/apps/support.sh diff --git a/mods/scripts/apps/deploy.sh b/mods/scripts/apps/deploy.sh index 84b15dbec9..a99bbe4ffa 100644 --- a/mods/scripts/apps/deploy.sh +++ b/mods/scripts/apps/deploy.sh @@ -32,6 +32,33 @@ check_and_create_network() { fi } +# Function to source configuration and functions for the app +appsourcing() { + if [[ "$script_type" == "personal" ]]; then + source "/pg/personal_configs/${app_name}.cfg" + source "/pg/p_apps/${app_name}/${app_name}.functions" 2>/dev/null + else + source "/pg/config/${app_name}.cfg" + source "/pg/apps/${app_name}/${app_name}.functions" 2>/dev/null + fi +} + +# Function to source configuration from the config file +#configsource() { +# if [[ "$config_type" == "personal" ]]; then +# config_path="/pg/personal_configs/${app_name}.cfg" +# else +# config_path="/pg/config/${app_name}.cfg" +# fi +# +# if [ -f "$config_path" ]; then +# source "$config_path" +# else +# echo "Config file for ${app_name} not found at ${config_path}." +# exit 1 +# fi +#} + # Function: Deploys / Redploys App redeploy_app() { # Check if lspci is installed; detect NVIDIA graphics cards @@ -48,10 +75,10 @@ redeploy_app() { # Determine which support script to source if [[ "$script_type" == "personal" ]]; then - source /pg/scripts/apps/support.sh "$app_name" "$script_type" && appsourcing + appsourcing source "/pg/p_apps/$app_name.app" elif [[ "$script_type" == "official" ]]; then - source /pg/scripts/apps/support.sh "$app_name" "$script_type" && appsourcing + appsourcing source "/pg/apps/$app_name.app" else echo -e "${RED}Invalid script type specified. Use 'personal' or 'official'.${NC}" diff --git a/mods/scripts/apps/support.sh b/mods/scripts/apps/support.sh deleted file mode 100644 index c5cd3f57b2..0000000000 --- a/mods/scripts/apps/support.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Combined script for official and personal app support - -# Arguments -app_name=$1 -config_type=$2 # 'personal' for personal apps, 'official' for official apps - -# Function to source configuration and functions for the app -appsourcing() { - if [[ "$config_type" == "personal" ]]; then - source "/pg/personal_configs/${app_name}.cfg" - source "/pg/p_apps/${app_name}/${app_name}.functions" 2>/dev/null - else - source "/pg/config/${app_name}.cfg" - source "/pg/apps/${app_name}/${app_name}.functions" 2>/dev/null - fi -} - -# Function to source configuration from the config file -configsource() { - local app_name="$1" - if [[ "$config_type" == "personal" ]]; then - config_path="/pg/personal_configs/${app_name}.cfg" - else - config_path="/pg/config/${app_name}.cfg" - fi - - if [ -f "$config_path" ]; then - source "$config_path" - else - echo "Config file for ${app_name} not found at ${config_path}." - exit 1 - fi -} \ No newline at end of file From 76fad4cb947ea6cf27f60f58415bb6088433deb6 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 17 Sep 2024 04:11:49 -0400 Subject: [PATCH 2/7] update --- mods/scripts/menu.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mods/scripts/menu.sh b/mods/scripts/menu.sh index 392e3b2131..9f8a00d85f 100644 --- a/mods/scripts/menu.sh +++ b/mods/scripts/menu.sh @@ -1,10 +1,21 @@ #!/bin/bash +# ANSI color codes +RED="\033[0;31m" +NC="\033[0m" # No color + +# Security check: Only allow user with UID 1000 and GID 1000 to run this script +if [[ $(id -u) -ne 1000 ]] || [[ $(id -g) -ne 1000 ]]; then + echo -e "${RED}WARNING: This script can only be run by the user with UID 1000 and GID 1000.${NC}" + read -p "Press [ENTER] to acknowledge" + menu_exit + exit 1 +fi + # Configuration file path CONFIG_FILE="/pg/config/config.cfg" -# ANSI color codes -RED="\033[0;31m" +# Additional ANSI color codes ORANGE="\033[0;33m" YELLOW="\033[1;33m" GREEN="\033[0;32m" @@ -12,7 +23,6 @@ CYAN="\033[0;36m" BLUE="\033[0;34m" PURPLE="\033[0;35m" BOLD="\033[1m" -NC="\033[0m" # No color # Clear the screen at the start clear @@ -130,4 +140,4 @@ main_menu() { # Run the script load_config -main_menu +main_menu \ No newline at end of file From 5bfa3f84bf30fb42e42c16e91e64a0397cb1b4ee Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 17 Sep 2024 04:48:24 -0400 Subject: [PATCH 3/7] update --- mods/scripts/menu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/scripts/menu.sh b/mods/scripts/menu.sh index 9f8a00d85f..6d05ff2b10 100644 --- a/mods/scripts/menu.sh +++ b/mods/scripts/menu.sh @@ -8,7 +8,7 @@ NC="\033[0m" # No color if [[ $(id -u) -ne 1000 ]] || [[ $(id -g) -ne 1000 ]]; then echo -e "${RED}WARNING: This script can only be run by the user with UID 1000 and GID 1000.${NC}" read -p "Press [ENTER] to acknowledge" - menu_exit + bash /pg/installer/menu_exit.sh exit 1 fi From 6e13b27b54ac28230f126394b6b9553060d87fbc Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 17 Sep 2024 04:59:20 -0400 Subject: [PATCH 4/7] update --- mods/scripts/menu.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/scripts/menu.sh b/mods/scripts/menu.sh index 6d05ff2b10..540c5dc080 100644 --- a/mods/scripts/menu.sh +++ b/mods/scripts/menu.sh @@ -4,9 +4,9 @@ RED="\033[0;31m" NC="\033[0m" # No color -# Security check: Only allow user with UID 1000 and GID 1000 to run this script -if [[ $(id -u) -ne 1000 ]] || [[ $(id -g) -ne 1000 ]]; then - echo -e "${RED}WARNING: This script can only be run by the user with UID 1000 and GID 1000.${NC}" +# Enhanced security check: Block root user and only allow user with UID 1000 and GID 1000 +if [[ $EUID -eq 0 ]] || [[ $(id -u) -ne 1000 ]] || [[ $(id -g) -ne 1000 ]]; then + echo -e "${RED}WARNING: This script can only be run by the user with UID 1000 and GID 1000, and cannot be run as root.${NC}" read -p "Press [ENTER] to acknowledge" bash /pg/installer/menu_exit.sh exit 1 From f7c442aba3c13649f8cce62ce498b6db5dd522c4 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 17 Sep 2024 05:24:54 -0400 Subject: [PATCH 5/7] update --- mods/scripts/menu.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mods/scripts/menu.sh b/mods/scripts/menu.sh index 540c5dc080..f290839ec4 100644 --- a/mods/scripts/menu.sh +++ b/mods/scripts/menu.sh @@ -4,9 +4,13 @@ RED="\033[0;31m" NC="\033[0m" # No color +# Get the username of the user with UID 1000 +REQUIRED_USER=$(getent passwd 1000 | cut -d: -f1) + # Enhanced security check: Block root user and only allow user with UID 1000 and GID 1000 if [[ $EUID -eq 0 ]] || [[ $(id -u) -ne 1000 ]] || [[ $(id -g) -ne 1000 ]]; then - echo -e "${RED}WARNING: This script can only be run by the user with UID 1000 and GID 1000, and cannot be run as root.${NC}" + echo -e "${RED}WARNING: This script can only be run by the user '$REQUIRED_USER' (UID 1000 and GID 1000).${NC}" + echo -e "${RED}It cannot be run as root or any other user.${NC}" read -p "Press [ENTER] to acknowledge" bash /pg/installer/menu_exit.sh exit 1 From 48c5310a228741f0cd5447c2c957d18bf27743c3 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 17 Sep 2024 05:40:55 -0400 Subject: [PATCH 6/7] update --- mods/scripts/apps/stage.sh | 61 ++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/mods/scripts/apps/stage.sh b/mods/scripts/apps/stage.sh index 200cffb56c..4b4a47c6c9 100644 --- a/mods/scripts/apps/stage.sh +++ b/mods/scripts/apps/stage.sh @@ -19,12 +19,30 @@ MAX_LINE_LENGTH=72 # Arguments deployment_type=$1 # 'personal' for personal deployment, 'official' for official deployment +# Base directory (adjust this to your actual base directory) +BASE_DIR="/pg" + +# Function to safely check if a directory exists +directory_exists() { + if [[ -d "$1" ]]; then + return 0 + else + return 1 + fi +} + # Function to create the appropriate apps directory if it doesn't exist create_apps_directory() { + local target_dir if [[ "$deployment_type" == "personal" ]]; then - [[ ! -d "/pg/p_apps" ]] && mkdir -p /pg/p_apps + target_dir="$BASE_DIR/p_apps" else - [[ ! -d "/pg/apps" ]] && mkdir -p /pg/apps + target_dir="$BASE_DIR/apps" + fi + + if ! directory_exists "$target_dir"; then + echo "Error: Directory $target_dir does not exist and cannot be created." + return 1 fi } @@ -32,18 +50,22 @@ create_apps_directory() { list_available_apps() { local app_dir if [[ "$deployment_type" == "personal" ]]; then - app_dir="/pg/p_apps" + app_dir="$BASE_DIR/p_apps" else - app_dir="/pg/apps" + app_dir="$BASE_DIR/apps" + fi + + if ! directory_exists "$app_dir"; then + echo "Error: App directory $app_dir does not exist." + return 1 fi - local all_apps=$(find "$app_dir" -maxdepth 1 -name "*.app" -type f -exec basename {} .app \; | sort) - local running_apps=$(docker ps --format '{{.Names}}' | sort) + local all_apps=$(find "$app_dir" -maxdepth 1 -name "*.app" -type f -exec basename {} .app \; 2>/dev/null | sort) + local running_apps=$(docker ps --format '{{.Names}}' 2>/dev/null | sort) local available_apps=() for app in $all_apps; do - # Only exclude those that are already running - if ! echo "$running_apps" | grep -i -w "$app" >/dev/null; then + if ! echo "$running_apps" | grep -q -i -w "$app"; then available_apps+=("$app") fi done @@ -59,20 +81,18 @@ display_available_apps() { for app in "${apps_list[@]}"; do local app_length=${#app} - local new_length=$((current_length + app_length + 1)) # +1 for the space + local new_length=$((current_length + app_length + 1)) - # If adding the app would exceed the maximum length, start a new line if [[ $new_length -gt $TERMINAL_WIDTH ]]; then echo "$current_line" current_line="$app " - current_length=$((app_length + 1)) # Reset with the new app and a space + current_length=$((app_length + 1)) else current_line+="$app " current_length=$new_length fi done - # Print the last line if it has content if [[ -n $current_line ]]; then echo "$current_line" fi @@ -81,13 +101,10 @@ display_available_apps() { # Function to deploy the selected app deploy_app() { local app_name=$1 - local app_script - app_script="/pg/scripts/apps/interface.sh" + local app_script="$BASE_DIR/scripts/apps/interface.sh" - # Ensure the app script exists before proceeding if [[ -f "$app_script" ]]; then - # Execute the apps_interface.sh script with the app name as an argument - bash /pg/scripts/apps/interface.sh "$app_name" "$deployment_type" + bash "$app_script" "$app_name" "$deployment_type" else echo "Error: Interface script $app_script not found!" read -p "Press Enter to continue..." @@ -99,13 +116,15 @@ deployment_function() { while true; do clear - create_apps_directory + if ! create_apps_directory; then + echo "Error: Unable to access or create necessary directories." + exit 1 + fi - # Get the list of available apps APP_LIST=($(list_available_apps)) echo -e "${RED}PG: Deployable Apps${NC}" - echo "" # Blank line for separation + echo "" if [[ ${#APP_LIST[@]} -eq 0 ]]; then echo -e "${ORANGE}No More Apps To Deploy${NC}" @@ -114,12 +133,10 @@ deployment_function() { fi echo "════════════════════════════════════════════════════════════════════════════════" - # Prompt the user to enter an app name or exit read -p "$(echo -e "Type [${RED}App${NC}] to Deploy or [${GREEN}Z${NC}] to Exit: ")" app_choice app_choice=$(echo "$app_choice" | tr '[:upper:]' '[:lower:]') - # Check if the user input is "z" if [[ "$app_choice" == "z" ]]; then exit 0 elif [[ " ${APP_LIST[@]} " =~ " $app_choice " ]]; then From 4c1dedc2752802fa9da26865f94a4c3a3945c2ec Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 17 Sep 2024 05:49:24 -0400 Subject: [PATCH 7/7] update --- mods/scripts/menu.sh | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/mods/scripts/menu.sh b/mods/scripts/menu.sh index f290839ec4..53d76e52b0 100644 --- a/mods/scripts/menu.sh +++ b/mods/scripts/menu.sh @@ -7,15 +7,39 @@ NC="\033[0m" # No color # Get the username of the user with UID 1000 REQUIRED_USER=$(getent passwd 1000 | cut -d: -f1) -# Enhanced security check: Block root user and only allow user with UID 1000 and GID 1000 -if [[ $EUID -eq 0 ]] || [[ $(id -u) -ne 1000 ]] || [[ $(id -g) -ne 1000 ]]; then - echo -e "${RED}WARNING: This script can only be run by the user '$REQUIRED_USER' (UID 1000 and GID 1000).${NC}" - echo -e "${RED}It cannot be run as root or any other user.${NC}" +# Function to check if the script is being run with sudo +is_sudo() { + if [ -n "$SUDO_USER" ]; then + return 0 # True, it's being run with sudo + else + return 1 # False, it's not being run with sudo + fi +} + +# Enhanced security check +if [[ -z "$SUDO_USER" ]]; then + echo -e "${RED}WARNING: This script must be run with sudo.${NC}" + echo -e "${RED}Please run it as 'sudo -u $REQUIRED_USER $0 $@'${NC}" + read -p "Press [ENTER] to acknowledge" + bash /pg/installer/menu_exit.sh + exit 1 +elif [[ $SUDO_UID -ne 1000 ]] || [[ $SUDO_GID -ne 1000 ]]; then + echo -e "${RED}WARNING: This script can only be run by the user '$REQUIRED_USER' (UID 1000 and GID 1000) using sudo.${NC}" + echo -e "${RED}Please run it as 'sudo -u $REQUIRED_USER $0 $@'${NC}" + read -p "Press [ENTER] to acknowledge" + bash /pg/installer/menu_exit.sh + exit 1 +elif [[ $EUID -ne 0 ]]; then + echo -e "${RED}WARNING: This script must be run with sudo privileges.${NC}" + echo -e "${RED}Please run it as 'sudo -u $REQUIRED_USER $0 $@'${NC}" read -p "Press [ENTER] to acknowledge" bash /pg/installer/menu_exit.sh exit 1 fi +# If we've made it here, the user is either UID 1000 or is UID 1000 using sudo +echo "Security check passed. Proceeding with the script..." + # Configuration file path CONFIG_FILE="/pg/config/config.cfg"