-
-
Notifications
You must be signed in to change notification settings - Fork 626
build.func ‐ script function explanations
Purpose: This function sets up various global variables that will be used throughout the script.
-
NSAPP
: Converts the string value in theAPP
variable to lowercase and removes any spaces. -
var_install
: Appends-install
to theNSAPP
value, representing the installation script name. -
INTEGER
: A regular expression used to validate integer values (with or without decimals). -
PVEHOST_NAME
: Sets the variable to the current hostname of the Proxmox server.
APP="MyApp"
variables
echo $NSAPP # Output: "myapp"
echo $var_install # Output: "myapp-install"
Purpose: Defines various color and formatting variables for terminal output.
- Defines colors like yellow (
YW
), green (GN
), and red (RD
) using ANSI escape codes for text formatting. - Also defines icons for different types of output, such as checkmarks (
CM
), error crosses (CROSS
), and information (INFO
).
color
echo -e "${GN}Success${CL}" # Output: Green colored "Success"
echo -e "${INFO}Info${CL}" # Output: Info icon followed by text "Info"
Purpose: Sets up error handling for the script.
-
set -Eeuo pipefail
: Ensures the script exits immediately if a command fails, an undefined variable is accessed, or if any command in a pipeline fails. -
trap
: Defines a trap to callerror_handler()
when an error occurs, passing the line number and command that failed.
catch_errors
ls non_existent_file # This will cause an error and call the error_handler
Purpose: Handles errors by displaying the error details.
- If a spinner is running, it is stopped.
- The function prints the error details, including the line number and the command that caused the error.
error_handler 42 "ls non_existent_file"
# Output: [ERROR] in line 42: exit code 2: while executing command "ls non_existent_file"
Purpose: Displays a rotating spinner animation.
- The spinner uses a set of frames (
⠋
,⠙
,⠹
, etc.) to simulate a spinning animation in the terminal. - The spinner runs until the process it is indicating is completed.
spinner # Call this function to start the spinner
Purpose: Functions for displaying different types of messages.
-
msg_info()
: Displays an informational message with a spinner animation. -
msg_ok()
: Displays a success message. -
msg_error()
: Displays an error message.
msg_info "This is an informational message"
msg_ok "Success!"
msg_error "An error occurred"
Purpose: Verifies if the script is running in the Bash shell.
- If the script is not running in Bash, it exits with a message indicating that Bash is required.
shell_check # Exits if the shell is not Bash
Purpose: Ensures the script is being run as root.
- If the script is not run as root, it exits with a message asking the user to run the script as root.
root_check # Exits if not run as root
Purpose: Verifies the Proxmox Virtual Environment (PVE) version.
- Ensures the Proxmox version is in the range 8.1 to 8.3, exiting with an error if not.
pve_check # Exits if Proxmox version is not 8.1-8.3
Purpose: Verifies if the system architecture is amd64
.
- If the system architecture is not
amd64
, it exits with a message indicating that the script will not work on ARM architectures (e.g., PiMox).
arch_check # Exits if the architecture is not amd64
Purpose: Retrieves the current IP address based on the operating system.
- For Debian/Ubuntu systems, it uses
hostname -I
. - For Alpine systems, it uses
ip addr show
.
get_current_ip # Outputs the system's current IP address
Purpose: Updates the /etc/motd
file with the current IP address.
- Removes any existing IP address entries from the file and adds the new IP address.
update_motd_ip # Updates the IP address in /etc/motd
Purpose: Displays an ASCII art header with the application name.
- If
figlet
is not installed, it will install it, download the slant font, and generate the ASCII header.
header_info # Displays the ASCII header with the app name
Purpose: Detects if the script is running over SSH.
- Prompts the user for confirmation to proceed if SSH is detected, as SSH might cause complications with certain commands.
ssh_check # Exits if SSH is used, or prompts to proceed
Purpose: Sets up default values for container configuration.
- Sets default values for container type, disk size, CPU count, RAM, and other settings.
- Can be overridden with user inputs.
base_settings # Sets up default settings for the container
Purpose: Outputs the default values for the container configuration.
- Displays the configured settings with corresponding icons.
echo_default # Displays the default configuration values
Purpose: Exits the script with a message.
- Clears the screen and prints a message indicating that the script has exited.
exit_script # Exits the script
Purpose: Allows the user to configure advanced settings for the container.
- Provides an interactive interface using
whiptail
to set advanced options, such as operating system, version, disk size, network configuration, and more.
advanced_settings # Displays an interactive configuration menu
Purpose: Installs the container according to the selected settings.
- Checks system requirements and starts the installation process.
install_script # Starts the container installation process
Purpose: Verifies the system has sufficient resources for the container.
- Ensures that the system has enough RAM and CPU cores for the container.
check_container_resources # Verifies if enough resources are available
Purpose: Verifies if the /boot
partition has sufficient space.
- Warns the user if storage is more than 80% full.
check_container_storage # Warns if /boot partition is over 80% full
Purpose: Initializes the installation or update process based on user choice.
- Prompts the user to confirm before proceeding with container creation or updates.
start # Starts the container creation or update process
Purpose: Builds the container using the defined settings.
- Collects user inputs, configures the container, and creates it using
pct
commands.
build_container # Builds the container with the selected settings
Purpose: Sets the description for the created container.
- Generates an HTML description for the container and adds it to the container configuration.
description # Sets the container description