@@ -43,6 +43,7 @@ function error_handler() {
4343 local command=" $2 "
4444 local error_message=" ${RD} [ERROR]${CL} in line ${RD} $line_number ${CL} : exit code ${RD} $exit_code ${CL} : while executing command ${YW} $command ${CL} "
4545 echo -e " \n$error_message \n"
46+ exit 200
4647}
4748
4849# This function displays a spinner.
@@ -112,7 +113,7 @@ function select_storage() {
112113 CONTENT=' vztmpl'
113114 CONTENT_LABEL=' Container template'
114115 ;;
115- * ) false || exit " Invalid storage class." ; ;
116+ * ) false || { msg_error " Invalid storage class." ; exit 201 ; } ;
116117 esac
117118
118119 # This Queries all storage locations
@@ -138,7 +139,7 @@ function select_storage() {
138139 STORAGE=$( whiptail --backtitle " Proxmox VE Helper Scripts" --title " Storage Pools" --radiolist \
139140 " Which storage pool you would like to use for the ${CONTENT_LABEL,,} ?\nTo make a selection, use the Spacebar.\n" \
140141 16 $(( $MSG_MAX_LENGTH + 23 )) 6 \
141- " ${MENU[@]} " 3>&1 1>&2 2>&3 ) || exit " Menu aborted."
142+ " ${MENU[@]} " 3>&1 1>&2 2>&3 ) || { msg_error " Menu aborted." ; exit 202 ; }
142143 if [ $? -ne 0 ]; then
143144 echo -e " ${CROSS}${RD} Menu aborted by user.${CL} "
144145 exit 0
@@ -148,17 +149,18 @@ function select_storage() {
148149 fi
149150}
150151# Test if required variables are set
151- [[ " ${CTID:- } " ]] || exit " You need to set 'CTID' variable."
152- [[ " ${PCT_OSTYPE:- } " ]] || exit " You need to set 'PCT_OSTYPE' variable."
152+ [[ " ${CTID:- } " ]] || { msg_error " You need to set 'CTID' variable." ; exit 203 ; }
153+ [[ " ${PCT_OSTYPE:- } " ]] || { msg_error " You need to set 'PCT_OSTYPE' variable." ; exit 204 ; }
153154
154155# Test if ID is valid
155- [ " $CTID " -ge " 100" ] || exit " ID cannot be less than 100."
156+ [ " $CTID " -ge " 100" ] || { msg_error " ID cannot be less than 100." ; exit 205 ; }
156157
157158# Test if ID is in use
158159if pct status $CTID & > /dev/null; then
159160 echo -e " ID '$CTID ' is already in use."
160161 unset CTID
161- exit " Cannot use ID that is already in use."
162+ msg_error " Cannot use ID that is already in use."
163+ exit 206
162164fi
163165
164166# Get template storage
@@ -177,14 +179,15 @@ msg_ok "Updated LXC Template List"
177179# Get LXC template string
178180TEMPLATE_SEARCH=${PCT_OSTYPE} -${PCT_OSVERSION:- }
179181mapfile -t TEMPLATES < <( pveam available -section system | sed -n " s/.*\($TEMPLATE_SEARCH .*\)/\1/p" | sort -t - -k 2 -V)
180- [ ${# TEMPLATES[@]} -gt 0 ] || exit " Unable to find a template when searching for '$TEMPLATE_SEARCH '."
182+ [ ${# TEMPLATES[@]} -gt 0 ] || { msg_error " Unable to find a template when searching for '$TEMPLATE_SEARCH '." ; exit 207 ; }
181183TEMPLATE=" ${TEMPLATES[-1]} "
182184
183185# Download LXC template if needed
184186if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE ; then
185187 msg_info " Downloading LXC Template"
186188 pveam download $TEMPLATE_STORAGE $TEMPLATE > /dev/null ||
187- exit " A problem occured while downloading the LXC template."
189+ msg_error " A problem occured while downloading the LXC template."
190+ exit 208
188191 msg_ok " Downloaded LXC Template"
189192fi
190193
@@ -198,5 +201,7 @@ PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}})
198201# Create container
199202msg_info " Creating LXC Container"
200203pct create $CTID ${TEMPLATE_STORAGE} :vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} > /dev/null ||
201- exit " A problem occured while trying to create container."
204+ msg_error " A problem occured while trying to create container."
205+ exit 200
202206msg_ok " LXC Container ${BL} $CTID ${CL} ${GN} was successfully created."
207+
0 commit comments