Compare commits

...

6 Commits

Author SHA1 Message Date
tteckster c9006a67d6
Update CHANGELOG.md 2023-05-16 00:32:39 -04:00
tteckster 92babeac23
Update update-lxcs.sh
add information about the boot disk, which provides an easy way to determine if you need to expand the disk.
2023-05-16 00:27:25 -04:00
tteckster eda9208477
Update CODE-AUDIT.md 2023-05-15 19:26:16 -04:00
tteckster caea206144
Update create_lxc.sh
added code descriptions
2023-05-15 19:15:26 -04:00
tteckster 3a06811e01
Update build.func
added code descriptions
2023-05-15 18:55:53 -04:00
tteckster 9192b8b076
Update install.func
added code descriptions
2023-05-15 18:33:04 -04:00
6 changed files with 78 additions and 15 deletions

View File

@ -2,6 +2,13 @@
# Change Log
All notable changes to this project will be documented in this file.
## 2023-05-16
### Changed
- **Proxmox VE LXC Updater**
- Add information about the boot disk, which provides an easy way to determine if you need to expand the disk.
## 2023-05-13
### Changed

View File

@ -1,9 +1,9 @@
In the case of the < app > LXC, the process involves running multiple scripts for each application or service.<br>
Initially, the `<app>.sh` script is executed to collect system parameters.<br>
Next, the `build.func` script adds user settings and integrates all the collected information.<br>
Then, the `create_lxc.sh` script constructs the LXC container.<br>
Following that, the `<app>-install.sh` script is executed, which utilizes the functions exported from the `install.func` script for installing the required applications.<br>
Finally, the process returns to the `<app>.sh` script to display the completion message.<br>
In the case of the AdGuard Home LXC, the process involves running multiple scripts for each application or service.<br>
Initially, the [adguard.sh](https://github.com/tteck/Proxmox/blob/main/ct/adguard.sh) script is executed to collect system parameters.<br>
Next, the [build.func](https://github.com/tteck/Proxmox/blob/main/misc/build.func) script adds user settings and integrates all the collected information.<br>
Then, the [create_lxc.sh](https://github.com/tteck/Proxmox/blob/main/ct/create_lxc.sh) script constructs the LXC container.<br>
Following that, the [adguard-install.sh](https://github.com/tteck/Proxmox/blob/main/install/adguard-install.sh) script is executed, which utilizes the functions exported from the [install.func](https://github.com/tteck/Proxmox/blob/main/misc/install.func) script for installing the required applications.<br>
Finally, the process returns to the [adguard.sh](https://github.com/tteck/Proxmox/blob/main/ct/adguard.sh) script to display the completion message.<br>
Thoroughly evaluating the `<app>-install.sh` script is crucial to gain a better understanding of the application installation process.<br>
Every application installation utilizes the same set of reusable scripts: `build.func`, `create_lxc.sh`, and `install.func`. These scripts are not specific to any particular application.<br>
Thoroughly evaluating the [adguard-install.sh](https://github.com/tteck/Proxmox/blob/main/install/adguard-install.sh) script is crucial to gain a better understanding of the application installation process.<br>
Every application installation utilizes the same set of reusable scripts: [build.func](https://github.com/tteck/Proxmox/blob/main/misc/build.func), [create_lxc.sh](https://github.com/tteck/Proxmox/blob/main/ct/create_lxc.sh), and [install.func](https://github.com/tteck/Proxmox/blob/main/misc/install.func). These scripts are not specific to any particular application.<br>

View File

@ -5,7 +5,10 @@
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
# This sets verbose mode if the global variable is set to "yes"
if [ "$VERBOSE" == "yes" ]; then set -x; fi
# This function sets color variables for formatting output in the terminal
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
@ -15,8 +18,12 @@ CM="${GN}✓${CL}"
CROSS="${RD}${CL}"
BFR="\\r\\033[K"
HOLD="-"
# This sets error handling options and defines the error_handler function to handle errors
set -Eeuo pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
# This function handles errors
function error_handler() {
local exit_code="$?"
local line_number="$1"
@ -24,20 +31,26 @@ function error_handler() {
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
echo -e "\n$error_message\n"
}
# This function prints an informational message
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
# This function prints a success message
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
# This function prints an error message
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
# This checks for the presence of valid Container Storage and Template Storage locations
msg_info "Validating Storage"
VALIDCT=$(pvesm status -content rootdir | awk 'NR>1')
if [ -z "$VALIDCT" ]; then
@ -50,6 +63,7 @@ if [ -z "$VALIDTMP" ]; then
exit 1
fi
# This function is used to select the storage class and determine the corresponding storage content type and label.
function select_storage() {
local CLASS=$1
local CONTENT
@ -65,7 +79,8 @@ function select_storage() {
;;
*) false || exit "Invalid storage class." ;;
esac
# This Queries all storage locations
local -a MENU
while read -r line; do
local TAG=$(echo $line | awk '{print $1}')
@ -78,7 +93,8 @@ function select_storage() {
fi
MENU+=("$TAG" "$ITEM" "OFF")
done < <(pvesm status -content $CONTENT | awk 'NR>1')
# Select storage location
if [ $((${#MENU[@]} / 3)) -eq 1 ]; then
printf ${MENU[0]}
else
@ -93,32 +109,40 @@ function select_storage() {
fi
}
# Test if required variables are set
[[ "${CTID:-}" ]] || exit "You need to set 'CTID' variable."
[[ "${PCT_OSTYPE:-}" ]] || exit "You need to set 'PCT_OSTYPE' variable."
# Test if ID is valid
[ "$CTID" -ge "100" ] || exit "ID cannot be less than 100."
# Test if ID is in use
if pct status $CTID &>/dev/null; then
echo -e "ID '$CTID' is already in use."
unset CTID
exit "Cannot use ID that is already in use."
fi
# Get template storage
TEMPLATE_STORAGE=$(select_storage template) || exit
msg_ok "Using ${BL}$TEMPLATE_STORAGE${CL} ${GN}for Template Storage."
# Get container storage
CONTAINER_STORAGE=$(select_storage container) || exit
msg_ok "Using ${BL}$CONTAINER_STORAGE${CL} ${GN}for Container Storage."
# Update LXC template list
msg_info "Updating LXC Template List"
pveam update >/dev/null
msg_ok "Updated LXC Template List"
# Get LXC template string
TEMPLATE_SEARCH=${PCT_OSTYPE}-${PCT_OSVERSION:-}
mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V)
[ ${#TEMPLATES[@]} -gt 0 ] || exit "Unable to find a template when searching for '$TEMPLATE_SEARCH'."
TEMPLATE="${TEMPLATES[-1]}"
# Download LXC template if needed
if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then
msg_info "Downloading LXC Template"
pveam download $TEMPLATE_STORAGE $TEMPLATE >/dev/null ||
@ -126,12 +150,14 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then
msg_ok "Downloaded LXC Template"
fi
# Combine all options
DEFAULT_PCT_OPTIONS=(
-arch $(dpkg --print-architecture))
PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}})
[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8})
# Create container
msg_info "Creating LXC Container"
pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null ||
exit "A problem occured while trying to create container."

View File

@ -1,9 +1,10 @@
variables() {
NSAPP=$(echo ${APP,,} | tr -d ' ')
var_install="${NSAPP}-install"
INTEGER='^[0-9]+([.][0-9]+)?$'
NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces.
var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP.
INTEGER='^[0-9]+([.][0-9]+)?$' # it defines the INTEGER regular expression pattern.
}
# This function sets various color variables using ANSI escape codes for formatting text in the terminal.
color() {
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
@ -18,11 +19,13 @@ color() {
HOLD="-"
}
# This function enables error handling in the script by setting options and defining a trap for the ERR signal.
catch_errors() {
set -Eeuo pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
}
# This function is called when an error occurs. It receives the exit code, line number, and command that caused the error, and displays an error message.
error_handler() {
local exit_code="$?"
local line_number="$1"
@ -31,21 +34,25 @@ error_handler() {
echo -e "\n$error_message\n"
}
# This function displays an informational message with a yellow color.
msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
# This function displays a success message with a green color.
msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
# This function displays an error message with a red color.
msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
# This function checks the version of Proxmox Virtual Environment (PVE) and exits if the version is not supported.
pve_check() {
if [ $(pveversion | grep -c "pve-manager/7\.[0-9]") -eq 0 ]; then
echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported"
@ -56,6 +63,7 @@ pve_check() {
fi
}
# This function checks the system architecture and exits if it's not "amd64".
arch_check() {
if [ "$(dpkg --print-architecture)" != "amd64" ]; then
echo -e "\n ${CROSS} This script will not work with PiMox! \n"
@ -65,6 +73,7 @@ arch_check() {
fi
}
# This function checks if the script is running through SSH and prompts the user to confirm if they want to proceed or exit.
ssh_check() {
if command -v pveversion >/dev/null 2>&1; then
if [ -n "${SSH_CLIENT:+x}" ]; then
@ -78,6 +87,7 @@ ssh_check() {
fi
}
# This function displays the default values for various settings.
echo_default() {
echo -e "${DGN}Using Distribution: ${BGN}$var_os${CL}"
echo -e "${DGN}Using $var_os Version: ${BGN}$var_version${CL}"
@ -105,12 +115,14 @@ echo_default() {
echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
}
# This function is called when the user decides to exit the script. It clears the screen and displays an exit message.
exit-script() {
clear
echo -e "⚠ User exited script \n"
exit
}
# This function allows the user to configure advanced settings for the script.
advanced_settings() {
whiptail --msgbox --title "Here is an instructional tip:" "To make a selection, use the Spacebar." 8 58
whiptail --msgbox --title "Default distribution for $APP" "${var_os} \n${var_version} \n" 8 58
@ -433,6 +445,7 @@ start() {
fi
}
# This function collects user settings and integrates all the collected information.
build_container() {
if [ "$VERB" == "yes" ]; then set -x; fi
@ -485,6 +498,7 @@ build_container() {
-unprivileged $CT_TYPE
$PW
"
# This executes create_lxc.sh and creates the container and .conf file
bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
@ -519,6 +533,7 @@ EOF
fi
fi
# This starts the container and executes <app>-install.sh
msg_info "Starting LXC Container"
pct start "$CTID"
msg_ok "Started LXC Container"
@ -530,6 +545,7 @@ EOF
}
# This function sets the description of the container.
description() {
IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
pct set "$CTID" -description "# ${APP} LXC

View File

@ -1,3 +1,4 @@
# This function sets color variables for formatting output in the terminal
color() {
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
@ -14,6 +15,7 @@ color() {
HOLD="-"
}
# This function enables IPv6 if it's not disabled and sets verbose mode if the global variable is set to "yes"
verb_ip6() {
if [ "$VERBOSE" = "yes" ]; then
set -x
@ -26,11 +28,13 @@ verb_ip6() {
fi
}
# This function sets error handling options and defines the error_handler function to handle errors
catch_errors() {
set -Eeuo pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
}
# This function handles errors
error_handler() {
local exit_code="$?"
local line_number="$1"
@ -42,21 +46,25 @@ error_handler() {
fi
}
# This function prints an informational message
msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
# This function prints a success message
msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
# This function prints an error message
msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
# This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection
setting_up_container() {
msg_info "Setting up Container OS"
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
@ -79,6 +87,7 @@ setting_up_container() {
msg_ok "Network Connected: ${BL}$(hostname -I)"
}
# This function checks the network connection by pinging a known IP address and prompts the user to continue if the internet is not connected
network_check() {
set +e
trap - ERR
@ -98,6 +107,7 @@ network_check() {
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
}
# This function updates the Container OS by running apt-get update and upgrade
update_os() {
msg_info "Updating Container OS"
$STD apt-get update
@ -105,6 +115,7 @@ update_os() {
msg_ok "Updated Container OS"
}
# This function modifies the message of the day (motd) and SSH settings
motd_ssh() {
echo "export TERM='xterm-256color'" >>/root/.bashrc
echo -e "$APPLICATION LXC provided by https://tteck.github.io/Proxmox/\n" >/etc/motd
@ -115,6 +126,7 @@ motd_ssh() {
fi
}
# This function customizes the container by modifying the getty service and enabling auto-login for the root user
customize() {
if [[ "$PASSWORD" == "" ]]; then
msg_info "Customizing Container"
@ -129,4 +141,4 @@ EOF
systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
msg_ok "Customized Container"
fi
}
}

View File

@ -39,7 +39,9 @@ function update_container() {
container=$1
header_info
name=$(pct exec "$container" hostname)
echo -e "${BL}[Info]${GN} Updating ${BL}$container${CL} : ${GN}$name${CL} \n"
disk_info=$(pct exec "$container" df /boot | awk 'NR==2{gsub("%","",$5); printf "%s %.1fG %.1fG %.1fG", $5, $3/1024/1024, $2/1024/1024, $4/1024/1024 }')
read -ra disk_info_array <<< "$disk_info"
echo -e "${BL}[Info]${GN} Updating ${BL}$container${CL} : ${GN}$name${CL} - ${YW}Boot Disk: ${disk_info_array[0]}% full [${disk_info_array[1]}/${disk_info_array[2]} used, ${disk_info_array[3]} free]${CL}\n"
os=$(pct config "$container" | awk '/^ostype/ {print $2}')
case "$os" in
alpine) pct exec "$container" -- ash -c "apk update && apk upgrade" ;;