From 9c44b26add7f23b0f78d7c752c6b1259f7a319b1 Mon Sep 17 00:00:00 2001 From: tteckster Date: Thu, 31 Aug 2023 14:21:31 -0400 Subject: [PATCH] turnkey scripts code refactoring --- turnkey/turnkey-core.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-fileserver.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-gitea.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-gitlab.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-nextcloud.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-observium.sh | 53 ++++++++++++------------- turnkey/turnkey-openvpn.sh | 54 ++++++++++++-------------- turnkey/turnkey-owncloud.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-torrentserver.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-wordpress.sh | 66 ++++++++++++++++++++++---------- turnkey/turnkey-zoneminder.sh | 65 +++++++++++++++++++++---------- 11 files changed, 455 insertions(+), 245 deletions(-) diff --git a/turnkey/turnkey-core.sh b/turnkey/turnkey-core.sh index 9db74e64..2294896d 100644 --- a/turnkey/turnkey-core.sh +++ b/turnkey/turnkey-core.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-core.sh)" # Setup script environment NAME="core" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-fileserver.sh b/turnkey/turnkey-fileserver.sh index 66efe4b1..88bbd21d 100644 --- a/turnkey/turnkey-fileserver.sh +++ b/turnkey/turnkey-fileserver.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-fileserver.sh)" # Setup script environment NAME="fileserver" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-4} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-gitea.sh b/turnkey/turnkey-gitea.sh index 16838fb5..85ef344b 100644 --- a/turnkey/turnkey-gitea.sh +++ b/turnkey/turnkey-gitea.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-gitea.sh)" # Setup script environment NAME="gitea" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-gitlab.sh b/turnkey/turnkey-gitlab.sh index 9b8127f3..a85c609a 100644 --- a/turnkey/turnkey-gitlab.sh +++ b/turnkey/turnkey-gitlab.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-gitlab.sh)" # Setup script environment NAME="gitlab" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-nextcloud.sh b/turnkey/turnkey-nextcloud.sh index 8dc8f673..cdbc41d9 100644 --- a/turnkey/turnkey-nextcloud.sh +++ b/turnkey/turnkey-nextcloud.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-nextcloud.sh)" # Setup script environment NAME="nextcloud" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-observium.sh b/turnkey/turnkey-observium.sh index 89e93204..da16c7ae 100644 --- a/turnkey/turnkey-observium.sh +++ b/turnkey/turnkey-observium.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT @@ -38,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -82,6 +78,8 @@ function cleanup_ctid() { if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -103,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -149,8 +147,8 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then fi # Create variable for 'pct' options -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." @@ -166,24 +164,23 @@ pct start "$CTID" sleep 5 # Get container IP -max_attempts=6 +max_attempts=5 attempt=1 IP="" - while [[ $attempt -le $max_attempts ]]; do - IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') - if [[ -n $IP ]]; then - break - else - warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." - sleep 5 - ((attempt++)) - fi + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi done if [[ -z $IP ]]; then - warn "Maximum number of attempts reached. IP address not found." - IP="NOT FOUND" + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" fi # Start Proxmox VE Monitor-All if available @@ -200,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-openvpn.sh b/turnkey/turnkey-openvpn.sh index 8a7edab0..c1548cab 100644 --- a/turnkey/turnkey-openvpn.sh +++ b/turnkey/turnkey-openvpn.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT @@ -38,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,11 +74,12 @@ function cleanup_ctid() { fi } -# Start Proxmox VE Monitor-All if running +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -104,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -150,8 +147,8 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then fi # Create variable for 'pct' options -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." @@ -167,24 +164,23 @@ pct start "$CTID" sleep 5 # Get container IP -max_attempts=6 +max_attempts=5 attempt=1 IP="" - while [[ $attempt -le $max_attempts ]]; do - IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') - if [[ -n $IP ]]; then - break - else - warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." - sleep 5 - ((attempt++)) - fi + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi done if [[ -z $IP ]]; then - warn "Maximum number of attempts reached. IP address not found." - IP="NOT FOUND" + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" fi # Start Proxmox VE Monitor-All if available @@ -201,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-owncloud.sh b/turnkey/turnkey-owncloud.sh index 2a263a79..a71630b9 100644 --- a/turnkey/turnkey-owncloud.sh +++ b/turnkey/turnkey-owncloud.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-owncloud.sh)" # Setup script environment NAME="owncloud" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-torrentserver.sh b/turnkey/turnkey-torrentserver.sh index ce74f19e..549a7786 100644 --- a/turnkey/turnkey-torrentserver.sh +++ b/turnkey/turnkey-torrentserver.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-torrentserver.sh)" # Setup script environment NAME="torrentserver" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-wordpress.sh b/turnkey/turnkey-wordpress.sh index 5e953343..63858486 100644 --- a/turnkey/turnkey-wordpress.sh +++ b/turnkey/turnkey-wordpress.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT # https://github.com/tteck/Proxmox/raw/main/LICENSE -# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-wordpress.sh)" # Setup script environment NAME="wordpress" @@ -39,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -78,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -102,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -147,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -173,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file diff --git a/turnkey/turnkey-zoneminder.sh b/turnkey/turnkey-zoneminder.sh index 300c6d30..ba90bd4f 100644 --- a/turnkey/turnkey-zoneminder.sh +++ b/turnkey/turnkey-zoneminder.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# A primitive script to install TurnKey LXC templates using basic settings. # Copyright (c) 2021-2023 tteck # Author: tteck (tteckster) # License: MIT @@ -38,10 +37,7 @@ EOF header_info read -p "Press ENTER to continue..." header_info -set -o errexit #Exit immediately if a pipeline returns a non-zero status -set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell -set -o nounset #Treat unset variables as an error -set -o pipefail #Pipe will exit with last non-zero status if applicable +set -eEuo pipefail shopt -s expand_aliases alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR @@ -77,9 +73,13 @@ function cleanup_ctid() { pct destroy $CTID fi } + +# Stop Proxmox VE Monitor-All if running if systemctl is-active -q ping-instances.service; then systemctl stop ping-instances.service fi + +# Set the CONTENT and CONTENT_LABEL variables function select_storage() { local CLASS=$1 local CONTENT @@ -101,22 +101,22 @@ function select_storage() { if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) fi - MENU+=( "$TAG" "$ITEM" "OFF" ) + MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content $CONTENT | awk 'NR>1') # Select storage location - if [ $((${#MENU[@]}/3)) -eq 0 ]; then # No storage locations are detected + if [ $((${#MENU[@]} / 3)) -eq 0 ]; then warn "'$CONTENT_LABEL' needs to be selected for at least one storage location." die "Unable to detect valid storage location." - elif [ $((${#MENU[@]}/3)) -eq 1 ]; then # Only one storage location is detected + elif [ $((${#MENU[@]} / 3)) -eq 1 ]; then printf ${MENU[0]} - else # More than one storage location is detected + else local STORAGE - while [ -z "${STORAGE:+x}" ]; do # Generate graphical menu + while [ -z "${STORAGE:+x}" ]; do STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." + "Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted." done printf $STORAGE fi @@ -146,24 +146,49 @@ if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then die "A problem occured while downloading the LXC template." fi -PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} ) -[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} ) +# Create variable for 'pct' options +PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) +[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}) # Create LXC msg "Creating LXC container..." pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null || die "A problem occured while trying to create container." -# Success message +# Save password +echo "TurnKey ${NAME} password: ${PASS}" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory + +# Start container msg "Starting LXC Container..." pct start "$CTID" sleep 5 -IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') -echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-${NAME}.creds + +# Get container IP +max_attempts=5 +attempt=1 +IP="" +while [[ $attempt -le $max_attempts ]]; do + IP=$(pct exec $CTID ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}') + if [[ -n $IP ]]; then + break + else + warn "Attempt $attempt: IP address not found. Pausing for 5 seconds..." + sleep 5 + ((attempt++)) + fi +done + +if [[ -z $IP ]]; then + warn "Maximum number of attempts reached. IP address not found." + IP="NOT FOUND" +fi + +# Start Proxmox VE Monitor-All if available if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi + +# Success message header_info echo info "LXC container '$CTID' was successfully created, and its IP address is ${IP}." @@ -172,4 +197,4 @@ info "Proceed to the LXC console to complete the setup." echo info "login: root" info "password: $PASS" -echo +echo \ No newline at end of file