[API] Update create-lxc.sh / Improve error messages #1 (#2049)

* update create-lxc.sh

* [core] Ignore create_lxc.sh at validate filename (#2059)

* Update validate-filenames.yml

---------

Co-authored-by: CanbiZ <47820557+MickLesk@users.noreply.github.com>
This commit is contained in:
Michel Roegl-Brunner 2025-02-05 16:29:07 +01:00 committed by GitHub
parent 778b6be4e0
commit 5451e61484
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 10 deletions

View File

@ -50,9 +50,13 @@ jobs:
NON_COMPLIANT_FILES=""
for FILE in $CHANGED_FILES; do
# Datei "ct/create_lxc.sh" explizit überspringen
if [[ "$FILE" == "ct/create_lxc.sh" ]]; then
continue
fi
BASENAME=$(echo "$(basename "${FILE%.*}")")
if [[ ! "$BASENAME" =~ ^[a-z0-9-]+$ ]]; then
NON_COMPLIANT_FILES="$NON_COMPLIANT_FILES $FILE"
NON_COMPLIANT_FILES="$NON_COMPLIANT_FILES $FILE"
fi
done

View File

@ -43,6 +43,7 @@ function error_handler() {
local command="$2"
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"
exit 200
}
# This function displays a spinner.
@ -112,7 +113,7 @@ function select_storage() {
CONTENT='vztmpl'
CONTENT_LABEL='Container template'
;;
*) false || exit "Invalid storage class." ;;
*) false || { msg_error "Invalid storage class."; exit 201; };
esac
# This Queries all storage locations
@ -138,7 +139,7 @@ function select_storage() {
STORAGE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \
"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."
"${MENU[@]}" 3>&1 1>&2 2>&3) || { msg_error "Menu aborted."; exit 202; }
if [ $? -ne 0 ]; then
echo -e "${CROSS}${RD} Menu aborted by user.${CL}"
exit 0
@ -148,17 +149,18 @@ 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."
[[ "${CTID:-}" ]] || { msg_error "You need to set 'CTID' variable."; exit 203; }
[[ "${PCT_OSTYPE:-}" ]] || { msg_error "You need to set 'PCT_OSTYPE' variable."; exit 204; }
# Test if ID is valid
[ "$CTID" -ge "100" ] || exit "ID cannot be less than 100."
[ "$CTID" -ge "100" ] || { msg_error "ID cannot be less than 100."; exit 205; }
# 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."
msg_error "Cannot use ID that is already in use."
exit 206
fi
# Get template storage
@ -177,14 +179,15 @@ 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'."
[ ${#TEMPLATES[@]} -gt 0 ] || { msg_error "Unable to find a template when searching for '$TEMPLATE_SEARCH'."; exit 207; }
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 ||
exit "A problem occured while downloading the LXC template."
msg_error "A problem occured while downloading the LXC template."
exit 208
msg_ok "Downloaded LXC Template"
fi
@ -198,5 +201,7 @@ PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}})
# 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."
msg_error "A problem occured while trying to create container."
exit 200
msg_ok "LXC Container ${BL}$CTID${CL} ${GN}was successfully created."