Massive Update: build.func | install.func | create_lxc.sh (Part 1) (#643)

* Big Update: Build.func Install.Func Create_LXC

* Change Author

Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com>

* Fix indentation / naming / echos

* Fix some Parts

* Add alpine-install.func

* update alpine to 3.20

* fix spaces

* Update build.func

* Merge Create_LXC from DEV

* Merge from DEV

* Merge from DEV

---------

Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com>
This commit is contained in:
CanbiZ
2024-12-16 12:41:51 +01:00
committed by GitHub
parent bcc6342f83
commit 315949b446
5 changed files with 435 additions and 173 deletions

View File

@ -2,6 +2,7 @@
# Copyright (c) 2021-2024 tteck
# Author: tteck (tteckster)
# Co-Author: MickLesk
# License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
@ -9,15 +10,25 @@
# if [ "$VERBOSE" == "yes" ]; then set -x; fi
# This function sets color variables for formatting output in the terminal
# Colors
YW=$(echo "\033[33m")
YWB=$(echo "\033[93m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
GN=$(echo "\033[1;92m")
# Formatting
CL=$(echo "\033[m")
CM="${GN}${CL}"
CROSS="${RD}${CL}"
UL=$(echo "\033[4m")
BOLD=$(echo "\033[1m")
BFR="\\r\\033[K"
HOLD=" "
TAB=" "
# Icons
CM="${TAB}✔️${TAB}${CL}"
CROSS="${TAB}✖️${TAB}${CL}"
INFO="${TAB}💡${TAB}${CL}"
# This sets error handling options and defines the error_handler function to handle errors
set -Eeuo pipefail
@ -36,19 +47,24 @@ function error_handler() {
# This function displays a spinner.
function spinner() {
local chars="/-\|"
local spin_i=0
printf "\e[?25l"
while true; do
printf "\r \e[36m%s\e[0m" "${chars:spin_i++%${#chars}:1}"
sleep 0.1
done
local frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
local spin_i=0
local interval=0.1
printf "\e[?25l"
local color="${YWB}"
while true; do
printf "\r ${color}%s${CL}" "${frames[spin_i]}"
spin_i=$(( (spin_i + 1) % ${#frames[@]} ))
sleep "$interval"
done
}
# This function displays an informational message with a yellow color.
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg} "
echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}"
spinner &
SPINNER_PID=$!
}
@ -58,7 +74,7 @@ function msg_ok() {
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
printf "\e[?25h"
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
echo -e "${BFR}${CM}${GN}${msg}${CL}"
}
# This function displays a error message with a red color.
@ -66,7 +82,7 @@ function msg_error() {
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID > /dev/null; then kill $SPINNER_PID > /dev/null; fi
printf "\e[?25h"
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
echo -e "${BFR}${CROSS}${RD}${msg}${CL}"
}
# This checks for the presence of valid Container Storage and Template Storage locations
@ -105,7 +121,7 @@ function select_storage() {
local TAG=$(echo $line | awk '{print $1}')
local TYPE=$(echo $line | awk '{printf "%-10s", $2}')
local FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
local ITEM=" Type: $TYPE Free: $FREE "
local ITEM="Type: $TYPE Free: $FREE "
local OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
@ -123,11 +139,14 @@ function select_storage() {
"Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\nTo make a selection, use the Spacebar.\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${MENU[@]}" 3>&1 1>&2 2>&3) || exit "Menu aborted."
if [ $? -ne 0 ]; then
echo -e "${CROSS}${RD} Menu aborted by user.${CL}"
exit 0
fi
done
printf $STORAGE
printf "%s" "$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."