From 604c20df17d37253cfd044a525f23e65517dca71 Mon Sep 17 00:00:00 2001 From: tteckster Date: Tue, 29 Aug 2023 19:17:30 -0400 Subject: [PATCH] turnkey code refactoring --- turnkey/turnkey-core.sh | 25 +++++++------------------ turnkey/turnkey-fileserver.sh | 25 +++++++------------------ turnkey/turnkey-gitlab.sh | 25 +++++++------------------ turnkey/turnkey-nextcloud.sh | 25 +++++++------------------ turnkey/turnkey-observium.sh | 25 +++++++------------------ turnkey/turnkey-owncloud.sh | 25 +++++++------------------ turnkey/turnkey-wordpress.sh | 25 +++++++------------------ 7 files changed, 49 insertions(+), 126 deletions(-) diff --git a/turnkey/turnkey-core.sh b/turnkey/turnkey-core.sh index d850eabe..6739424b 100644 --- a/turnkey/turnkey-core.sh +++ b/turnkey/turnkey-core.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-core.sh)" # Setup script environment +NAME="core" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-core_17.1-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.1-1_amd64.tar.gz" +PCT_DISK_SIZE="4" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-core + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 2 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey Core Password" >>~/turnkey-core.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-core.creds #run `cat turnkey-core.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi diff --git a/turnkey/turnkey-fileserver.sh b/turnkey/turnkey-fileserver.sh index fea4aa0b..859c9f7b 100644 --- a/turnkey/turnkey-fileserver.sh +++ b/turnkey/turnkey-fileserver.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-fileserver.sh)" # Setup script environment +NAME="fileserver" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-fileserver_17.1-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.1-1_amd64.tar.gz" +PCT_DISK_SIZE="8" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-fileserver + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 2 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey File Server Password" >>~/turnkey-fileserver.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-fileserver.creds #run `cat turnkey-fileserver.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi diff --git a/turnkey/turnkey-gitlab.sh b/turnkey/turnkey-gitlab.sh index ffdd3e58..1feddb3a 100644 --- a/turnkey/turnkey-gitlab.sh +++ b/turnkey/turnkey-gitlab.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-gitlab.sh)" # Setup script environment +NAME="gitlab" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-gitlab_17.1-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.1-1_amd64.tar.gz" +PCT_DISK_SIZE="8" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-gitlab + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 4 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey GitLab Password" >>~/turnkey-gitlab.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-gitlab.creds #run `cat turnkey-gitlab.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi diff --git a/turnkey/turnkey-nextcloud.sh b/turnkey/turnkey-nextcloud.sh index ebd2b5cd..dfbd2247 100644 --- a/turnkey/turnkey-nextcloud.sh +++ b/turnkey/turnkey-nextcloud.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-nextcloud.sh)" # Setup script environment +NAME="nextcloud" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-nextcloud_17.2-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.2-1_amd64.tar.gz" +PCT_DISK_SIZE="10" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-nextcloud + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 2 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey Nextcloud Password" >>~/turnkey-nextcloud.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-nextcloud.creds #run `cat turnkey-nextcloud.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi diff --git a/turnkey/turnkey-observium.sh b/turnkey/turnkey-observium.sh index 52ae0971..bbde4f62 100644 --- a/turnkey/turnkey-observium.sh +++ b/turnkey/turnkey-observium.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-observium.sh)" # Setup script environment +NAME="observium" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-observium_17.2-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.2-1_amd64.tar.gz" +PCT_DISK_SIZE="4" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-observium + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 2 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey Observium Password" >>~/turnkey-observium.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-observium.creds #run `cat turnkey-observium.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi diff --git a/turnkey/turnkey-owncloud.sh b/turnkey/turnkey-owncloud.sh index 56ea54f9..74f4b5e6 100644 --- a/turnkey/turnkey-owncloud.sh +++ b/turnkey/turnkey-owncloud.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-owncloud.sh)" # Setup script environment +NAME="owncloud" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-owncloud_17.1-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.1-1_amd64.tar.gz" +PCT_DISK_SIZE="10" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-owncloud + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 2 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey ownCloud Password" >>~/turnkey-owncloud.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-owncloud.creds #run `cat turnkey-owncloud.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi diff --git a/turnkey/turnkey-wordpress.sh b/turnkey/turnkey-wordpress.sh index 9d9b5620..39039884 100644 --- a/turnkey/turnkey-wordpress.sh +++ b/turnkey/turnkey-wordpress.sh @@ -7,11 +7,14 @@ # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/turnkey/turnkey-wordpress.sh)" # Setup script environment +NAME="wordpress" PASS="$(openssl rand -base64 8)" -TEMPLATE_SEARCH="debian-11-turnkey-wordpress_17.1-1_amd64.tar.gz" +CTID=$(pvesh get /cluster/nextid) +TEMPLATE_SEARCH="debian-11-turnkey-${NAME}_17.1-1_amd64.tar.gz" +PCT_DISK_SIZE="8" PCT_OPTIONS=" -features keyctl=1,nesting=1 - -hostname turnkey-wordpress + -hostname turnkey-${NAME} -tags proxmox-helper-scripts -onboot 1 -cores 2 @@ -118,20 +121,6 @@ function select_storage() { fi } -# Test if required variables are set -CTID=$(pvesh get /cluster/nextid) -[[ "${CTID:-}" ]] || die "You need to set 'CTID' variable." - -# Test if ID is valid -[ "$CTID" -ge "100" ] || die "ID cannot be less than 100." - -# Test if ID is in use -if pct status $CTID &>/dev/null; then - warn "ID '$CTID' is already in use." - unset CTID - die "Cannot use ID that is already in use." -fi - # Get template storage TEMPLATE_STORAGE=$(select_storage template) || exit info "Using '$TEMPLATE_STORAGE' for template storage." @@ -168,8 +157,8 @@ pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/ msg "Starting LXC Container..." pct start "$CTID" info "LXC container '$CTID' was successfully created." -echo "TurnKey WordPress Password" >>~/turnkey-wordpress.creds # file is located in the Proxmox root directory -echo $PASS >>~/turnkey-wordpress.creds #run `cat turnkey-wordpress.creds` in the Proxmox shell +echo "TurnKey ${NAME} Password" >>~/turnkey-${NAME}.creds # file is located in the Proxmox root directory +echo $PASS >>~/turnkey-${NAME}.creds if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service fi