diff --git a/ct/adguard-v4.sh b/ct/adguard-v4.sh deleted file mode 100644 index c7f12804..00000000 --- a/ct/adguard-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Adguard" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${GN} - ___ __ __ - / | ____/ /___ ___ ______ __________/ / - / /| |/ __ / __ / / / / __ / ___/ __ / - / ___ / /_/ / /_/ / /_/ / /_/ / / / /_/ / -/_/v4|_\__,_/\__, /\__,_/\__,_/_/ \__,_/ - /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} Setup should be reachable by going to the following URL. - ${BL}http://${IP}:3000${CL} \n" diff --git a/ct/adguard-v5.sh b/ct/adguard-v5.sh index daf5027a..9cec3c16 100644 --- a/ct/adguard-v5.sh +++ b/ct/adguard-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -141,7 +135,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -316,7 +309,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -380,7 +372,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/alpine-v5.sh b/ct/alpine-v5.sh index 7f9c7d03..38ffc8c7 100644 --- a/ct/alpine-v5.sh +++ b/ct/alpine-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -314,7 +307,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -359,7 +351,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/archlinux-v5.sh b/ct/archlinux-v5.sh index afef7c5a..8e424a66 100644 --- a/ct/archlinux-v5.sh +++ b/ct/archlinux-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/audiobookshelf-v5.sh b/ct/audiobookshelf-v5.sh index ad90c03c..86199f22 100644 --- a/ct/audiobookshelf-v5.sh +++ b/ct/audiobookshelf-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/autobrr-v5.sh b/ct/autobrr-v5.sh index 5f3589ba..fa31ef71 100644 --- a/ct/autobrr-v5.sh +++ b/ct/autobrr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -141,7 +135,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -316,7 +309,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -372,7 +364,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/blocky-v4.sh b/ct/blocky-v4.sh deleted file mode 100644 index 507d2f71..00000000 --- a/ct/blocky-v4.sh +++ /dev/null @@ -1,327 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Blocky" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ____ __ __ - / __ )/ /___v4_____/ /____ __ - / __ / / __ \/ ___/ //_/ / / / - / /_/ / / /_/ / /__/ ,< / /_/ / -/_____/_/\____/\___/_/|_|\__, / - /____/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/blocky-v5.sh b/ct/blocky-v5.sh index 7291b0be..efe66ff7 100644 --- a/ct/blocky-v5.sh +++ b/ct/blocky-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/casaos-v4.sh b/ct/casaos-v4.sh deleted file mode 100644 index b3ae3583..00000000 --- a/ct/casaos-v4.sh +++ /dev/null @@ -1,344 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="CasaOS" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ______ ____ _____ - / ____/___ __v4______ _/ __ \/ ___/ - / / / __ `/ ___/ __ `/ / / /\__ \ -/ /___/ /_/ (__ ) /_/ / /_/ /___/ / -\____/\__,_/____/\__,_/\____//____/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "FUSE OVERLAYFS" --yesno "(ZFS) Enable Fuse Overlayfs?" 10 58); then - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}Yes${CL}" - FUSE="yes" - else - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$FUSE" == "yes" ]; then -FEATURES="fuse=1,keyctl=1,nesting=1" -else -FEATURES="keyctl=1,nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export ST=$FUSE -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -EOF -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} Setup should be reachable by going to the following URL. - ${BL}http://${IP} ${CL} \n" diff --git a/ct/casaos-v5.sh b/ct/casaos-v5.sh index 2a7e1c93..bb901bca 100644 --- a/ct/casaos-v5.sh +++ b/ct/casaos-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -144,7 +138,6 @@ function default_settings() { FUSE="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -326,7 +319,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -373,7 +365,6 @@ pushd $TEMP_DIR >/dev/null export ST=$FUSE export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/changedetection-v4.sh b/ct/changedetection-v4.sh deleted file mode 100644 index 95108992..00000000 --- a/ct/changedetection-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Change Detection" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ________ ____ __ __ _ - / ____/ /_v4____ _____ ____ ____ / __ \___ / /____ _____/ /_(_)___ ____ - / / / __ \/ __ `/ __ \/ __ `/ _ \ / / / / _ \/ __/ _ \/ ___/ __/ / __ \/ __ \ -/ /___/ / / / /_/ / / / / /_/ / __/ / /_/ / __/ /_/ __/ /__/ /_/ / /_/ / / / / -\____/_/ /_/\__,_/_/ /_/\__, /\___/ /_____/\___/\__/\___/\___/\__/_/\____/_/ /_/ - /____/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD (leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:5000${CL} \n" diff --git a/ct/changedetection-v5.sh b/ct/changedetection-v5.sh index e50e3fda..13afb78e 100644 --- a/ct/changedetection-v5.sh +++ b/ct/changedetection-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -362,7 +354,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/create_lxc.sh b/ct/create_lxc.sh index c0af30d9..f6071c13 100644 --- a/ct/create_lxc.sh +++ b/ct/create_lxc.sh @@ -36,21 +36,14 @@ if [ -z "$VALIDTMP" ]; then exit 1 fi -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function select_storage() { diff --git a/ct/cronicle-v5.sh b/ct/cronicle-v5.sh index e1e831cc..bf0495e1 100644 --- a/ct/cronicle-v5.sh +++ b/ct/cronicle-v5.sh @@ -33,20 +33,14 @@ HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" hostname="$(hostname)" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -140,7 +134,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -315,7 +308,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -410,7 +402,6 @@ pushd $TEMP_DIR >/dev/null export SERV=$SERVER export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/daemonsync-v4.sh b/ct/daemonsync-v4.sh deleted file mode 100644 index faaf9a81..00000000 --- a/ct/daemonsync-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Daemon Sync" -var_disk="8" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - ____ _____ - / __ \____ ____ ____ ___ ____ ____ / ___/__ ______ _____ - / / / / __ / _ \/ __ __ \/ __ \/ __ \ \__ \/ / / / __ \/ ___/ - / /_/ / /_/ / __/ / / / / / /_/ / / / / ___/ / /_/ / / / / /__ -/_____/\__,_/\___/_/ /_/ /_/\____/_/ /_/ v4/____/\__, /_/ /_/\___/ - /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8084${CL} \n" diff --git a/ct/daemonsync-v5.sh b/ct/daemonsync-v5.sh index c79e3cac..401086bb 100644 --- a/ct/daemonsync-v5.sh +++ b/ct/daemonsync-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/dashy-v4.sh b/ct/dashy-v4.sh deleted file mode 100644 index f128a191..00000000 --- a/ct/dashy-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Dashy" -var_disk="3" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ____ __ - / __ \____ ______/ /_ __ __ - / / / / __ / ___/ __ \/ / / / - / /_/ / /_/ (__ ) / / / /_/ / -/_____/\__,_/____/_/ /_/\__, / - v4 /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:4000${CL} \n" diff --git a/ct/dashy-v5.sh b/ct/dashy-v5.sh index d3ed0919..069b8ee1 100644 --- a/ct/dashy-v5.sh +++ b/ct/dashy-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -389,7 +381,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/debian-v4.sh b/ct/debian-v4.sh deleted file mode 100644 index 441ebe05..00000000 --- a/ct/debian-v4.sh +++ /dev/null @@ -1,326 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Debian" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ____ __________ _______ _ __ - / __ \/ ____/ __ )/ _/ | / | / / - / / / / __/ / __ |/ // /| | / |/ / - / /_/ / /_v4/ /_/ // // ___ |/ /| / -/_____/_____/_____/___/_/ |_/_/ |_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD (leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} ${var_version} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/debian-v5.sh b/ct/debian-v5.sh index 9f007fb1..9fae150f 100644 --- a/ct/debian-v5.sh +++ b/ct/debian-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/deconz-v4.sh b/ct/deconz-v4.sh deleted file mode 100644 index 87a41090..00000000 --- a/ct/deconz-v4.sh +++ /dev/null @@ -1,343 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="deCONZ" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="ubuntu" -var_version="20.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - __ __________ _ _______ - ____/ /v4 / ____/ __ \/ | / /__ / - / __ / _ \/ / / / / / |/ / / / -/ /_/ / __/ /___/ /_/ / /| / / /__ -\__,_/\___/\____/\____/_/ |_/ /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}${CL}\n" diff --git a/ct/deconz-v5.sh b/ct/deconz-v5.sh index f99fffb4..8368ce39 100644 --- a/ct/deconz-v5.sh +++ b/ct/deconz-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -317,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/deluge-v5.sh b/ct/deluge-v5.sh index f6124413..93fde875 100644 --- a/ct/deluge-v5.sh +++ b/ct/deluge-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -139,7 +133,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -314,7 +307,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -359,7 +351,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/docker-v4.sh b/ct/docker-v4.sh deleted file mode 100644 index d3a6ee55..00000000 --- a/ct/docker-v4.sh +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Docker" -var_disk="4" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - ____ __ - / __ \____ _____/ /_v4__ _____ - / / / / __ \/ ___/ //_/ _ \/ ___/ - / /_/ / /_/ / /__/ ,< / __/ / -/_____/\____/\___/_/|_|\___/_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "FUSE OVERLAYFS" --yesno "(ZFS) Enable Fuse Overlayfs?" 10 58); then - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}Yes${CL}" - FUSE="yes" - else - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$FUSE" == "yes" ]; then -FEATURES="fuse=1,keyctl=1,nesting=1" -else -FEATURES="keyctl=1,nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export ST=$FUSE -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -EOF -if [ "$CT_TYPE" == "0" ]; then -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/docker-v5.sh b/ct/docker-v5.sh index d2e3c0a7..5d4b2eb2 100644 --- a/ct/docker-v5.sh +++ b/ct/docker-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { FUSE="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -325,7 +318,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -370,7 +362,6 @@ pushd $TEMP_DIR >/dev/null export ST=$FUSE export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/emby-v4.sh b/ct/emby-v4.sh deleted file mode 100644 index 4935a5c9..00000000 --- a/ct/emby-v4.sh +++ /dev/null @@ -1,350 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Emby" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="ubuntu" -var_version="20.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${DGN} - ______ __ - / ____/___ v4_ / /_ __ __ - / __/ / __ __ \/ __ \/ / / / - / /___/ / / / / / /_/ / /_/ / -/_____/_/ /_/ /_/_.___/\__, / - /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - var_version=$(whiptail --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ - "18.04" "Bionic" OFF \ - "20.04" "Focal" ON \ - "22.04" "Jammy" OFF \ - "22.10" "Kinetic" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Ubuntu Version: ${BGN}$var_version${CL}"; fi - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: c 226:0 rwm -lxc.cgroup2.devices.allow: c 226:128 rwm -lxc.cgroup2.devices.allow: c 29:0 rwm -lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file -lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir -lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8096${CL}\n" diff --git a/ct/emby-v5.sh b/ct/emby-v5.sh index 7392ac61..fb1392ac 100644 --- a/ct/emby-v5.sh +++ b/ct/emby-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -326,7 +319,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -382,7 +374,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/emqx-v4.sh b/ct/emqx-v4.sh deleted file mode 100644 index 032b2ec9..00000000 --- a/ct/emqx-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="EMQX" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ________ _______v4 _ __ - / ____/ |/ / __ \ | |/ / - / __/ / /|_/ / / / / | / - / /___/ / / / /_/ / / | -/_____/_/ /_/\___\_\/_/|_| - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} Setup should be reachable by going to the following URL. - ${BL}http://${IP}:18083${CL} \n" diff --git a/ct/emqx-v5.sh b/ct/emqx-v5.sh index 26360cbc..5f0aaa9a 100644 --- a/ct/emqx-v5.sh +++ b/ct/emqx-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -362,7 +354,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/esphome-v4.sh b/ct/esphome-v4.sh deleted file mode 100644 index dc4fe5bf..00000000 --- a/ct/esphome-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="ESPHome" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${CL} - ___________ ____ __ ______ __ _________ - / ____/ ___// __ \/ / / / __ \/ |/ / ____/ - / __/ \__ \/ /_/ / /_/ / / / / /|_/ / __/ - / /___ ___/ / ____/ __ / /_/ / / / / /_v4 -/_____//____/_/ /_/ /_/\____/_/ /_/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:6052${CL} \n" diff --git a/ct/esphome-v5.sh b/ct/esphome-v5.sh index 6ec4e410..b0a51c9c 100644 --- a/ct/esphome-v5.sh +++ b/ct/esphome-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -369,7 +361,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/grafana-v4.sh b/ct/grafana-v4.sh deleted file mode 100644 index f89a2857..00000000 --- a/ct/grafana-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Grafana" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - ______ ____ - / ____/________ _/ __/___ _____ ____ _ - / / __/ ___/ __ / /_/ __ / __ \/ __ / -/ /_/ / / / /_/ / __/ /_/ / / / / /_/ / -\____/_/ v4\__,_/_/ \__,_/_/ /_/\__,_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:3000${CL} \n" diff --git a/ct/grafana-v5.sh b/ct/grafana-v5.sh index 85e1b111..38514eed 100644 --- a/ct/grafana-v5.sh +++ b/ct/grafana-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/grocy-v4.sh b/ct/grocy-v4.sh deleted file mode 100644 index e355e177..00000000 --- a/ct/grocy-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="grocy" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - ____ __________ _______ __ - / __ / ___/ __ \/ ___/ / / / - / /_/ / / / /_/ / /__/ /_/ / - \__, /_/ \____/\___/\__, / -/____/ v4 /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}${CL} \n" diff --git a/ct/grocy-v5.sh b/ct/grocy-v5.sh index 62441b72..64a58fe6 100644 --- a/ct/grocy-v5.sh +++ b/ct/grocy-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -362,7 +354,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/heimdalldashboard-v4.sh b/ct/heimdalldashboard-v4.sh deleted file mode 100644 index f39c042f..00000000 --- a/ct/heimdalldashboard-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Heimdall Dashboard" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ __ _ __ ____ ____ __ __ __ - / / / /__ (_)___ ___ ____/ /_v4 _/ / / / __ \____ ______/ /_ / /_ ____ ____ __________/ / - / /_/ / _ \/ / __ __ \/ __ / __ / / / / / / / __ / ___/ __ \/ __ \/ __ \/ __ / ___/ __ / - / __ / __/ / / / / / / /_/ / /_/ / / / / /_/ / /_/ (__ ) / / / /_/ / /_/ / /_/ / / / /_/ / -/_/ /_/\___/_/_/ /_/ /_/\__,_/\__,_/_/_/ /_____/\__,_/____/_/ /_/_.___/\____/\__,_/_/ \__,_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:7990${CL} \n" diff --git a/ct/heimdalldashboard-v5.sh b/ct/heimdalldashboard-v5.sh index 00dddee1..4dcc78d0 100644 --- a/ct/heimdalldashboard-v5.sh +++ b/ct/heimdalldashboard-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -442,7 +434,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/homeassistant-core-v4.sh b/ct/homeassistant-core-v4.sh deleted file mode 100644 index ae1cd2c7..00000000 --- a/ct/homeassistant-core-v4.sh +++ /dev/null @@ -1,343 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Home Assistant-Core" -var_disk="8" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _ _ _ _ ___ - /\ /\___ _ __ ___ ___ /_\ ___ ___(_)___| |_ __ _ _ __ | |_ / __\___v4_ __ ___ - / /_/ / _ \| '_ ` _ \ / _ \ //_\\/ __/ __| / __| __/ _` | '_ \| __| / / / _ \| '__/ _ \ -/ __ / (_) | | | | | | __/ / _ \__ \__ \ \__ \ || (_| | | | | |_ / /__| (_) | | | __/ -\/ /_/ \___/|_| |_| |_|\___| \_/ \_/___/___/_|___/\__\__,_|_| |_|\__| \____/\___/|_| \___| - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable (after it's initialized) by going to the following URL. - ${BL}http://${IP}:8123${CL}" diff --git a/ct/homeassistant-core-v5.sh b/ct/homeassistant-core-v5.sh index 1d67e929..769a6f1a 100644 --- a/ct/homeassistant-core-v5.sh +++ b/ct/homeassistant-core-v5.sh @@ -34,21 +34,14 @@ CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" STABLE=$(curl -s https://raw.githubusercontent.com/home-assistant/version/master/stable.json | grep "default" | awk '{print substr($2, 2, length($2)-3) }') BETA=$(curl -s https://raw.githubusercontent.com/home-assistant/version/master/beta.json | grep "default" | awk '{print substr($2, 2, length($2)-3) }') -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -144,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } @@ -320,7 +312,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -438,7 +429,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/homeassistant-v4.sh b/ct/homeassistant-v4.sh deleted file mode 100644 index 1407f92c..00000000 --- a/ct/homeassistant-v4.sh +++ /dev/null @@ -1,357 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Home Assistant" -var_disk="16" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ __ ___ _ __ __ - / / / /___ ____ ___ ___ v4 / | __________(_)____/ /_____ _____ / /_ - / /_/ / __ \/ __ __ \/ _ \ / /| | / ___/ ___/ / ___/ __/ __ / __ \/ __/ - / __ / /_/ / / / / / / __/ / ___ |(__ |__ ) (__ ) /_/ /_/ / / / / /_ -/_/ /_/\____/_/ /_/ /_/\___/ /_/ |_/____/____/_/____/\__/\__,_/_/ /_/\__/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "FUSE OVERLAYFS" --yesno "(ZFS) Enable Fuse Overlayfs?" 10 58); then - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}Yes${CL}" - FUSE="yes" - else - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$FUSE" == "yes" ]; then -FEATURES="fuse=1,keyctl=1,nesting=1" -else -FEATURES="keyctl=1,nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export ST=$FUSE -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -EOF -if [ "$CT_TYPE" == "0" ]; then -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8123${CL} -Portainer should be reachable by going to the following URL. - ${BL}http://${IP}:9000${CL}\n" diff --git a/ct/homeassistant-v5.sh b/ct/homeassistant-v5.sh index afaa19eb..49de18fd 100644 --- a/ct/homeassistant-v5.sh +++ b/ct/homeassistant-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -145,7 +139,6 @@ function default_settings() { FUSE="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } @@ -328,7 +321,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -438,7 +430,6 @@ pushd $TEMP_DIR >/dev/null export ST=$FUSE export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/homebridge-v4.sh b/ct/homebridge-v4.sh deleted file mode 100644 index 5aa8300e..00000000 --- a/ct/homebridge-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Homebridge" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - __ ______ __ _____________ ____ ________ ____________ - / / / / __ \/ |/ / ____/ __ )/ __ \/ _/ __ \/ ____/ ____/ - / /_/ / / / / /|_/ / __/ / __ / /_/ // // / / / / __/ __/ - / __ / /_/ / / / / /___/ /_/ / _, _// // /_/ / /_/ / /___ -/_/ /_/\____/_/v4/_/_____/_____/_/ |_/___/_____/\____/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8581${CL} \n" diff --git a/ct/homebridge-v5.sh b/ct/homebridge-v5.sh index d036f6ed..95297599 100644 --- a/ct/homebridge-v5.sh +++ b/ct/homebridge-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/homepage-v4.sh b/ct/homepage-v4.sh deleted file mode 100644 index 07eea829..00000000 --- a/ct/homepage-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Homepage" -var_disk="3" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - __ __ - / / / /___ ____ ___ ___ ____ ____ _____ ____ - / /_/ / __ \/ __ `__ \/ _ \/ __ \/ __ `/ __ `/ _ \ - / __ / /_/ / / / / / / __/ /_/ / /_/ / /_/ / __/ -/_/ /_/\____/_/ /_/ /_/\___/ .___/\__,_/\__, /\___/ - /_/ v4 /____/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} Setup should be reachable by going to the following URL. - ${BL}http://${IP}:3000${CL} \n" diff --git a/ct/homepage-v5.sh b/ct/homepage-v5.sh index 413bcb9a..555343bc 100644 --- a/ct/homepage-v5.sh +++ b/ct/homepage-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -369,7 +361,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/homer-v5.sh b/ct/homer-v5.sh index fcb920b0..494b0b7c 100644 --- a/ct/homer-v5.sh +++ b/ct/homer-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -382,7 +374,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/hyperion-v4.sh b/ct/hyperion-v4.sh deleted file mode 100644 index 2b0fc124..00000000 --- a/ct/hyperion-v4.sh +++ /dev/null @@ -1,344 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Hyperion" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { -cat <<"EOF" - __ __ _ - / / / /_ ______v4___ _____(_)___ ____ - / /_/ / / / / __ \/ _ \/ ___/ / __ \/ __ \ - / __ / /_/ / /_/ / __/ / / / /_/ / / / / -/_/ /_/\__, / .___/\___/_/ /_/\____/_/ /_/ - /____/_/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD (leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8090${CL} \n" diff --git a/ct/hyperion-v5.sh b/ct/hyperion-v5.sh index 51353a73..2ae540da 100644 --- a/ct/hyperion-v5.sh +++ b/ct/hyperion-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/influxdb-v4.sh b/ct/influxdb-v4.sh deleted file mode 100644 index 6ee8e824..00000000 --- a/ct/influxdb-v4.sh +++ /dev/null @@ -1,326 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="InfluxDB" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - ____ ______ ____ ____ - / _/_v4 / __/ /_ ___ __/ __ \/ __ ) - / // __ \/ /_/ / / / / |/_/ / / / __ | - _/ // / / / __/ / /_/ /> &1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/influxdb-v5.sh b/ct/influxdb-v5.sh index 03681cb6..053feb3e 100644 --- a/ct/influxdb-v5.sh +++ b/ct/influxdb-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/iobroker-v4.sh b/ct/iobroker-v4.sh deleted file mode 100644 index b4515677..00000000 --- a/ct/iobroker-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="ioBroker" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - _ ____ __ - (_)___ / __ )_________ / /_____ _____ - / / __ \/ __ / ___/ __ \/ //_/ _ \/ ___/ - / / /_/ / /_/ / / / /_/ / ,< / __/ / -/_/\____/_____/_/ v4\____/_/|_|\___/_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8081${CL} \n" diff --git a/ct/iobroker-v5.sh b/ct/iobroker-v5.sh index 257ae0bd..6d022ee3 100644 --- a/ct/iobroker-v5.sh +++ b/ct/iobroker-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/jellyfin-v4.sh b/ct/jellyfin-v4.sh deleted file mode 100644 index 774a3738..00000000 --- a/ct/jellyfin-v4.sh +++ /dev/null @@ -1,350 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Jellyfin" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="ubuntu" -var_version="20.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${DGN} - __________ ____ _____________ __ - / / ____/ / / /\ \/ / ____/ _/ | / / - __ / / __/ / / / / \ / /_ / // |/ / -/ /_/ / /___/ /___/ /_v4/ / __/ _/ // /| / -\____/_____/_____/_____/_/_/ /___/_/ |_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - var_version=$(whiptail --title "UBUNTU VERSION" --radiolist "Choose Version" 11 58 4 \ - "18.04" "Bionic" OFF \ - "20.04" "Focal" ON \ - "22.04" "Jammy" OFF \ - "22.10" "Kinetic" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Ubuntu Version: ${BGN}$var_version${CL}"; fi - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: c 226:0 rwm -lxc.cgroup2.devices.allow: c 226:128 rwm -lxc.cgroup2.devices.allow: c 29:0 rwm -lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file -lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir -lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8096${CL}\n" diff --git a/ct/jellyfin-v5.sh b/ct/jellyfin-v5.sh index 127dcd25..ec315a7c 100644 --- a/ct/jellyfin-v5.sh +++ b/ct/jellyfin-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -145,7 +139,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -328,7 +321,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -372,7 +364,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/k0s-v5.sh b/ct/k0s-v5.sh index bcf5f0ee..6a4281a7 100644 --- a/ct/k0s-v5.sh +++ b/ct/k0s-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/kavita-v5.sh b/ct/kavita-v5.sh index d0d21213..0267f0a9 100644 --- a/ct/kavita-v5.sh +++ b/ct/kavita-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -141,7 +135,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -316,7 +309,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -361,7 +353,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/keycloak-v4.sh b/ct/keycloak-v4.sh deleted file mode 100644 index 5237a3ed..00000000 --- a/ct/keycloak-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Keycloak" -var_disk="4" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - __ __ __ __ - / //_/__ __ _______/ /___ ____ _/ /__ - / ,< / _ \/ / / / ___/ / __ \/ __ / //_/ - / /| / __/ /_/ / /__/ / /_/ / /_/ / ,< -/_/ |_\___/\__, /\___/_/\____/\__,_/_/|_| - v4 /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8080${CL} \n" diff --git a/ct/keycloak-v5.sh b/ct/keycloak-v5.sh index 2d9e16fe..85b170e2 100644 --- a/ct/keycloak-v5.sh +++ b/ct/keycloak-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/lidarr-v5.sh b/ct/lidarr-v5.sh index 07586f05..1a11e0d7 100644 --- a/ct/lidarr-v5.sh +++ b/ct/lidarr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/magicmirror-v4.sh b/ct/magicmirror-v4.sh deleted file mode 100644 index 2342d731..00000000 --- a/ct/magicmirror-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="MagicMirror" -var_disk="3" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ ___ _ __ ____ - / |/ /___ _____ _(_)____/ |/ (_)_____________ _____ - / /|_/ / __ / __ / / ___/ /|_/ / / ___/ ___/ __ \/ ___/ - / / / / /_/ / /_/ / / /__/ / / / / / / / / /_/ / / -/_/ /_/\__,_/\__, /_/\___/_/ /_/_/_/ /_/ \____/_/ - /____/ v4 -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8080${CL} \n" diff --git a/ct/magicmirror-v5.sh b/ct/magicmirror-v5.sh index 9a738bcf..8fb8eef7 100644 --- a/ct/magicmirror-v5.sh +++ b/ct/magicmirror-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -365,7 +357,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/mariadb-v4.sh b/ct/mariadb-v4.sh deleted file mode 100644 index 5281c61d..00000000 --- a/ct/mariadb-v4.sh +++ /dev/null @@ -1,326 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="MariaDB" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ ___ _ ____ ____ - / |/ /___ ______(_)___ _/ __ \/ __ ) - / /|_/ / __ / ___/ / __ / / / / __ | - / / / / /_/ / / / / /_/ / /_/ / /_/ / -/_/ /_/\__,_/_/v4/_/\__,_/_____/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/mariadb-v5.sh b/ct/mariadb-v5.sh index 96fdb8e1..3ad4ae5a 100644 --- a/ct/mariadb-v5.sh +++ b/ct/mariadb-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/meshcentral-v4.sh b/ct/meshcentral-v4.sh deleted file mode 100644 index b1a2b983..00000000 --- a/ct/meshcentral-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="MeshCentral" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ ___ __ ______ __ __ - / |/ /__ _____/ /_ / ____/__ ____ / /__________ _/ / - / /|_/ / _ \/ ___/ __ \/ / / _ \/ __ \/ __/ ___/ __ / / - / / / / __(__ ) / / / /___/ __/ / / / /_/ / / /_/ / / -/_/ /_/\___/____/_/ /_/\____/\___/_/ /_/\__/_/ v4\__,_/_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}${CL} \n" diff --git a/ct/meshcentral-v5.sh b/ct/meshcentral-v5.sh index 37d26f3f..825c5a55 100644 --- a/ct/meshcentral-v5.sh +++ b/ct/meshcentral-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/motioneye-v4.sh b/ct/motioneye-v4.sh deleted file mode 100644 index f2101198..00000000 --- a/ct/motioneye-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Motioneye" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ ___ __ _ ________ ________ - / |/ /___ / /_(_)___ ____ / ____/\ \/ / ____/ - / /|_/ / __ \/ __/ / __ \/ __ \/ __/ \ / __/ - / / / / /_/ / /_/ / /_/ / / / / /___v4 / / /___ -/_/ /_/\____/\__/_/\____/_/ /_/_____/ /_/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8765${CL} \n" diff --git a/ct/motioneye-v5.sh b/ct/motioneye-v5.sh index f5b6186d..4d8d82a2 100644 --- a/ct/motioneye-v5.sh +++ b/ct/motioneye-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -362,7 +354,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/mqtt-v4.sh b/ct/mqtt-v4.sh deleted file mode 100644 index 16d80e43..00000000 --- a/ct/mqtt-v4.sh +++ /dev/null @@ -1,293 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="MQTT" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=`echo "\033[33m"` -BL=`echo "\033[36m"` -RD=`echo "\033[01;31m"` -BGN=`echo "\033[4;92m"` -GN=`echo "\033[1;92m"` -DGN=`echo "\033[32m"` -CL=`echo "\033[m"` -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { -echo -e "${GN} - __ _______ ____________ - / |/ / __ \/_ __/_ __/ - / /|_/ / / / / / / / / - / / / / /_/ / / / / / -/_/ /_/\___\_\/_/ v4/_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) -if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit -fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { -CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ -"1" "Unprivileged" ON \ -"0" "Privileged" OFF \ -3>&1 1>&2 2>&3) -exitstatus=$? -if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" -fi -PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then PW1="Automatic Login" PW=" "; - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" -else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi -fi -CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $CT_ID ]; then CT_ID="$NEXTID"; echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"; -else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi; -fi -CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $CT_NAME ]; then HN="$NSAPP"; echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"; -else - if [ $exitstatus = 0 ]; then HN=$(echo ${CT_NAME,,} | tr -d ' '); echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"; fi; -fi -DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $DISK_SIZE ]; then DISK_SIZE="$var_disk"; echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; -else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi; - if ! [[ $DISK_SIZE =~ $INTEGER ]] ; then echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}"; advanced_settings; fi; -fi -CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $CORE_COUNT ]; then CORE_COUNT="$var_cpu"; echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; -else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi; -fi -RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $RAM_SIZE ]; then RAM_SIZE="$var_ram"; echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; -else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi; -fi -BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $BRG ]; then BRG="vmbr0"; echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; -else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi; -fi -NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ -z $NET ]; then NET="dhcp"; echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; -else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi; -fi -GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then GATE1="Default" GATE=""; - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" -else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi -fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi -MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then MAC1="Default" MAC=""; - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" -else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi -fi -VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) -exitstatus=$? -if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then VLAN1="Default" VLAN=""; - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" -else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi -fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi -if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" -else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings -fi -} -function start_script() { -if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings -else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings -fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/mqtt-v5.sh b/ct/mqtt-v5.sh index 8cc7274e..5a4e9351 100644 --- a/ct/mqtt-v5.sh +++ b/ct/mqtt-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -140,7 +134,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -315,7 +308,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/n8n-v4.sh b/ct/n8n-v4.sh deleted file mode 100644 index 58af3ddb..00000000 --- a/ct/n8n-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="n8n" -var_disk="3" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ___ - / _ \ - _ __ | (_) |_v4_ - | _ \ > _ <| _ \ - | | | | (_) | | | | - |_| |_|\___/|_| |_| -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:5678${CL} \n" diff --git a/ct/n8n-v5.sh b/ct/n8n-v5.sh index c4a371af..a1fa02ad 100644 --- a/ct/n8n-v5.sh +++ b/ct/n8n-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/navidrome-v4.sh b/ct/navidrome-v4.sh deleted file mode 100644 index 3f188aa6..00000000 --- a/ct/navidrome-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Navidrome" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _ __ _ __ - / | / /___ __ v4__(_)___/ /________ ____ ___ ___ - / |/ / __ / | / / / __ / ___/ __ \/ __ __ \/ _ \ - / /| / /_/ /| |/ / / /_/ / / / /_/ / / / / / / __/ -/_/ |_/\__,_/ |___/_/\__,_/_/ \____/_/ /_/ /_/\___/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:4533${CL} \n" diff --git a/ct/navidrome-v5.sh b/ct/navidrome-v5.sh index 06f2a828..1f38d743 100644 --- a/ct/navidrome-v5.sh +++ b/ct/navidrome-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -374,7 +366,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/nextcloudpi-v4.sh b/ct/nextcloudpi-v4.sh deleted file mode 100644 index c1ff886d..00000000 --- a/ct/nextcloudpi-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="NextCloudPi" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _ __ __ ________ ______ _ - / | / /__ _ __/ /_/ ____/ /___ __v4______/ / __ \(_) - / |/ / _ \| |/_/ __/ / / / __ \/ / / / __ / /_/ / / - / /| / __/> &1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} Setup should be reachable by going to the following URL. - ${BL}https://${IP}/${CL} \n" diff --git a/ct/nextcloudpi-v5.sh b/ct/nextcloudpi-v5.sh index af9a035b..e77c3b4a 100644 --- a/ct/nextcloudpi-v5.sh +++ b/ct/nextcloudpi-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/nginx-proxy-manager-v4.sh b/ct/nginx-proxy-manager-v4.sh deleted file mode 100644 index 23e60e9c..00000000 --- a/ct/nginx-proxy-manager-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Nginx Proxy Manager" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - _ __ _ ____ __ ___ - / | / /___ _(_)___ _ __ / __ \_________ _ ____ __ / |/ /___ _____ ____ _____ ____ _____ - / |/ / __ / / __ \| |/_/ / /_/ / ___/ __ \| |/_/ / / / / /|_/ / __ / __ \/ __ / __ / _ \/ ___/ - / /| / /_/ / / / / /> < / ____/ / / /_/ /> &1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/nginx-proxy-manager-install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:81${CL} \n" diff --git a/ct/nginxproxymanager-v5.sh b/ct/nginxproxymanager-v5.sh index 41cf41a8..237ee263 100644 --- a/ct/nginxproxymanager-v5.sh +++ b/ct/nginxproxymanager-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -472,7 +464,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/nocodb-v4.sh b/ct/nocodb-v4.sh deleted file mode 100644 index 80776771..00000000 --- a/ct/nocodb-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="NocoDB" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - _ __ ____ ____ - / | / /___ ____v4___ / __ \/ __ ) - / |/ / __ \/ ___/ __ \/ / / / __ | - / /| / /_/ / /__/ /_/ / /_/ / /_/ / -/_/ |_/\____/\___/\____/_____/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8080/dashboard${CL} \n" diff --git a/ct/nocodb-v5.sh b/ct/nocodb-v5.sh index d552dd84..e06cdc12 100644 --- a/ct/nocodb-v5.sh +++ b/ct/nocodb-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -366,7 +358,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/node-red-v4.sh b/ct/node-red-v4.sh deleted file mode 100644 index 24568629..00000000 --- a/ct/node-red-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Node-Red" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - _ __ __ ____ __ - / | / /___ ____/ /__ v4 / __ \___ ____/ / - / |/ / __ \/ __ / _ \ / /_/ / _ \/ __ / - / /| / /_/ / /_/ / __/ / _, _/ __/ /_/ / -/_/ |_/\____/\__,_/\___/ /_/ |_|\___/\__,_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:1880${CL} \n" diff --git a/ct/node-red-v5.sh b/ct/node-red-v5.sh index d6239acc..cc5720ed 100644 --- a/ct/node-red-v5.sh +++ b/ct/node-red-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -399,7 +391,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/omada-v4.sh b/ct/omada-v4.sh deleted file mode 100644 index 70fbbe6a..00000000 --- a/ct/omada-v4.sh +++ /dev/null @@ -1,337 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Omada" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="ubuntu" -var_version="20.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - ____ __ - / __ \____ ___v4____ _____/ /___ _ - / / / / __ __ \/ __ / __ / __ / -/ /_/ / / / / / / /_/ / /_/ / /_/ / -\____/_/ /_/ /_/\__,_/\__,_/\__,_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - var_version=$(whiptail --title "UBUNTU VERSION" --radiolist "Choose Version" 11 58 4 \ - "18.04" "Bionic" OFF \ - "20.04" "Focal" ON \ - "22.04" "Jammy" OFF \ - "22.10" "Kinetic" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Ubuntu Version: ${BGN}$var_version${CL}"; fi - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}https://${IP}:8043${CL} \n" diff --git a/ct/omada-v5.sh b/ct/omada-v5.sh index c200d3fd..35861b21 100644 --- a/ct/omada-v5.sh +++ b/ct/omada-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -326,7 +319,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -361,7 +353,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/omv-v4.sh b/ct/omv-v4.sh deleted file mode 100644 index 573745c9..00000000 --- a/ct/omv-v4.sh +++ /dev/null @@ -1,339 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="OMV" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ____ __ ___ ___ _ __ ____ - / __ \____v4___ ____ / |/ /__ ____/ (_)___ | | / /___ ___ __/ / /_ - / / / / __ \/ _ \/ __ \/ /|_/ / _ \/ __ / / __ `/ | / / __ `/ / / / / __/ -/ /_/ / /_/ / __/ / / / / / / __/ /_/ / / /_/ /| |/ / /_/ / /_/ / / /_ -\____/ .___/\___/_/ /_/_/ /_/\___/\__,_/_/\__,_/ |___/\__,_/\__,_/_/\__/ - /_/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -EOF -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}${CL} \n" diff --git a/ct/omv-v5.sh b/ct/omv-v5.sh index 8591a72e..8406e00a 100644 --- a/ct/omv-v5.sh +++ b/ct/omv-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/openhab-v4.sh b/ct/openhab-v4.sh deleted file mode 100644 index 2d014284..00000000 --- a/ct/openhab-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="openHAB" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - __ _____ ____ - ____v4____ ___ ____ / / / / | / __ ) - / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __ | -/ /_/ / /_/ / __/ / / / __ / ___ |/ /_/ / -\____/ .___/\___/_/ /_/_/ /_/_/ |_/_____/ - /_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8080${CL} \n" diff --git a/ct/openhab-v5.sh b/ct/openhab-v5.sh index 837f815c..a1d4a601 100644 --- a/ct/openhab-v5.sh +++ b/ct/openhab-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/paperless-ngx-v4.sh b/ct/paperless-ngx-v4.sh deleted file mode 100644 index 1630ed49..00000000 --- a/ct/paperless-ngx-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Paperless-ngx" -var_disk="4" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ____ __ - / __ \____ _____ ___ _____/ /__v4__________ ____ ____ __ __ - / /_/ / __ `/ __ \/ _ \/ ___/ / _ \/ ___/ ___/___/ __ \/ __ `/ |/_/ - / ____/ /_/ / /_/ / __/ / / / __(__ |__ )___/ / / / /_/ /> < -/_/ \__,_/ .___/\___/_/ /_/\___/____/____/ /_/ /_/\__, /_/|_| - /_/ /____/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8000${CL} \n" diff --git a/ct/paperless-ngx-v5.sh b/ct/paperless-ngx-v5.sh index b4de9ab6..d014671b 100644 --- a/ct/paperless-ngx-v5.sh +++ b/ct/paperless-ngx-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -431,7 +423,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/photoprism-v4.sh b/ct/photoprism-v4.sh deleted file mode 100644 index 1574037c..00000000 --- a/ct/photoprism-v4.sh +++ /dev/null @@ -1,331 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="PhotoPrism" -var_disk="8" -var_cpu="2" -var_ram="3072" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ____ __ ______ __________ ____ ____ _________ __ ___ - / __ \/ / / / __ \/_ __/ __ \/ __ \/ __ \/ _/ ___// |/ / - / /_/ / /_/ / / / / / / / / / / /_/ / /_/ // / \__ \/ /|_/ / - / ____/ __ / /_/ / / / / /_/ / ____/ _, _// / v4_/ / / / / -/_/ /_/ /_/\____/ /_/ \____/_/ /_/ |_/___//____/_/ /_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_info "Setting Container to Normal Resources" -pct set $CTID -memory 2048 -msg_ok "Set Container to Normal Resources" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:2342${CL} \n" diff --git a/ct/photoprism-v5.sh b/ct/photoprism-v5.sh index ccab7aad..2c7042d6 100644 --- a/ct/photoprism-v5.sh +++ b/ct/photoprism-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -141,7 +135,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -316,7 +309,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -384,7 +376,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/pihole-v4.sh b/ct/pihole-v4.sh deleted file mode 100644 index 891d272e..00000000 --- a/ct/pihole-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Pihole" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ____ ____ __ ______ __ ______ - / __ \/ _/ / / / / __ \/ / / ____/ - / /_/ // /___/ /_/ / / / / / / __/ - / ____// /___/ __ / /_/ / /v4_/ /___ -/_/ /___/ /_/ /_/\____/_____/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}/admin${CL} \n" diff --git a/ct/pihole-v5.sh b/ct/pihole-v5.sh index 299c53d0..989bd0de 100644 --- a/ct/pihole-v5.sh +++ b/ct/pihole-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/plex-v4.sh b/ct/plex-v4.sh deleted file mode 100644 index ba26e011..00000000 --- a/ct/plex-v4.sh +++ /dev/null @@ -1,350 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Plex" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="ubuntu" -var_version="20.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - ____ __ - / __ \/ /__ _ __ - / /_/ / / _ \| |/_/ - / ____/ / __/> < -/_/v4 /_/\___/_/|_| -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - var_version=$(whiptail --title "UBUNTU VERSION" --radiolist "Choose Version" 11 58 4 \ - "18.04" "Bionic" OFF \ - "20.04" "Focal" ON \ - "22.04" "Jammy" OFF \ - "22.10" "Kinetic" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Ubuntu Version: ${BGN}$var_version${CL}"; fi - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: c 226:0 rwm -lxc.cgroup2.devices.allow: c 226:128 rwm -lxc.cgroup2.devices.allow: c 29:0 rwm -lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file -lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir -lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:32400/web${CL}\n" diff --git a/ct/plex-v5.sh b/ct/plex-v5.sh index 30894617..f7dc89a0 100644 --- a/ct/plex-v5.sh +++ b/ct/plex-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -144,7 +138,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -327,7 +320,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -382,7 +374,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/podman-homeassistant-v4.sh b/ct/podman-homeassistant-v4.sh deleted file mode 100644 index 5887d22a..00000000 --- a/ct/podman-homeassistant-v4.sh +++ /dev/null @@ -1,354 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Podman-Home Assistant" -var_disk="16" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - ____ __ - / __ \____ ____/ /___ ___ ____ _____ - v4 / /_/ / __ \/ __ / __ __ \/ __ / __ \ - / ____/ /_/ / /_/ / / / / / / /_/ / / / / - __ __ /_/ \____/\__,_/_/ /_/ /_/\__,_/_/ /_/__ __ - / / / /___ ____ ___ ___ / | __________(_)____/ /_____ _____ / /_ - / /_/ / __ \/ __ __ \/ _ \ / /| | / ___/ ___/ / ___/ __/ __ / __ \/ __/ - / __ / /_/ / / / / / / __/ / ___ |(__ |__ ) (__ ) /_/ /_/ / / / / /_ -/_/ /_/\____/_/ /_/ /_/\___/ /_/ |_/____/____/_/____/\__/\__,_/_/ /_/\__/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit - -if [ "$CT_TYPE" == "0" ]; then -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -else - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8123${CL} -Yacht should be reachable by going to the following URL. - ${BL}http://${IP}:8000${CL}\n" diff --git a/ct/podman-homeassistant-v5.sh b/ct/podman-homeassistant-v5.sh index 55f0f9c5..711ae8f8 100644 --- a/ct/podman-homeassistant-v5.sh +++ b/ct/podman-homeassistant-v5.sh @@ -36,20 +36,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -146,7 +140,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -321,7 +314,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -413,7 +405,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/podman-v5.sh b/ct/podman-v5.sh index c4475f01..325d7268 100644 --- a/ct/podman-v5.sh +++ b/ct/podman-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/postgresql-v4.sh b/ct/postgresql-v4.sh deleted file mode 100644 index d1013485..00000000 --- a/ct/postgresql-v4.sh +++ /dev/null @@ -1,327 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="PostgreSQL" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - ____ __ _____ ____ __ - / __ \____ _____/ /_____ _________ / ___// __ \ / / - / /_/ / __ \/ ___/ __/ __ / ___/ _ \\__ \/ / / / / / - / ____/ /_/ (__ ) /_/ /_/ / / / __/__/ / /_/ / / /___ -/_/ \____/____/\__/\__, /_/v4 \___/____/\___\_\/_____/ - /____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/postgresql-v5.sh b/ct/postgresql-v5.sh index e1247142..3a00762f 100644 --- a/ct/postgresql-v5.sh +++ b/ct/postgresql-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/prometheus-v4.sh b/ct/prometheus-v4.sh deleted file mode 100644 index a4106946..00000000 --- a/ct/prometheus-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Prometheus" -var_disk="4" -var_cpu="1" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ____ __ __ - / __ \_________ ____ ___ ___ / /_/ /_ ___ __ _______ - / /_/ / ___/ __ \/ __ __ \/ _ \/ __/ __ \/ _ \/ / / / ___/ - / ____/ / / /_/ / / / / / / __/ /_/ / / / __/ /_/ (__ ) -/_/ v4/_/ \____/_/ /_/ /_/\___/\__/_/ /_/\___/\__,_/____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:9090${CL} \n" diff --git a/ct/prometheus-v5.sh b/ct/prometheus-v5.sh index 2de01b11..a11c6e8e 100644 --- a/ct/prometheus-v5.sh +++ b/ct/prometheus-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/prowlarr-v5.sh b/ct/prowlarr-v5.sh index ed741da7..5d73e435 100644 --- a/ct/prowlarr-v5.sh +++ b/ct/prowlarr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/radarr-v5.sh b/ct/radarr-v5.sh index 3ae34a9c..e453cd1a 100644 --- a/ct/radarr-v5.sh +++ b/ct/radarr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/readarr-v5.sh b/ct/readarr-v5.sh index d8e03dfb..39092a64 100644 --- a/ct/readarr-v5.sh +++ b/ct/readarr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/rockylinux-v5.sh b/ct/rockylinux-v5.sh index 8cf707f2..992902d1 100644 --- a/ct/rockylinux-v5.sh +++ b/ct/rockylinux-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/sabnzbd-v5.sh b/ct/sabnzbd-v5.sh index c5480465..6edfd424 100644 --- a/ct/sabnzbd-v5.sh +++ b/ct/sabnzbd-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/scrypted-v4.sh b/ct/scrypted-v4.sh deleted file mode 100644 index 3dd86f9b..00000000 --- a/ct/scrypted-v4.sh +++ /dev/null @@ -1,343 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Scrypted" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _____ __ __ - / ___/____________v4______ / /____ ____/ / - \__ \/ ___/ ___/ / / / __ \/ __/ _ \/ __ / - ___/ / /__/ / / /_/ / /_/ / /_/ __/ /_/ / -/____/\___/_/ \__, / .___/\__/\___/\__,_/ - /____/_/ -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}https://${IP}:10443${CL} \n" diff --git a/ct/scrypted-v5.sh b/ct/scrypted-v5.sh index 3b4c7eda..97f0bedf 100644 --- a/ct/scrypted-v5.sh +++ b/ct/scrypted-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/shinobi-v4.sh b/ct/shinobi-v4.sh deleted file mode 100644 index e52e3565..00000000 --- a/ct/shinobi-v4.sh +++ /dev/null @@ -1,338 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Shinobi" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="ubuntu" -var_version="22.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _____ __ _ __ _ - / ___// /_ (_)___v4____ / /_ (_) - \__ \/ __ \/ / __ \/ __ \/ __ \/ / - ___/ / / / / / / / / /_/ / /_/ / / -/____/_/ /_/_/_/ /_/\____/_.___/_/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - var_version=$(whiptail --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ - "18.04" "Bionic" OFF \ - "20.04" "Focal" OFF \ - "22.04" "Jammy" ON \ - "22.10" "Kinetic" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Ubuntu Version: ${BGN}$var_version${CL}"; fi - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} Setup should be reachable by going to the following URL. - ${BL}http://${IP}:8080/super${CL} \n" diff --git a/ct/shinobi-v5.sh b/ct/shinobi-v5.sh index 0a3ca6cf..9e9943b7 100644 --- a/ct/shinobi-v5.sh +++ b/ct/shinobi-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -326,7 +319,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -373,7 +365,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/sonarr-v5.sh b/ct/sonarr-v5.sh index bf291d82..f0ddd2bc 100644 --- a/ct/sonarr-v5.sh +++ b/ct/sonarr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/syncthing-v4.sh b/ct/syncthing-v4.sh deleted file mode 100644 index f6f928c1..00000000 --- a/ct/syncthing-v4.sh +++ /dev/null @@ -1,330 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Syncthing" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _____ __ __ _ - / ___/__ ______v4_____/ /_/ /_ (_)___ ____ _ - \__ \/ / / / __ \/ ___/ __/ __ \/ / __ \/ __ `/ - ___/ / /_/ / / / / /__/ /_/ / / / / / / / /_/ / -/____/\__, /_/ /_/\___/\__/_/ /_/_/_/ /_/\__, / - /____/ /____/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8384 ${CL} (after initial start) \n" diff --git a/ct/syncthing-v5.sh b/ct/syncthing-v5.sh index fc983f24..cc8c498e 100644 --- a/ct/syncthing-v5.sh +++ b/ct/syncthing-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -364,7 +356,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/tdarr-v5.sh b/ct/tdarr-v5.sh index 882fa1d7..16fee7d4 100644 --- a/ct/tdarr-v5.sh +++ b/ct/tdarr-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/technitiumdns-v4.sh b/ct/technitiumdns-v4.sh deleted file mode 100644 index ca581f21..00000000 --- a/ct/technitiumdns-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Technitium DNS" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - ______ __ _ __ _ ____ _ _______ - /_ __/__ _____/ /_ ____ (_) /_(_)_ ______ ___ v4 / __ \/ | / / ___/ - / / / _ \/ ___/ __ \/ __ \/ / __/ / / / / __ __ \ / / / / |/ /\__ \ - / / / __/ /__/ / / / / / / / /_/ / /_/ / / / / / / / /_/ / /| /___/ / -/_/ \___/\___/_/ /_/_/ /_/_/\__/_/\__,_/_/ /_/ /_/ /_____/_/ |_//____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:5380${CL} \n" diff --git a/ct/technitiumdns-v5.sh b/ct/technitiumdns-v5.sh index ec98b23c..d9f0cc23 100644 --- a/ct/technitiumdns-v5.sh +++ b/ct/technitiumdns-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -425,7 +417,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/transmission-v5.sh b/ct/transmission-v5.sh index 53bf082a..9c040e3e 100644 --- a/ct/transmission-v5.sh +++ b/ct/transmission-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/trilium-v4.sh b/ct/trilium-v4.sh deleted file mode 100644 index 8fd5f853..00000000 --- a/ct/trilium-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Trilium" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - ______ _ ___ - /_ __/_v4_(_) (_)_ ______ ___ - / / / ___/ / / / / / / __ `__ \ - / / / / / / / / /_/ / / / / / / -/_/ /_/ /_/_/_/\__,_/_/ /_/ /_/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8080${CL} \n" diff --git a/ct/trilium-v5.sh b/ct/trilium-v5.sh index 9facb7ca..09e8bf47 100644 --- a/ct/trilium-v5.sh +++ b/ct/trilium-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -382,7 +374,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/ubuntu-v4.sh b/ct/ubuntu-v4.sh deleted file mode 100644 index 803ce681..00000000 --- a/ct/ubuntu-v4.sh +++ /dev/null @@ -1,335 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Ubuntu" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="ubuntu" -var_version="22.04" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - __ ____ __ - / / / / /_v4__ ______ / /___ __ - / / / / __ \/ / / / __ \/ __/ / / / -/ /_/ / /_/ / /_/ / / / / /_/ /_/ / -\____/_.___/\__,_/_/ /_/\__/\__,_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using ${var_os} Version: ${BGN}${var_version}${CL}" - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - var_version=$(whiptail --title "UBUNTU VERSION" --radiolist "Choose Version" 10 58 4 \ - "18.04" "Bionic" OFF \ - "20.04" "Focal" OFF \ - "22.04" "Jammy" ON \ - "22.10" "Kinetic" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Ubuntu Version: ${BGN}$var_version${CL}"; fi - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} ${var_version} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/ubuntu-v5.sh b/ct/ubuntu-v5.sh index 0cdab57f..938f771a 100644 --- a/ct/ubuntu-v5.sh +++ b/ct/ubuntu-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -139,7 +133,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -322,7 +315,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -366,7 +358,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/umbrel-v4.sh b/ct/umbrel-v4.sh deleted file mode 100644 index 9b557c03..00000000 --- a/ct/umbrel-v4.sh +++ /dev/null @@ -1,344 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Umbrel" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - __ __ __ __ - / / / /___ ___v4/ /_ ________ / / - / / / / __ `__ \/ __ \/ ___/ _ \/ / -/ /_/ / / / / / / /_/ / / / __/ / -\____/_/ /_/ /_/_.___/_/ \___/_/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "FUSE OVERLAYFS" --yesno "(ZFS) Enable Fuse Overlayfs?" 10 58); then - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}Yes${CL}" - FUSE="yes" - else - echo -e "${DGN}(ZFS) Enable Fuse Overlayfs: ${BGN}No${CL}" - FUSE="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$FUSE" == "yes" ]; then -FEATURES="fuse=1,keyctl=1,nesting=1" -else -FEATURES="keyctl=1,nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export ST=$FUSE -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -LXC_CONFIG=/etc/pve/lxc/${CTID}.conf -cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -EOF -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL (reboot is required before app installs). - ${BL}http://${IP} ${CL} \n" diff --git a/ct/umbrel-v5.sh b/ct/umbrel-v5.sh index 684b4fc2..6d421a09 100644 --- a/ct/umbrel-v5.sh +++ b/ct/umbrel-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -144,7 +138,6 @@ function default_settings() { FUSE="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -326,7 +319,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -371,7 +363,6 @@ pushd $TEMP_DIR >/dev/null export ST=$FUSE export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/unifi-v4.sh b/ct/unifi-v4.sh deleted file mode 100644 index 38229ab0..00000000 --- a/ct/unifi-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Unifi" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - __ __ _ _____ - / / / /_v4 (_) __(_) - / / / / __ \/ / /_/ / -/ /_/ / / / / / __/ / -\____/_/ /_/_/_/ /_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP}${CL} should be reachable by going to the following URL. - ${BL}https://${IP}:8443${CL} \n" diff --git a/ct/unifi-v5.sh b/ct/unifi-v5.sh index 5f07d29a..87ec5d1f 100644 --- a/ct/unifi-v5.sh +++ b/ct/unifi-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -363,7 +355,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/uptimekuma-v4.sh b/ct/uptimekuma-v4.sh deleted file mode 100644 index 289694da..00000000 --- a/ct/uptimekuma-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Uptime Kuma" -var_disk="4" -var_cpu="1" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${DGN} - __ __ __ _ __ __ - / / / /___ / /_(_)___ ___ ___ v4 / //_/_ ______ ___ ____ _ - / / / / __ \/ __/ / __ __ \/ _ \ / ,< / / / / __ __ \/ __ / -/ /_/ / /_/ / /_/ / / / / / / __/ / /| / /_/ / / / / / / /_/ / -\____/ .___/\__/_/_/ /_/ /_/\___/ /_/ |_\__,_/_/ /_/ /_/\__,_/ - /_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:3001${CL} \n" diff --git a/ct/uptimekuma-v5.sh b/ct/uptimekuma-v5.sh index c29a3832..b08413ed 100644 --- a/ct/uptimekuma-v5.sh +++ b/ct/uptimekuma-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -380,7 +372,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/vaultwarden-v4.sh b/ct/vaultwarden-v4.sh deleted file mode 100644 index be5fe841..00000000 --- a/ct/vaultwarden-v4.sh +++ /dev/null @@ -1,332 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Vaultwarden" -var_disk="6" -var_cpu="2" -var_ram="3072" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${CL} - _ _____ __ ____ _______ _____ ____ ____ _______ __ -| | / / | / / / / / /_ __/ | / / | / __ \/ __ \/ ____/ | / / -| | / / /| |/ / / / / / / | | /| / / /| | / /_/ / / / / __/ / |/ / -| |/ / ___ / /_/ / /___/ / | |/ |/ / ___ |/ _, _/ /_/ / /___/ /| / -|___/_/ |_\____/_____/_/ v4 |__/|__/_/ |_/_/ |_/_____/_____/_/ |_/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_info "Setting Container to Normal Resources" -pct set $CTID -memory 512 -pct set $CTID -cores 1 -msg_ok "Set Container to Normal Resources" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8000${CL} \n" diff --git a/ct/vaultwarden-v5.sh b/ct/vaultwarden-v5.sh index fda70c39..87ebde7d 100644 --- a/ct/vaultwarden-v5.sh +++ b/ct/vaultwarden-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -141,7 +135,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -431,7 +423,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/whisparr-v5.sh b/ct/whisparr-v5.sh index 27636526..eb983253 100644 --- a/ct/whisparr-v5.sh +++ b/ct/whisparr-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -139,7 +133,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -314,7 +307,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -359,7 +351,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/whoogle-v4.sh b/ct/whoogle-v4.sh deleted file mode 100644 index 7d3a7f6c..00000000 --- a/ct/whoogle-v4.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Whoogle" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${GN} - _ ____ ______ ____ ________ ______ -| | v4 / / / / / __ \/ __ \/ ____/ / / ____/ -| | /| / / /_/ / / / / / / / / __/ / / __/ -| |/ |/ / __ / /_/ / /_/ / /_/ / /___/ /___ -|__/|__/_/ /_/\____/\____/\____/_____/_____/ -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:5000${CL} \n" diff --git a/ct/whoogle-v5.sh b/ct/whoogle-v5.sh index b8600076..e39ecff8 100644 --- a/ct/whoogle-v5.sh +++ b/ct/whoogle-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -362,7 +354,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/wikijs-v4.sh b/ct/wikijs-v4.sh deleted file mode 100644 index 6fc2487f..00000000 --- a/ct/wikijs-v4.sh +++ /dev/null @@ -1,329 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Wikijs" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${BL} - _ ___ __ _ _ -| | / (_) /__(_) (_)____ -| | /| / / / //_/ / / / ___/ -| |/ |/ / / ,< / / / (__ ) -|__/|__/_/_/|_/_(_)_/ /____/ - /___/ v4 -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:3000${CL} \n" diff --git a/ct/wikijs-v5.sh b/ct/wikijs-v5.sh index 1ed0b3b8..db50b8e9 100644 --- a/ct/wikijs-v5.sh +++ b/ct/wikijs-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -376,7 +368,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/wireguard-v4.sh b/ct/wireguard-v4.sh deleted file mode 100644 index 532847ad..00000000 --- a/ct/wireguard-v4.sh +++ /dev/null @@ -1,330 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Wireguard" -var_disk="2" -var_cpu="1" -var_ram="512" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${RD} - __ ___ _____ _ - \ \ / (_) / ____| | | - \ \ /\ / / _ _ __ ___| | __ _ _ __ _ _ __ __| | - \ \/ \/ / | | __/ _ \ | |_ | | | |/ _ | __/ _ | - \ /\ / | | | | __/ |__| | |_| | (_| | | | (_| | - \/ \/ v4|_|_| \___|\_____|\__,_|\__,_|_| \__,_| - ${YW}With WGDashboard -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}" - CT_TYPE="1" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" ON \ - "0" "Privileged" OFF \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "WGDashboard should be reachable by going to the following URL. - ${BL}http://${IP}:10086${CL} \n" diff --git a/ct/wireguard-v5.sh b/ct/wireguard-v5.sh index 376ff186..78d35fa2 100644 --- a/ct/wireguard-v5.sh +++ b/ct/wireguard-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -418,7 +410,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/yunohost-v5.sh b/ct/yunohost-v5.sh index e9d630c4..f60795d2 100644 --- a/ct/yunohost-v5.sh +++ b/ct/yunohost-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -138,7 +132,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -313,7 +306,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -358,7 +350,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/zigbee2mqtt-v4.sh b/ct/zigbee2mqtt-v4.sh deleted file mode 100644 index 986309c5..00000000 --- a/ct/zigbee2mqtt-v4.sh +++ /dev/null @@ -1,341 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Zigbee2MQTT" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - echo -e "${YW} - _____ _ __ ___ __ _______ ____________ -/__ / (_)___ _/ /_ ___ ___ |__ \ / |/ / __ \/_ __/_ __/ - / / / / __ / __ \/ _ \/ _ \__/ // /|_/ / / / / / / / / - / /__/ / /_/ / /_/ / __/ __/ __// / / / /_/ / / / / / -/____/_/\__, /_.___/\___/\___/____/_/ /_/\___\_\/_/ /_/ - v4 /____/ 🐝 -${CL}" -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" diff --git a/ct/zigbee2mqtt-v5.sh b/ct/zigbee2mqtt-v5.sh index e006440e..ad1d2455 100644 --- a/ct/zigbee2mqtt-v5.sh +++ b/ct/zigbee2mqtt-v5.sh @@ -33,20 +33,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -143,7 +137,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -318,7 +311,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -393,7 +385,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/ct/zwave-js-ui-v4.sh b/ct/zwave-js-ui-v4.sh deleted file mode 100644 index 1125bd07..00000000 --- a/ct/zwave-js-ui-v4.sh +++ /dev/null @@ -1,343 +0,0 @@ -#!/usr/bin/env bash -echo -e "Loading..." -APP="Zwave-JS-UI" -var_disk="4" -var_cpu="2" -var_ram="1024" -var_os="debian" -var_version="11" -NSAPP=$(echo ${APP,,} | tr -d ' ') -var_install="${NSAPP}-install" -NEXTID=$(pvesh get /cluster/nextid) -INTEGER='^[0-9]+$' -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then - echo "User selected Yes" -else - clear - echo -e "⚠ User exited script \n" - exit -fi -function header_info { - cat <<"EOF" - _____ _______ __ ______ -/__ /_ ______ __v4 _____ / / ___/ / / / / _/ - / /| | /| / / __ `/ | / / _ \ __ / /\__ \ / / / // / - / /_| |/ |/ / /_/ /| |/ / __/ / /_/ /___/ / / /_/ // / -/____/__/|__/\__,_/ |___/\___/ \____//____/ \____/___/ - -EOF -} -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function PVE_CHECK() { - PVE=$(pveversion | grep "pve-manager/7" | wc -l) - if [[ $PVE != 1 ]]; then - echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function ARCH_CHECK() { - ARCH=$(dpkg --print-architecture) - if [[ "$ARCH" != "amd64" ]]; then - echo -e "\n ❌ This script will not work with PiMox! \n" - echo -e "Exiting..." - sleep 2 - exit - fi -} -function default_settings() { - echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}" - CT_TYPE="0" - echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}" - PW="" - echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}" - CT_ID=$NEXTID - echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}" - HN=$NSAPP - echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}" - DISK_SIZE="$var_disk" - echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}" - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}" - RAM_SIZE="$var_ram" - echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}" - GATE="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - SD="" - echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}" - NS="" - echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}" - MAC="" - echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}" - VLAN="" - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" -} -function advanced_settings() { - CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \ - "1" "Unprivileged" OFF \ - "0" "Privileged" ON \ - 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}" - fi - PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $PW1 ]; then - PW1="Automatic Login" PW=" " - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - else - PW="-password $PW1" - echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}" - fi - fi - CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_ID ]; then - CT_ID="$NEXTID" - echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi - fi - CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CT_NAME ]; then - HN="$NSAPP" - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - else - if [ $exitstatus = 0 ]; then - HN=$(echo ${CT_NAME,,} | tr -d ' ') - echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" - fi - fi - DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $DISK_SIZE ]; then - DISK_SIZE="$var_disk" - echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi - if ! [[ $DISK_SIZE =~ $INTEGER ]]; then - echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}" - advanced_settings - fi - fi - CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $CORE_COUNT ]; then - CORE_COUNT="$var_cpu" - echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi - fi - RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $RAM_SIZE ]; then - RAM_SIZE="$var_ram" - echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi - fi - BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $BRG ]; then - BRG="vmbr0" - echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi - fi - NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ -z $NET ]; then - NET="dhcp" - echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}" - else - if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi - fi - GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $GATE1 ]; then - GATE1="Default" GATE="" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}" - fi - fi - SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $SD ]; then - SD="" - echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}" - else - SX=$SD - SD="-searchdomain=$SD" - echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}" - fi - fi - NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $NS ]; then - NS="" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}" - else - NX=$NS - NS="-nameserver=$NS" - echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}" - fi - fi - MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $MAC1 ]; then - MAC1="Default" MAC="" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - else - MAC=",hwaddr=$MAC1" - echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" - fi - fi - VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3) - exitstatus=$? - if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then - VLAN1="Default" VLAN="" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" - fi - fi - if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then - echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}" - SSH="yes" - else - echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}" - SSH="no" - fi - if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then - echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}" - VERB="yes" - else - echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" - VERB="no" - fi - if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then - echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" - else - clear - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -function start_script() { - if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then - header_info - echo -e "${BL}Using Default Settings${CL}" - default_settings - else - header_info - echo -e "${RD}Using Advanced Settings${CL}" - advanced_settings - fi -} -clear -start_script -if [ "$VERB" == "yes" ]; then set -x; fi -if [ "$CT_TYPE" == "1" ]; then - FEATURES="nesting=1,keyctl=1" -else - FEATURES="nesting=1" -fi -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -export VERBOSE=$VERB -export SSH_ROOT=${SSH} -export CTID=$CT_ID -export PCT_OSTYPE=$var_os -export PCT_OSVERSION=$var_version -export PCT_DISK_SIZE=$DISK_SIZE -export PCT_OPTIONS=" - -features $FEATURES - -hostname $HN - $SD - $NS - -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN - -onboot 1 - -cores $CORE_COUNT - -memory $RAM_SIZE - -unprivileged $CT_TYPE - $PW -" -bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit -if [ "$CT_TYPE" == "0" ]; then - LXC_CONFIG=/etc/pve/lxc/${CTID}.conf - cat <>$LXC_CONFIG -lxc.cgroup2.devices.allow: a -lxc.cap.drop: -lxc.cgroup2.devices.allow: c 188:* rwm -lxc.cgroup2.devices.allow: c 189:* rwm -lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir -lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file -lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file -EOF -fi -msg_info "Starting LXC Container" -pct start $CTID -msg_ok "Started LXC Container" -lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -pct set $CTID -description "# ${APP} LXC -### https://tteck.github.io/Proxmox/ -" -msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:8091${CL} \n" diff --git a/ct/zwave-js-ui-v5.sh b/ct/zwave-js-ui-v5.sh index 3018177d..da1e45c8 100644 --- a/ct/zwave-js-ui-v5.sh +++ b/ct/zwave-js-ui-v5.sh @@ -32,20 +32,14 @@ BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -142,7 +136,6 @@ function default_settings() { SSH="no" echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}" } function advanced_settings() { @@ -317,7 +310,6 @@ function advanced_settings() { else echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}" VERB="no" - VERB2="silent" fi if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}" @@ -376,7 +368,6 @@ TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null export DISABLEIPV6=$DISABLEIP6 export VERBOSE=$VERB -export STD=$VERB2 export SSH_ROOT=${SSH} export CTID=$CT_ID export PCT_OSTYPE=$var_os diff --git a/install/adguard-install.sh b/install/adguard-install.sh deleted file mode 100644 index fbe4d973..00000000 --- a/install/adguard-install.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing AdGuard Home" -curl -sSL https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh &>/dev/null -msg_ok "Installed AdGuard Home" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/adguard-v5-install.sh b/install/adguard-v5-install.sh index 497b3a81..533c988a 100644 --- a/install/adguard-v5-install.sh +++ b/install/adguard-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -98,12 +94,11 @@ $STD bash install.sh rm install.sh msg_ok "Installed AdGuard Home" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -116,10 +111,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/audiobookshelf-v5-install.sh b/install/audiobookshelf-v5-install.sh index 13e8a432..e9086b57 100644 --- a/install/audiobookshelf-v5-install.sh +++ b/install/audiobookshelf-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -96,11 +92,11 @@ $STD apt-get update $STD apt install audiobookshelf msg_ok "Installed audiobookshelf" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -113,10 +109,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/autobrr-v5-install.sh b/install/autobrr-v5-install.sh index 9c54ff2a..03a1d05c 100644 --- a/install/autobrr-v5-install.sh +++ b/install/autobrr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -117,11 +113,11 @@ WantedBy=multi-user.target" >$service_path systemctl enable --now -q autobrr.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -134,10 +130,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/blocky-install.sh b/install/blocky-install.sh deleted file mode 100644 index 4422902e..00000000 --- a/install/blocky-install.sh +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Blocky" -systemctl stop systemd-resolved &>/dev/null -systemctl disable systemd-resolved.service &>/dev/null -RELEASE=$(curl -s https://api.github.com/repos/0xERR0R/blocky/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -wget https://github.com/0xERR0R/blocky/releases/download/v$RELEASE/blocky_${RELEASE}_Linux_x86_64.tar.gz &>/dev/null -mkdir -p /opt/blocky -tar -xf blocky_${RELEASE}_Linux_x86_64.tar.gz -C /opt/blocky -rm -rf blocky_${RELEASE}_Linux_x86_64.tar.gz -cat </opt/blocky/config.yml -upstream: - # these external DNS resolvers will be used. Blocky picks 2 random resolvers from the list for each query - # format for resolver: [net:]host:[port][/path]. net could be empty (default, shortcut for tcp+udp), tcp+udp, tcp, udp, tcp-tls or https (DoH). If port is empty, default port will be used (53 for udp and tcp, 853 for tcp-tls, 443 for https (Doh)) - # this configuration is mandatory, please define at least one external DNS resolver - default: - # example for tcp+udp IPv4 server (https://digitalcourage.de/) - #- 5.9.164.112 - # Cloudflare - - 1.1.1.1 - # example for DNS-over-TLS server (DoT) - #- tcp-tls:fdns1.dismail.de:853 - # example for DNS-over-HTTPS (DoH) - #- https://dns.digitale-gesellschaft.ch/dns-query - # optional: use client name (with wildcard support: * - sequence of any characters, [0-9] - range) - # or single ip address / client subnet as CIDR notation - #laptop*: - #- 123.123.123.123 - -# optional: timeout to query the upstream resolver. Default: 2s -#upstreamTimeout: 2s - -# optional: If true, blocky will fail to start unless at least one upstream server per group is reachable. Default: false -#startVerifyUpstream: true - -# optional: Determines how blocky will create outgoing connections. This impacts both upstreams, and lists. -# accepted: dual, v4, v6 -# default: dual -#connectIPVersion: dual - -# optional: custom IP address(es) for domain name (with all sub-domains). Multiple addresses must be separated by a comma -# example: query "printer.lan" or "my.printer.lan" will return 192.168.178.3 -#customDNS: - #customTTL: 1h - # optional: if true (default), return empty result for unmapped query types (for example TXT, MX or AAAA if only IPv4 address is defined). - # if false, queries with unmapped types will be forwarded to the upstream resolver - #filterUnmappedTypes: true - # optional: replace domain in the query with other domain before resolver lookup in the mapping - #rewrite: - #example.com: printer.lan - #mapping: - #printer.lan: 192.168.178.3,2001:0db8:85a3:08d3:1319:8a2e:0370:7344 - -# optional: definition, which DNS resolver(s) should be used for queries to the domain (with all sub-domains). Multiple resolvers must be separated by a comma -# Example: Query client.fritz.box will ask DNS server 192.168.178.1. This is necessary for local network, to resolve clients by host name -#conditional: - # optional: if false (default), return empty result if after rewrite, the mapped resolver returned an empty answer. If true, the original query will be sent to the upstream resolver - # Example: The query "blog.example.com" will be rewritten to "blog.fritz.box" and also redirected to the resolver at 192.168.178.1. If not found and if was set to , the original query "blog.example.com" will be sent upstream. - # Usage: One usecase when having split DNS for internal and external (internet facing) users, but not all subdomains are listed in the internal domain. - #fallbackUpstream: false - # optional: replace domain in the query with other domain before resolver lookup in the mapping - #rewrite: - #example.com: fritz.box - #mapping: - #fritz.box: 192.168.178.1 - #lan.net: 192.168.178.1,192.168.178.2 - -# optional: use black and white lists to block queries (for example ads, trackers, adult pages etc.) -blocking: - # definition of blacklist groups. Can be external link (http/https) or local file - blackLists: - ads: - - https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt - - https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts - - http://sysctl.org/cameleon/hosts - - https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt - - | - # inline definition with YAML literal block scalar style - # hosts format - someadsdomain.com - special: - - https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts - # definition of whitelist groups. Attention: if the same group has black and whitelists, whitelists will be used to disable particular blacklist entries. If a group has only whitelist entries -> this means only domains from this list are allowed, all other domains will be blocked - whiteLists: - ads: - - whitelist.txt - - | - # inline definition with YAML literal block scalar style - # hosts format - whitelistdomain.com - # this is a regex - /^banners?[_.-]/ - # definition: which groups should be applied for which client - clientGroupsBlock: - # default will be used, if no special definition for a client name exists - default: - - ads - - special - # use client name (with wildcard support: * - sequence of any characters, [0-9] - range) - # or single ip address / client subnet as CIDR notation - #laptop*: - #- ads - #192.168.178.1/24: - #- special - # which response will be sent, if query is blocked: - # zeroIp: 0.0.0.0 will be returned (default) - # nxDomain: return NXDOMAIN as return code - # comma separated list of destination IP addresses (for example: 192.100.100.15, 2001:0db8:85a3:08d3:1319:8a2e:0370:7344). Should contain ipv4 and ipv6 to cover all query types. Useful with running web server on this address to display the "blocked" page. - blockType: zeroIp - # optional: TTL for answers to blocked domains - # default: 6h - blockTTL: 1m - # optional: automatically list refresh period (in duration format). Default: 4h. - # Negative value -> deactivate automatically refresh. - # 0 value -> use default - refreshPeriod: 4h - # optional: timeout for list download (each url). Default: 60s. Use large values for big lists or slow internet connections - downloadTimeout: 4m - # optional: Download attempt timeout. Default: 60s - downloadAttempts: 5 - # optional: Time between the download attempts. Default: 1s - downloadCooldown: 10s - # optional: if failOnError, application startup will fail if at least one list can't be downloaded / opened. Default: blocking - #startStrategy: failOnError - -# optional: configuration for caching of DNS responses -caching: - # duration how long a response must be cached (min value). - # If <=0, use response's TTL, if >0 use this value, if TTL is smaller - # Default: 0 - minTime: 5m - # duration how long a response must be cached (max value). - # If <0, do not cache responses - # If 0, use TTL - # If > 0, use this value, if TTL is greater - # Default: 0 - maxTime: 30m - # Max number of cache entries (responses) to be kept in cache (soft limit). Useful on systems with limited amount of RAM. - # Default (0): unlimited - maxItemsCount: 0 - # if true, will preload DNS results for often used queries (default: names queried more than 5 times in a 2-hour time window) - # this improves the response time for often used queries, but significantly increases external traffic - # default: false - prefetching: true - # prefetch track time window (in duration format) - # default: 120 - prefetchExpires: 2h - # name queries threshold for prefetch - # default: 5 - prefetchThreshold: 5 - # Max number of domains to be kept in cache for prefetching (soft limit). Useful on systems with limited amount of RAM. - # Default (0): unlimited - #prefetchMaxItemsCount: 0 - -# optional: configuration of client name resolution -clientLookup: - # optional: this DNS resolver will be used to perform reverse DNS lookup (typically local router) - #upstream: 192.168.178.1 - # optional: some routers return multiple names for client (host name and user defined name). Define which single name should be used. - # Example: take second name if present, if not take first name - #singleNameOrder: - #- 2 - #- 1 - # optional: custom mapping of client name to IP addresses. Useful if reverse DNS does not work properly or just to have custom client names. - #clients: - #laptop: - #- 192.168.178.29 -# optional: configuration for prometheus metrics endpoint -prometheus: - # enabled if true - #enable: true - # url path, optional (default '/metrics') - #path: /metrics - -# optional: write query information (question, answer, client, duration etc.) to daily csv file -queryLog: - # optional one of: mysql, postgresql, csv, csv-client. If empty, log to console - #type: mysql - # directory (should be mounted as volume in docker) for csv, db connection string for mysql/postgresql - #target: db_user:db_password@tcp(db_host_or_ip:3306)/db_name?charset=utf8mb4&parseTime=True&loc=Local - #postgresql target: postgres://user:password@db_host_or_ip:5432/db_name - # if > 0, deletes log files which are older than ... days - #logRetentionDays: 7 - # optional: Max attempts to create specific query log writer, default: 3 - #creationAttempts: 1 - # optional: Time between the creation attempts, default: 2s - #creationCooldown: 2s - -# optional: Blocky can synchronize its cache and blocking state between multiple instances through redis. -redis: - # Server address and port - #address: redis:6379 - # Password if necessary - #password: passwd - # Database, default: 0 - #database: 2 - # Connection is required for blocky to start. Default: false - #required: true - # Max connection attempts, default: 3 - #connectionAttempts: 10 - # Time between the connection attempts, default: 1s - #connectionCooldown: 3s - -# optional: DNS listener port(s) and bind ip address(es), default 53 (UDP and TCP). Example: 53, :53, "127.0.0.1:5353,[::1]:5353" -port: 553 -# optional: Port(s) and bind ip address(es) for DoT (DNS-over-TLS) listener. Example: 853, 127.0.0.1:853 -#tlsPort: 853 -# optional: HTTPS listener port(s) and bind ip address(es), default empty = no http listener. If > 0, will be used for prometheus metrics, pprof, REST API, DoH... Example: 443, :443, 127.0.0.1:443 -#httpPort: 4000 -#httpsPort: 443 -# optional: Mininal TLS version that the DoH and DoT server will use -#minTlsServeVersion: 1.3 -# if https port > 0: path to cert and key file for SSL encryption. if not set, self-signed certificate will be generated -#certFile: server.crt -#keyFile: server.key -# optional: use this DNS server to resolve blacklist urls and upstream DNS servers. Useful if no DNS resolver is configured and blocky needs to resolve a host name. Format net:IP:port, net must be udp or tcp -#bootstrapDns: tcp+udp:1.1.1.1 - -filtering: -# optional: drop all queries with following query types. Default: empty - #queryTypes: - #- AAAA - -# optional: if path defined, use this file for query resolution (A, AAAA and rDNS). Default: empty -hostsFile: - # optional: Path to hosts file (e.g. /etc/hosts on Linux) - #filePath: /etc/hosts - # optional: TTL, default: 1h - #hostsTTL: 60m - # optional: Time between hosts file refresh, default: 1h - #refreshPeriod: 30m - # optional: Whether loopback hosts addresses (127.0.0.0/8 and ::1) should be filtered or not, default: false - #filterLoopback: true -# optional: Log level (one from debug, info, warn, error). Default: info -#logLevel: info -# optional: Log format (text or json). Default: text -#logFormat: text -# optional: log timestamps. Default: true -#logTimestamp: true -# optional: obfuscate log output (replace all alphanumeric characters with *) for user sensitive data like request domains or responses to increase privacy. Default: false -#logPrivacy: false - -# optional: add EDE error codes to dns response -#ede: - # enabled if true, Default: false - #enable: true -EOF -msg_ok "Installed Blocky" - -msg_info "Creating Service" -cat </etc/systemd/system/blocky.service -[Unit] -Description=Blocky -After=network.target -[Service] -User=root -WorkingDirectory=/opt/blocky -ExecStart=/opt/blocky/./blocky --config config.yml -[Install] -WantedBy=multi-user.target -EOF -systemctl enable --now blocky -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/blocky-v5-install.sh b/install/blocky-v5-install.sh index b1b80f4b..b68882b1 100644 --- a/install/blocky-v5-install.sh +++ b/install/blocky-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -350,11 +346,11 @@ EOF $STD systemctl enable --now blocky msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -367,10 +363,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/casaos-install.sh b/install/casaos-install.sh deleted file mode 100644 index 141058cd..00000000 --- a/install/casaos-install.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y unzip &>/dev/null -msg_ok "Installed Dependencies" - -DOCKER_CONFIG_PATH='/etc/docker/daemon.json' -mkdir -p $(dirname $DOCKER_CONFIG_PATH) -cat >$DOCKER_CONFIG_PATH <<'EOF' -{ - "log-driver": "journald" -} -EOF - -msg_info "Installing CasaOS (Patience)" -if [ "$ST" == "yes" ]; then -VER=$(curl -s https://api.github.com/repos/containers/fuse-overlayfs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -cd /usr/local/bin -curl -sSL -o fuse-overlayfs https://github.com/containers/fuse-overlayfs/releases/download/$VER/fuse-overlayfs-x86_64 -chmod 755 /usr/local/bin/fuse-overlayfs -cd ~ -fi -wget -qO- https://get.casaos.io | bash &>/dev/null -msg_ok "Installed CasaOS" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/casaos-v5-install.sh b/install/casaos-v5-install.sh index 1a2358fc..013a9a46 100644 --- a/install/casaos-v5-install.sh +++ b/install/casaos-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -106,12 +102,11 @@ fi $STD bash <(curl -fsSL https://get.casaos.io) msg_ok "Installed CasaOS" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -124,10 +119,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/changedetection-install.sh b/install/changedetection-install.sh deleted file mode 100644 index e8c2fdd3..00000000 --- a/install/changedetection-install.sh +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS" -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y pip &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Change Detection" -mkdir /opt/changedetection -pip3 install changedetection.io &>/dev/null -msg_ok "Installed Change Detection" - -msg_info "Creating Service" -cat </etc/systemd/system/changedetection.service -[Unit] -Description=Change Detection -After=network-online.target -[Service] -Type=simple -WorkingDirectory=/opt/changedetection -ExecStart=changedetection.io -d /opt/changedetection -p 5000 -[Install] -WantedBy=multi-user.target -EOF -systemctl enable --now changedetection &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/changedetection-v5-install.sh b/install/changedetection-v5-install.sh index bf528d16..f8b24983 100644 --- a/install/changedetection-v5-install.sh +++ b/install/changedetection-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -110,11 +106,11 @@ EOF $STD systemctl enable --now changedetection msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -127,10 +123,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/cronicle-v5-install.sh b/install/cronicle-v5-install.sh index 85be2f0a..d9c2aca7 100644 --- a/install/cronicle-v5-install.sh +++ b/install/cronicle-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -116,11 +112,11 @@ chmod 775 /etc/init.d/cronicled $STD update-rc.d cronicled defaults msg_ok "Installed Cronicle Primary Server" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -133,10 +129,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/daemonsync-install.sh b/install/daemonsync-install.sh deleted file mode 100644 index 9f68ed71..00000000 --- a/install/daemonsync-install.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y g++-multilib &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Daemon Sync Server" -wget -qL https://github.com/tteck/Proxmox/raw/main/misc/daemonsync_2.2.0.0059_amd64.deb &>/dev/null -sudo dpkg -i daemonsync_2.2.0.0059_amd64.deb &>/dev/null -msg_ok "Installed Daemon Sync Server" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/daemonsync-v5-install.sh b/install/daemonsync-v5-install.sh index 4281260e..04229094 100644 --- a/install/daemonsync-v5-install.sh +++ b/install/daemonsync-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -95,12 +91,11 @@ wget -qL https://github.com/tteck/Proxmox/raw/main/misc/daemonsync_2.2.0.0059_am $STD dpkg -i daemonsync_2.2.0.0059_amd64.deb msg_ok "Installed Daemon Sync Server" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -113,10 +108,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf daemonsync_2.2.0.0059_amd64.deb diff --git a/install/dashy-install.sh b/install/dashy-install.sh deleted file mode 100644 index 680a95cc..00000000 --- a/install/dashy-install.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -sudo apt-get install -y nodejs git make g++ gcc &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Yarn" -npm install --global yarn &>/dev/null -msg_ok "Installed Yarn" - -msg_info "Installing Dashy (Patience)" -git clone https://github.com/Lissy93/dashy.git &>/dev/null -cd /dashy -yarn &>/dev/null -export NODE_OPTIONS=--max-old-space-size=1000 &>/dev/null -yarn build &>/dev/null -msg_ok "Installed Dashy" - -msg_info "Creating Service" -cat </etc/systemd/system/dashy.service -[Unit] -Description=dashy - -[Service] -Type=simple -WorkingDirectory=/dashy -ExecStart=/usr/bin/yarn start -[Install] -WantedBy=multi-user.target -EOF -sudo systemctl start dashy &>/dev/null -sudo systemctl enable dashy &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/dashy-v5-install.sh b/install/dashy-v5-install.sh index 14f76bef..84bc8eaa 100644 --- a/install/dashy-v5-install.sh +++ b/install/dashy-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -126,12 +122,11 @@ $STD systemctl enable dashy systemctl start dashy msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -144,10 +139,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/debian-install.sh b/install/debian-install.sh deleted file mode 100644 index 0029b4e4..00000000 --- a/install/debian-install.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS" -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/debian-v5-install.sh b/install/debian-v5-install.sh index 3a525e6b..428fe812 100644 --- a/install/debian-v5-install.sh +++ b/install/debian-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -88,11 +84,11 @@ $STD apt-get install -y sudo $STD apt-get install -y mc msg_ok "Installed Dependencies" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -105,10 +101,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/deconz-install.sh b/install/deconz-install.sh deleted file mode 100644 index 18395883..00000000 --- a/install/deconz-install.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting Phoscon Repository" -wget -q http://phoscon.de/apt/deconz.pub.key -O - | sudo apt-key add - &>/dev/null -sh -c "echo 'deb [arch=amd64] http://phoscon.de/apt/deconz $(lsb_release -cs) main' > /etc/apt/sources.list.d/deconz.list" &>/dev/null -msg_ok "Setup Phoscon Repository" - -msg_info "Installing deConz" -apt-get update &>/dev/null -apt-get install -y deconz &>/dev/null -msg_ok "Installed deConz" - -msg_info "Creating Service" -service_path="/lib/systemd/system/deconz.service" -echo "[Unit] -Description=deCONZ: ZigBee gateway -- REST API -Wants=deconz-init.service deconz-update.service -StartLimitIntervalSec=0 - -[Service] -User=root -ExecStart=/usr/bin/deCONZ -platform minimal --http-port=80 -Restart=on-failure -RestartSec=30 -AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_KILL CAP_SYS_BOOT CAP_SYS_TIME - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl start deconz -systemctl enable deconz &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/deconz-v5-install.sh b/install/deconz-v5-install.sh index 0235e7de..1b4a59b3 100644 --- a/install/deconz-v5-install.sh +++ b/install/deconz-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -119,11 +115,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now deconz msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -136,10 +132,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/deluge-v5-install.sh b/install/deluge-v5-install.sh index 19f9449d..4d2c8e21 100644 --- a/install/deluge-v5-install.sh +++ b/install/deluge-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -133,11 +129,11 @@ systemctl enable --now -q deluged.service systemctl enable --now -q deluge-web.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -150,10 +146,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/docker-install.sh b/install/docker-install.sh deleted file mode 100644 index df358aba..00000000 --- a/install/docker-install.sh +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -get_latest_release() { - curl -sL https://api.github.com/repos/$1/releases/latest | grep '"tag_name":' | cut -d'"' -f4 -} - -DOCKER_LATEST_VERSION=$(get_latest_release "moby/moby") -PORTAINER_LATEST_VERSION=$(get_latest_release "portainer/portainer") -DOCKER_COMPOSE_LATEST_VERSION=$(get_latest_release "docker/compose") - -msg_info "Installing Docker $DOCKER_LATEST_VERSION" -DOCKER_CONFIG_PATH='/etc/docker/daemon.json' -mkdir -p $(dirname $DOCKER_CONFIG_PATH) -if [ "$ST" == "yes" ]; then -VER=$(curl -s https://api.github.com/repos/containers/fuse-overlayfs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -cd /usr/local/bin -curl -sSL -o fuse-overlayfs https://github.com/containers/fuse-overlayfs/releases/download/$VER/fuse-overlayfs-x86_64 -chmod 755 /usr/local/bin/fuse-overlayfs -cd ~ -echo -e '{\n "storage-driver": "fuse-overlayfs",\n "log-driver": "journald"\n}' > /etc/docker/daemon.json -else -echo -e '{\n "log-driver": "journald"\n}' > /etc/docker/daemon.json -fi -sh <(curl -sSL https://get.docker.com) &>/dev/null -msg_ok "Installed Docker $DOCKER_LATEST_VERSION" - -read -r -p "Would you like to add Portainer? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - PORTAINER="Y" -else - PORTAINER="N" -fi - -if [[ $PORTAINER == "Y" ]]; then - msg_info "Installing Portainer $PORTAINER_LATEST_VERSION" - docker volume create portainer_data >/dev/null - docker run -d \ - -p 8000:8000 \ - -p 9000:9000 \ - --name=portainer \ - --restart=always \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v portainer_data:/data \ - portainer/portainer-ce:latest &>/dev/null - msg_ok "Installed Portainer $PORTAINER_LATEST_VERSION" -fi - -read -r -p "Would you like to add Docker Compose? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - DOCKER_COMPOSE="Y" -else - DOCKER_COMPOSE="N" -fi - -if [[ $DOCKER_COMPOSE == "Y" ]]; then - msg_info "Installing Docker Compose $DOCKER_COMPOSE_LATEST_VERSION" - DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} - mkdir -p $DOCKER_CONFIG/cli-plugins - curl -sSL https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_LATEST_VERSION/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose - chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose - msg_ok "Installed Docker Compose $DOCKER_COMPOSE_LATEST_VERSION" -fi - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/docker-v5-install.sh b/install/docker-v5-install.sh index 762327dd..fa8b1495 100644 --- a/install/docker-v5-install.sh +++ b/install/docker-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -150,12 +146,11 @@ if [[ $DOCKER_COMPOSE == "Y" ]]; then msg_ok "Installed Docker Compose $DOCKER_COMPOSE_LATEST_VERSION" fi -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -168,10 +163,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/emby-install.sh b/install/emby-install.sh deleted file mode 100644 index 3ce66a06..00000000 --- a/install/emby-install.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -if [[ -z "$(grep -w "100000" /proc/self/uid_map)" ]]; then - msg_info "Setting Up Hardware Acceleration" - apt-get -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - beignet-opencl-icd &>/dev/null - - /bin/chgrp video /dev/dri - /bin/chmod 755 /dev/dri - /bin/chmod 660 /dev/dri/* - msg_ok "Set Up Hardware Acceleration" -fi - -LATEST=$(curl -sL https://api.github.com/repos/MediaBrowser/Emby.Releases/releases/latest | grep '"tag_name":' | cut -d'"' -f4) - -msg_info "Installing Emby" -wget https://github.com/MediaBrowser/Emby.Releases/releases/download/${LATEST}/emby-server-deb_${LATEST}_amd64.deb &>/dev/null -dpkg -i emby-server-deb_${LATEST}_amd64.deb &>/dev/null -msg_ok "Installed Emby" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -rm emby-server-deb_${LATEST}_amd64.deb -msg_ok "Cleaned" diff --git a/install/emby-v5-install.sh b/install/emby-v5-install.sh index ffe06b70..18d832f1 100644 --- a/install/emby-v5-install.sh +++ b/install/emby-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -109,11 +105,11 @@ wget -q https://github.com/MediaBrowser/Emby.Releases/releases/download/${LATEST $STD dpkg -i emby-server-deb_${LATEST}_amd64.deb msg_ok "Installed Emby" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -126,10 +122,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/emqx-install.sh b/install/emqx-install.sh deleted file mode 100644 index 49adfa50..00000000 --- a/install/emqx-install.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing EMQX" -curl -s https://packagecloud.io/install/repositories/emqx/emqx/script.deb.sh | bash &>/dev/null -sudo apt-get install -y emqx >/dev/null -systemctl enable --now emqx -msg_ok "Installed EMQX" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/emqx-v5-install.sh b/install/emqx-v5-install.sh index c8fadb4b..bcbae979 100644 --- a/install/emqx-v5-install.sh +++ b/install/emqx-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -94,11 +90,11 @@ $STD apt-get install -y emqx $STD systemctl enable --now emqx msg_ok "Installed EMQX" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -111,10 +107,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" apt-get autoremove >/dev/null diff --git a/install/esphome-install.sh b/install/esphome-install.sh deleted file mode 100644 index fbd8570a..00000000 --- a/install/esphome-install.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Python3-pip" -apt-get install -y python3-pip &>/dev/null -msg_ok "Installed Python3-pip" - -msg_info "Installing ESPHome" -pip3 install esphome &>/dev/null -msg_ok "Installed ESPHome" - -msg_info "Installing ESPHome Dashboard" -pip3 install tornado esptool &>/dev/null - -service_path="/etc/systemd/system/esphomeDashboard.service" -echo "[Unit] -Description=ESPHome Dashboard -After=network.target -[Service] -ExecStart=/usr/local/bin/esphome /root/config/ dashboard -Restart=always -User=root -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable esphomeDashboard.service &>/dev/null -systemctl start esphomeDashboard -msg_ok "Installed ESPHome Dashboard" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/esphome-v5-install.sh b/install/esphome-v5-install.sh index 0504c6c9..433d8487 100644 --- a/install/esphome-v5-install.sh +++ b/install/esphome-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -115,12 +111,11 @@ $STD systemctl enable esphomeDashboard.service systemctl start esphomeDashboard msg_ok "Installed ESPHome Dashboard" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -133,10 +128,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/grafana-install.sh b/install/grafana-install.sh deleted file mode 100644 index efc51a98..00000000 --- a/install/grafana-install.sh +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -apt-get install -y apt-transport-https &>/dev/null -apt-get install -y software-properties-common &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Grafana Repository" -wget -qO- https://packages.grafana.com/gpg.key | sudo apt-key add - &>/dev/null -echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list &>/dev/null -msg_ok "Set up Grafana Repository" - -msg_info "Installing Grafana" -apt-get update &>/dev/null -apt-get install -y grafana &>/dev/null -msg_ok "Installed Grafana" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi -systemctl start grafana-server -systemctl enable grafana-server.service &>/dev/null - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/grafana-v5-install.sh b/install/grafana-v5-install.sh index 29e171c9..b695df32 100644 --- a/install/grafana-v5-install.sh +++ b/install/grafana-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -102,12 +98,11 @@ $STD apt-get update $STD apt-get install -y grafana msg_ok "Installed Grafana" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -120,10 +115,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi systemctl start grafana-server $STD systemctl enable grafana-server.service diff --git a/install/grocy-install.sh b/install/grocy-install.sh deleted file mode 100644 index 1d7acc0a..00000000 --- a/install/grocy-install.sh +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y apache2 &>/dev/null -apt-get install -y unzip &>/dev/null -apt-get install -y apt-transport-https &>/dev/null -apt-get install -y lsb-release &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing PHP 8.1" -curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg -sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' -apt-get update &>/dev/null -apt-get install -y php8.1 &>/dev/null -apt-get install -y libapache2-mod-php8.1 &>/dev/null -apt-get install -y php8.1-sqlite3 &>/dev/null -apt-get install -y php8.1-gd &>/dev/null -apt-get install -y php8.1-intl &>/dev/null -apt-get install -y php8.1-mbstring &>/dev/null -msg_ok "Installed PHP 8.1" - -msg_info "Installing grocy" -wget https://releases.grocy.info/latest &>/dev/null -unzip latest -d /var/www/html &>/dev/null -chown -R www-data:www-data /var/www/html -cp /var/www/html/config-dist.php /var/www/html/data/config.php -chmod +x /var/www/html/update.sh - -cat </etc/apache2/sites-available/grocy.conf - - ServerAdmin webmaster@localhost - DocumentRoot /var/www/html/public - ErrorLog /var/log/apache2/error.log - - Options Indexes FollowSymLinks MultiViews - AllowOverride All - Order allow,deny - allow from all - - -EOF - -a2dissite 000-default.conf &>/dev/null -a2ensite grocy.conf &>/dev/null -a2enmod rewrite &>/dev/null -systemctl reload apache2 -msg_ok "Installed grocy" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -rm -rf /root/latest -msg_ok "Cleaned" diff --git a/install/grocy-v5-install.sh b/install/grocy-v5-install.sh index d847d5a6..34073ba0 100644 --- a/install/grocy-v5-install.sh +++ b/install/grocy-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -132,11 +128,11 @@ $STD a2enmod rewrite systemctl reload apache2 msg_ok "Installed grocy" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -149,10 +145,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/heimdalldashboard-install.sh b/install/heimdalldashboard-install.sh deleted file mode 100644 index cf19a76c..00000000 --- a/install/heimdalldashboard-install.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing PHP" -apt-get install -y php &>/dev/null -apt-get install -y php-sqlite3 &>/dev/null -apt-get install -y php-zip &>/dev/null -msg_ok "Installed PHP" - -RELEASE=$(curl -sX GET "https://api.github.com/repos/linuxserver/Heimdall/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]') -msg_info "Installing Heimdall Dashboard ${RELEASE}" -curl --silent -o ${RELEASE}.tar.gz -L "https://github.com/linuxserver/Heimdall/archive/${RELEASE}.tar.gz" &>/dev/null -tar xvzf ${RELEASE}.tar.gz &>/dev/null -VER=$(curl -s https://api.github.com/repos/linuxserver/Heimdall/releases/latest | - grep "tag_name" | - awk '{print substr($2, 3, length($2)-4) }') -rm -rf ${RELEASE}.tar.gz -mv Heimdall-${VER} /opt/Heimdall -msg_ok "Installed Heimdall Dashboard ${RELEASE}" - -msg_info "Creating Service" -service_path="/etc/systemd/system/heimdall.service" -echo "[Unit] -Description=Heimdall -After=network.target - -[Service] -Restart=always -RestartSec=5 -Type=simple -User=root -WorkingDirectory=/opt/Heimdall -ExecStart="/usr/bin/php" artisan serve --port 7990 --host 0.0.0.0 -TimeoutStopSec=30 - -[Install] -WantedBy=multi-user.target" >$service_path -sudo systemctl enable --now heimdall.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/heimdalldashboard-v5-install.sh b/install/heimdalldashboard-v5-install.sh index a94d230d..ce1b5f75 100644 --- a/install/heimdalldashboard-v5-install.sh +++ b/install/heimdalldashboard-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -126,12 +122,11 @@ WantedBy=multi-user.target" >$service_path $STD sudo systemctl enable --now heimdall.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -144,10 +139,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/homeassistant-core-install.sh b/install/homeassistant-core-install.sh deleted file mode 100644 index a9fb4de6..00000000 --- a/install/homeassistant-core-install.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies (Patience)" -apt-get install -y \ - make \ - build-essential \ - libjpeg-dev \ - libpcap-dev \ - libssl-dev \ - zlib1g-dev \ - libbz2-dev \ - libreadline-dev \ - libsqlite3-dev \ - libmariadb-dev-compat \ - autoconf \ - git \ - curl \ - sudo \ - llvm \ - libncursesw5-dev \ - xz-utils \ - tzdata \ - bluez \ - tk-dev \ - libxml2-dev \ - libxmlsec1-dev \ - libffi-dev \ - libopenjp2-7 \ - libtiff5 \ - libturbojpeg0-dev \ - liblzma-dev &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Linux D-Bus Message Broker" -cat <>/etc/apt/sources.list -deb http://deb.debian.org/debian bullseye-backports main contrib non-free -deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free -EOF -apt-get update &>/dev/null -apt-get -t bullseye-backports install -y dbus-broker &>/dev/null -systemctl enable --now dbus-broker.service &>/dev/null -msg_ok "Installed Linux D-Bus Message Broker" - -msg_info "Installing pyenv" -git clone https://github.com/pyenv/pyenv.git ~/.pyenv &>/dev/null -set +e -echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc -echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc -echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.bashrc -msg_ok "Installed pyenv" -. ~/.bashrc -set -e -msg_info "Installing Python 3.10.8" -pyenv install 3.10.8 &>/dev/null -pyenv global 3.10.8 -msg_ok "Installed Python 3.10.8" - -read -r -p " Use the Beta Branch? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - BR="--pre " -else - BR="" -fi - -msg_info "Installing Home Assistant-Core" -mkdir /srv/homeassistant -cd /srv/homeassistant -python3 -m venv . -source bin/activate -pip install --upgrade pip &>/dev/null -python3 -m pip install wheel &>/dev/null -pip install mysqlclient &>/dev/null -pip install psycopg2-binary &>/dev/null -pip install ${BR}homeassistant &>/dev/null -msg_ok "Installed Home Assistant-Core" - -# fix for inconsistent versions, hopefully the HA team will get this fixed -if [ "${BR}" == "--pre " ]; then -sed -i '{s/dbus-fast==1.82.0/dbus-fast==1.83.1/g; s/bleak==0.19.2/bleak==0.19.5/g}' /srv/homeassistant/lib/python3.10/site-packages/homeassistant/package_constraints.txt -sed -i '{s/dbus-fast==1.82.0/dbus-fast==1.83.1/g; s/bleak==0.19.2/bleak==0.19.5/g}' /srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/bluetooth/manifest.json -else -sed -i '{s/dbus-fast==1.75.0/dbus-fast==1.83.1/g; s/bleak==0.19.2/bleak==0.19.5/g}' /srv/homeassistant/lib/python3.10/site-packages/homeassistant/package_constraints.txt -sed -i '{s/dbus-fast==1.75.0/dbus-fast==1.83.1/g; s/bleak==0.19.2/bleak==0.19.5/g}' /srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/bluetooth/manifest.json -fi - -msg_info "Creating Service" -cat </etc/systemd/system/homeassistant.service -[Unit] -Description=Home Assistant -After=network-online.target -[Service] -Type=simple -WorkingDirectory=/root/.homeassistant -ExecStart=/srv/homeassistant/bin/hass -c "/root/.homeassistant" -RestartForceExitStatus=100 -[Install] -WantedBy=multi-user.target -EOF -systemctl enable homeassistant &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/homeassistant-core-v5-install.sh b/install/homeassistant-core-v5-install.sh index c4663502..1ca60ef6 100644 --- a/install/homeassistant-core-v5-install.sh +++ b/install/homeassistant-core-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -168,11 +164,11 @@ EOF $STD systemctl enable --now homeassistant msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -185,10 +181,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/homeassistant-install.sh b/install/homeassistant-install.sh deleted file mode 100644 index 52c3c427..00000000 --- a/install/homeassistant-install.sh +++ /dev/null @@ -1,360 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Python3-pip" -apt-get install -y python3-pip &>/dev/null -msg_ok "Installed Python3-pip" - -get_latest_release() { - curl -sL https://api.github.com/repos/$1/releases/latest | grep '"tag_name":' | cut -d'"' -f4 -} - -DOCKER_LATEST_VERSION=$(get_latest_release "moby/moby") -CORE_LATEST_VERSION=$(get_latest_release "home-assistant/core") -PORTAINER_LATEST_VERSION=$(get_latest_release "portainer/portainer") - -msg_info "Installing Docker $DOCKER_LATEST_VERSION" -DOCKER_CONFIG_PATH='/etc/docker/daemon.json' -mkdir -p $(dirname $DOCKER_CONFIG_PATH) -if [ "$ST" == "yes" ]; then -VER=$(curl -s https://api.github.com/repos/containers/fuse-overlayfs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -cd /usr/local/bin -curl -sSL -o fuse-overlayfs https://github.com/containers/fuse-overlayfs/releases/download/$VER/fuse-overlayfs-x86_64 -chmod 755 /usr/local/bin/fuse-overlayfs -cd ~ -echo -e '{\n "storage-driver": "fuse-overlayfs",\n "log-driver": "journald"\n}' > /etc/docker/daemon.json -else -echo -e '{\n "log-driver": "journald"\n}' > /etc/docker/daemon.json -fi -sh <(curl -sSL https://get.docker.com) &>/dev/null -msg_ok "Installed Docker $DOCKER_LATEST_VERSION" - -msg_info "Pulling Portainer $PORTAINER_LATEST_VERSION Image" -docker pull portainer/portainer-ce:latest &>/dev/null -msg_ok "Pulled Portainer $PORTAINER_LATEST_VERSION Image" - -msg_info "Installing Portainer $PORTAINER_LATEST_VERSION" -docker volume create portainer_data >/dev/null -docker run -d \ - -p 8000:8000 \ - -p 9000:9000 \ - --name=portainer \ - --restart=always \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v portainer_data:/data \ - portainer/portainer-ce:latest &>/dev/null -msg_ok "Installed Portainer $PORTAINER_LATEST_VERSION" - -msg_info "Pulling Home Assistant $CORE_LATEST_VERSION Image" -docker pull homeassistant/home-assistant:stable &>/dev/null -msg_ok "Pulled Home Assistant $CORE_LATEST_VERSION Image" - -msg_info "Installing Home Assistant $CORE_LATEST_VERSION" -docker volume create hass_config >/dev/null -docker run -d \ - --name homeassistant \ - --privileged \ - --restart unless-stopped \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v /dev:/dev \ - -v hass_config:/config \ - -v /etc/localtime:/etc/localtime:ro \ - --net=host \ - homeassistant/home-assistant:stable &>/dev/null -msg_ok "Installed Home Assistant $CORE_LATEST_VERSION" - -msg_info "Creating Update Menu Script" -pip3 install runlike &>/dev/null -UPDATE_PATH='/root/update' -UPDATE_CONTAINERS_PATH='/root/update-containers.sh' -cat >$UPDATE_PATH <<'EOF' -#!/bin/sh -set -o errexit -show_menu(){ - normal=`echo "\033[m"` - safe=`echo "\033[32m"` - menu=`echo "\033[36m"` - number=`echo "\033[33m"` - bgred=`echo "\033[41m"` - fgred=`echo "\033[31m"` - hostname -I - printf "\n${menu}*********************************************${normal}\n" - printf "${menu}**${number} 1)${safe} Switch to Stable Branch ${normal}\n" - printf "${menu}**${number} 2)${number} Switch to Beta Branch ${normal}\n" - printf "${menu}**${number} 3)${fgred} Switch to Dev Branch ${normal}\n" - printf "${menu}**${number} 4)${safe} Backup Home Assistant Data (to root) ${normal}\n" - printf "${menu}**${number} 5)${number} Restore Home Assistant Data ${normal}\n" - printf "${menu}**${number} 6)${fgred} Edit Home Assistant Configuration ${normal}\n" - printf "${menu}**${number} 7)${safe} Restart Home Assistant ${normal}\n" - printf "${menu}**${number} 8)${safe} Just Update Containers ${normal}\n" - printf "${menu}**${number} 9)${number} Remove Unused Images ${normal}\n" - printf "${menu}**${number} 10)${safe} Update Host OS ${normal}\n" - printf "${menu}**${number} 11)${safe} Reboot Host OS ${normal}\n" - printf "${menu}*********************************************${normal}\n" - printf "Please choose an option from the menu and enter or ${fgred}x to exit. ${normal}" - read opt -} -option_picked(){ - msgcolor=`echo "\033[01;31m"` - normal=`echo "\033[00;00m"` - message=${@:-"${normal}Error: No message passed"} - printf "${msgcolor}${message}${normal}\n" -} -clear -show_menu -while [ $opt != '' ] - do - if [ $opt = '' ]; then - exit; - else - case $opt in - 1) clear; - option_picked "Switching to Stable Branch"; - TAG=stable - break; - ;; - 2) clear; - option_picked "Switching to Beta Branch"; - TAG=beta - break; - ;; - 3) while true; do - read -p "Are you sure you want to Switch to Dev Branch? Proceed(y/n)?" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "Please answer yes or no.";; - esac - done - clear; - option_picked "Switching to Dev Branch"; - TAG=dev - break; - ;; - 4) clear; - option_picked "Backing up Home Assistant Data to root (hass_config)"; - rm -r hass_config; - cp -pR /var/lib/docker/volumes/hass_config/ /root/; - sleep 2; - clear; - show_menu; - ;; - 5) while true; do - read -p "Are you sure you want to Restore Home Assistant Data? Proceed(y/n)?" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "Please answer yes or no.";; - esac - done - clear; - option_picked "Restoring Home Assistant Data from root (hass_config)"; - rm -r /var/lib/docker/volumes/hass_config/_data; - cp -pR /root/hass_config/_data /var/lib/docker/volumes/hass_config/; - sleep 2; - clear; - show_menu; - ;; - 6) while true; do - read -p "Are you sure you want to Edit Home Assistant Configuration? Proceed(y/n)?" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "Please answer yes or no.";; - esac - done - clear; - option_picked "Editing Home Assistant Configuration"; - nano /var/lib/docker/volumes/hass_config/_data/configuration.yaml; - clear; - show_menu; - ;; - 7) clear; - option_picked "Restarting Home Assistant"; - docker restart homeassistant; - exit; - ;; - 8) clear; - option_picked "Just Updating Containers"; - ./update-containers.sh; - sleep 2; - clear; - show_menu; - ;; - 9) clear; - option_picked "Removing Unused Images"; - docker image prune -af; - sleep 2; - clear; - show_menu; - ;; - 10) clear; - option_picked "Updating Host OS"; - apt update && apt upgrade -y; - sleep 2; - clear; - show_menu; - ;; - 11) clear; - option_picked "Reboot Host OS"; - reboot; - exit; - ;; - x)exit; - ;; - \n)exit; - ;; - *)clear; - option_picked "Please choose an option from the menu"; - show_menu; - ;; - esac - fi - done -docker pull homeassistant/home-assistant:$TAG -docker rm --force homeassistant -docker run -d \ - --name homeassistant \ - --privileged \ - --restart unless-stopped \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v /dev:/dev \ - -v hass_config:/config \ - -v /etc/localtime:/etc/localtime:ro \ - -v /etc/timezone:/etc/timezone:ro \ - --net=host \ - homeassistant/home-assistant:$TAG -EOF -sudo chmod +x /root/update -cat >$UPDATE_CONTAINERS_PATH <<'EOF' -#!/bin/bash -set -o errexit -CONTAINER_LIST="${1:-$(docker ps -q)}" -for container in ${CONTAINER_LIST}; do - CONTAINER_IMAGE="$(docker inspect --format "{{.Config.Image}}" --type container ${container})" - RUNNING_IMAGE="$(docker inspect --format "{{.Image}}" --type container "${container}")" - docker pull "${CONTAINER_IMAGE}" - LATEST_IMAGE="$(docker inspect --format "{{.Id}}" --type image "${CONTAINER_IMAGE}")" - if [[ "${RUNNING_IMAGE}" != "${LATEST_IMAGE}" ]]; then - echo "Updating ${container} image ${CONTAINER_IMAGE}" - DOCKER_COMMAND="$(runlike "${container}")" - docker rm --force "${container}" - eval ${DOCKER_COMMAND} - fi -done -EOF -sudo chmod +x /root/update-containers.sh -msg_ok "Created Update Menu Script" -mkdir /root/hass_config -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/homeassistant-v5-install.sh b/install/homeassistant-v5-install.sh index eaed502e..b6c63719 100644 --- a/install/homeassistant-v5-install.sh +++ b/install/homeassistant-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -153,12 +149,11 @@ $STD docker run -d \ mkdir /root/hass_config msg_ok "Installed Home Assistant $CORE_LATEST_VERSION" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -171,10 +166,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/homebridge-install.sh b/install/homebridge-install.sh deleted file mode 100644 index 3fdc5a6b..00000000 --- a/install/homebridge-install.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -sudo apt-get install -y nodejs gcc g++ make python net-tools &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Homebridge" -sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x &>/dev/null -msg_info "Installed Homebridge" - -msg_info "Creating Service" -sudo hb-service install --user homebridge &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/homebridge-v5-install.sh b/install/homebridge-v5-install.sh index 6526111b..1bf8da31 100644 --- a/install/homebridge-v5-install.sh +++ b/install/homebridge-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -105,12 +101,11 @@ msg_info "Creating Service" $STD hb-service install --user homebridge msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -123,10 +118,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/homepage-install.sh b/install/homepage-install.sh deleted file mode 100644 index b69d538c..00000000 --- a/install/homepage-install.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_14.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -npm install -g pnpm &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Homepage" -git clone https://github.com/benphelps/homepage.git /opt/homepage &>/dev/null -cd /opt/homepage -mkdir -p config -pnpm install &>/dev/null -pnpm build &>/dev/null -msg_ok "Installed Homepage" - -msg_info "Creating Service" -service_path="/etc/systemd/system/homepage.service" -echo "[Unit] -Description=Homepage -After=network.target -StartLimitIntervalSec=0 -[Service] -Type=simple -Restart=always -RestartSec=1 -User=root -WorkingDirectory=/opt/homepage/ -ExecStart=pnpm start -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now homepage &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/homepage-v5-install.sh b/install/homepage-v5-install.sh index eca56674..81bc069e 100644 --- a/install/homepage-v5-install.sh +++ b/install/homepage-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -125,11 +121,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now homepage msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -142,10 +138,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/homer-v5-install.sh b/install/homer-v5-install.sh index e4f564d5..b7bbed3a 100644 --- a/install/homer-v5-install.sh +++ b/install/homer-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -114,11 +110,11 @@ EOF $STD systemctl enable --now homer msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -131,10 +127,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/hyperion-install.sh b/install/hyperion-install.sh deleted file mode 100644 index 29644340..00000000 --- a/install/hyperion-install.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS" -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y lsb-release &>/dev/null -apt-get install -y gpg &>/dev/null -apt-get install -y apt-transport-https &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Hyperion" -wget -qO- https://apt.hyperion-project.org/hyperion.pub.key | sudo gpg --dearmor -o /usr/share/keyrings/hyperion.pub.gpg &>/dev/null -echo "deb [signed-by=/usr/share/keyrings/hyperion.pub.gpg] https://apt.hyperion-project.org/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hyperion.list &>/dev/null -apt-get update &>/dev/null -apt-get install -y hyperion &>/dev/null -systemctl enable --now hyperion@root.service &>/dev/null -msg_ok "Installed Hyperion" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/hyperion-v5-install.sh b/install/hyperion-v5-install.sh index 62dd33fc..82bf8084 100644 --- a/install/hyperion-v5-install.sh +++ b/install/hyperion-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -99,11 +95,11 @@ $STD apt-get install -y hyperion $STD systemctl enable --now hyperion@root.service msg_ok "Installed Hyperion" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -116,10 +112,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove >/dev/null diff --git a/install/influxdb-install.sh b/install/influxdb-install.sh deleted file mode 100644 index 1d11d97f..00000000 --- a/install/influxdb-install.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y lsb-base &>/dev/null -apt-get install -y lsb-release &>/dev/null -apt-get install -y gnupg2 &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up InfluxDB Repository" -wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - &>/dev/null -echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list &>/dev/null -msg_ok "Set up InfluxDB Repository" - -read -r -p "Which version of InfluxDB to install? (1 or 2) " prompt -if [[ $prompt == "2" ]]; then - INFLUX="2" -else - INFLUX="1" -fi - -msg_info "Installing InfluxDB" -apt-get update &>/dev/null -if [[ $INFLUX == "2" ]]; then - apt-get install -y influxdb2 &>/dev/null -else - apt-get install -y influxdb &>/dev/null -fi -systemctl enable --now influxdb &>/dev/null -msg_ok "Installed InfluxDB" - -read -r -p "Would you like to add Telegraf? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - TELEGRAF="Y" -else - TELEGRAF="N" -fi - -if [[ $TELEGRAF == "Y" ]]; then - msg_info "Installing Telegraf" - apt-get install -y telegraf &>/dev/null - msg_ok "Installed Telegraf" -fi - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/influxdb-v5-install.sh b/install/influxdb-v5-install.sh index f5becf2e..6c16f851 100644 --- a/install/influxdb-v5-install.sh +++ b/install/influxdb-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -128,12 +124,11 @@ if [[ $TELEGRAF == "Y" ]]; then msg_ok "Installed Telegraf" fi -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -146,10 +141,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/iobroker-install.sh b/install/iobroker-install.sh deleted file mode 100644 index 813e9c46..00000000 --- a/install/iobroker-install.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing ioBroker (10 min)" -curl -sLf https://iobroker.net/install.sh | bash - &>/dev/null -msg_ok "Installed ioBroker" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/iobroker-v5-install.sh b/install/iobroker-v5-install.sh index 96db7e0b..9baddbb6 100644 --- a/install/iobroker-v5-install.sh +++ b/install/iobroker-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -93,12 +89,11 @@ msg_info "Installing ioBroker (Patience)" $STD bash <(curl -fsSL https://iobroker.net/install.sh) msg_ok "Installed ioBroker" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -111,10 +106,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/jellyfin-install.sh b/install/jellyfin-install.sh deleted file mode 100644 index 94c8ad5f..00000000 --- a/install/jellyfin-install.sh +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y apt-transport-https &>/dev/null -apt-get install -y software-properties-common &>/dev/null -msg_ok "Installed Dependencies" - -if [[ -z "$(grep -w "100000" /proc/self/uid_map)" ]]; then - msg_info "Setting Up Hardware Acceleration" - apt-get -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - beignet-opencl-icd &>/dev/null - - /bin/chgrp video /dev/dri - /bin/chmod 755 /dev/dri - /bin/chmod 660 /dev/dri/* - msg_ok "Set Up Hardware Acceleration" -fi - -msg_info "Setting Up Jellyfin Repository" -sudo add-apt-repository universe -y &>/dev/null -wget -q -O - https://repo.jellyfin.org/ubuntu/jellyfin_team.gpg.key | sudo apt-key add - &>/dev/null -echo "deb [arch=$(dpkg --print-architecture)] https://repo.jellyfin.org/ubuntu $(lsb_release -c -s) main" | sudo tee /etc/apt/sources.list.d/jellyfin.list &>/dev/null -msg_ok "Set Up Jellyfin Repository" - -msg_info "Installing Jellyfin" -apt-get update &>/dev/null -sudo apt install jellyfin-server -y &>/dev/null -apt install jellyfin-ffmpeg -y &>/dev/null -msg_ok "Installed Jellyfin" - -msg_info "Creating Service" -cat <<'EOF' >/lib/systemd/system/jellyfin.service -[Unit] -Description = Jellyfin Media Server -After = network.target -[Service] -Type = simple -EnvironmentFile = /etc/default/jellyfin -User = root -ExecStart = /usr/bin/jellyfin -Restart = on-failure -TimeoutSec = 15 -[Install] -WantedBy = multi-user.target -EOF -ln -s /usr/share/jellyfin/web/ /usr/lib/jellyfin/bin/jellyfin-web -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/jellyfin-v5-install.sh b/install/jellyfin-v5-install.sh index 99df1d57..9b06ea4c 100644 --- a/install/jellyfin-v5-install.sh +++ b/install/jellyfin-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -133,11 +129,11 @@ EOF ln -s /usr/share/jellyfin/web/ /usr/lib/jellyfin/bin/jellyfin-web msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -150,10 +146,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/k0s-v5-install.sh b/install/k0s-v5-install.sh index a87798ad..8a8553ae 100644 --- a/install/k0s-v5-install.sh +++ b/install/k0s-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -109,11 +105,11 @@ msg_info "Installing Helm" $STD bash <(curl -sSLf https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3) msg_ok "Installed Helm" fi -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -126,10 +122,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/kavita-v5-install.sh b/install/kavita-v5-install.sh index b76e7979..e7f41d47 100644 --- a/install/kavita-v5-install.sh +++ b/install/kavita-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,7 +10,6 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" @@ -42,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -67,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -108,11 +111,11 @@ chmod +x /opt/Kavita/* && chown root /opt/Kavita/* systemctl enable --now -q kavita.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -125,10 +128,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/keycloak-install.sh b/install/keycloak-install.sh deleted file mode 100644 index 92488072..00000000 --- a/install/keycloak-install.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies (Patience)" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y openjdk-11-jdk &>/dev/null -msg_ok "Installed Dependencies" - -RELEASE=$(curl -s https://api.github.com/repos/keycloak/keycloak/releases/latest | - grep "tag_name" | - awk '{print substr($2, 2, length($2)-3) }') - -msg_info "Installing Keycloak v$RELEASE" -cd /opt -wget https://github.com/keycloak/keycloak/releases/download/$RELEASE/keycloak-$RELEASE.tar.gz &>/dev/null -tar -xvf keycloak-$RELEASE.tar.gz &>/dev/null -mv keycloak-$RELEASE keycloak -msg_ok "Installed Keycloak" - -msg_info "Creating Service" -service_path="/etc/systemd/system/keycloak.service" -echo "[Unit] -Description=Keycloak -After=network-online.target -[Service] -User=root -WorkingDirectory=/opt/keycloak -ExecStart=/opt/keycloak/bin/kc.sh start-dev -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now keycloak.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/keycloak-v5-install.sh b/install/keycloak-v5-install.sh index 4370ce4d..6fdf6051 100644 --- a/install/keycloak-v5-install.sh +++ b/install/keycloak-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -112,11 +108,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now keycloak.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -129,10 +125,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/lidarr-v5-install.sh b/install/lidarr-v5-install.sh index 653c2d7e..d32cf2af 100644 --- a/install/lidarr-v5-install.sh +++ b/install/lidarr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -119,11 +115,11 @@ systemctl -q daemon-reload systemctl enable --now -q lidarr msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -136,10 +132,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Lidarr.master.*.tar.gz diff --git a/install/magicmirror-install.sh b/install/magicmirror-install.sh deleted file mode 100644 index 37ada095..00000000 --- a/install/magicmirror-install.sh +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Setting up MagicMirror Repository" -git clone https://github.com/MichMich/MagicMirror /opt/magicmirror &>/dev/null -msg_ok "Set up MagicMirror Repository" - -msg_info "Installing MagicMirror" -cd /opt/magicmirror &>/dev/null -npm install --only=prod --omit=dev &>/dev/null - -cat </opt/magicmirror/config/config.js -let config = { - address: "0.0.0.0", - port: 8080, - basePath: "/", - ipWhitelist: [], - useHttps: false, - httpsPrivateKey: "", - httpsCertificate: "", - language: "en", - locale: "en-US", - logLevel: ["INFO", "LOG", "WARN", "ERROR"], - timeFormat: 24, - units: "metric", - serverOnly: true, - modules: [ - { - module: "alert", - }, - { - module: "updatenotification", - position: "top_bar" - }, - { - module: "clock", - position: "top_left" - }, - { - module: "calendar", - header: "US Holidays", - position: "top_left", - config: { - calendars: [ - { - symbol: "calendar-check", - url: "webcal://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics" - } - ] - } - }, - { - module: "compliments", - position: "lower_third" - }, - { - module: "weather", - position: "top_right", - config: { - weatherProvider: "openweathermap", - type: "current", - location: "New York", - locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city - apiKey: "YOUR_OPENWEATHER_API_KEY" - } - }, - { - module: "weather", - position: "top_right", - header: "Weather Forecast", - config: { - weatherProvider: "openweathermap", - type: "forecast", - location: "New York", - locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city - apiKey: "YOUR_OPENWEATHER_API_KEY" - } - }, - { - module: "newsfeed", - position: "bottom_bar", - config: { - feeds: [ - { - title: "New York Times", - url: "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml" - } - ], - showSourceTitle: true, - showPublishDate: true, - broadcastNewsFeeds: true, - broadcastNewsUpdates: true - } - }, - ] -}; - -/*************** DO NOT EDIT THE LINE BELOW ***************/ -if (typeof module !== "undefined") {module.exports = config;} -EOF -msg_ok "Installed MagicMirror" - -msg_info "Creating Service" -service_path="/etc/systemd/system/magicmirror.service" -echo "[Unit] -Description=Magic Mirror -After=network.target -StartLimitIntervalSec=0 - -[Service] -Type=simple -Restart=always -RestartSec=1 -User=root -WorkingDirectory=/opt/magicmirror/ -ExecStart=/usr/bin/node serveronly - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now magicmirror &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/magicmirror-v5-install.sh b/install/magicmirror-v5-install.sh index f347ba92..94db7430 100644 --- a/install/magicmirror-v5-install.sh +++ b/install/magicmirror-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,7 +10,6 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" @@ -74,7 +74,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -217,11 +217,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now magicmirror msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -234,10 +234,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/mariadb-install.sh b/install/mariadb-install.sh deleted file mode 100644 index cd499979..00000000 --- a/install/mariadb-install.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing MariaDB" -curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash &>/dev/null -apt-get update >/dev/null -apt-get install -y mariadb-server &>/dev/null -msg_ok "Installed MariaDB" - -read -r -p "Would you like to add Adminer? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - ADMINER="Y" -else - ADMINER="N" -fi - -if [[ $ADMINER == "Y" ]]; then - msg_info "Installing Adminer" - sudo apt install adminer -y &>/dev/null - sudo a2enconf adminer &>/dev/null - sudo systemctl reload apache2 &>/dev/null - msg_ok "Installed Adminer" -fi - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/mariadb-v5-install.sh b/install/mariadb-v5-install.sh index 7e5b2265..35d38926 100644 --- a/install/mariadb-v5-install.sh +++ b/install/mariadb-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -110,12 +106,11 @@ if [[ $ADMINER == "Y" ]]; then msg_ok "Installed Adminer" fi -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -128,10 +123,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/meshcentral-install.sh b/install/meshcentral-install.sh deleted file mode 100644 index af40b17d..00000000 --- a/install/meshcentral-install.sh +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing MeshCentral" -mkdir /opt/meshcentral -cd /opt/meshcentral -npm install meshcentral &>/dev/null -node node_modules/meshcentral --install &>/dev/null -msg_ok "Installed MeshCentral" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/meshcentral-v5-install.sh b/install/meshcentral-v5-install.sh index e4085bed..825aaa00 100644 --- a/install/meshcentral-v5-install.sh +++ b/install/meshcentral-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -104,12 +100,11 @@ $STD npm install meshcentral $STD node node_modules/meshcentral --install msg_ok "Installed MeshCentral" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -122,10 +117,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/motioneye-install.sh b/install/motioneye-install.sh deleted file mode 100644 index 7d819d66..00000000 --- a/install/motioneye-install.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y cifs-utils &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Motion" -apt-get install motion -y &>/dev/null -systemctl stop motion &>/dev/null -systemctl disable motion &>/dev/null -msg_ok "Installed Motion" - -msg_info "Installing FFmpeg" -apt-get install ffmpeg v4l-utils -y &>/dev/null -msg_ok "Installed FFmpeg" - -msg_info "Installing Python" -apt-get update &>/dev/null -apt-get install python2 -y &>/dev/null -curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py &>/dev/null -python2 get-pip.py &>/dev/null -apt-get install libffi-dev libzbar-dev libzbar0 -y &>/dev/null -apt-get install python2-dev libssl-dev libcurl4-openssl-dev libjpeg-dev -y &>/dev/null -msg_ok "Installed Python" - -msg_info "Installing MotionEye" -apt-get update &>/dev/null -sudo pip install motioneye &>/dev/null -mkdir -p /etc/motioneye -cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf -mkdir -p /var/lib/motioneye -msg_ok "Installed MotionEye" - -msg_info "Creating Service" -cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service &>/dev/null -systemctl enable motioneye &>/dev/null -systemctl start motioneye -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/motioneye-v5-install.sh b/install/motioneye-v5-install.sh index 77a8f558..772149a2 100644 --- a/install/motioneye-v5-install.sh +++ b/install/motioneye-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -123,12 +119,11 @@ $STD systemctl enable motioneye systemctl start motioneye msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -141,10 +136,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/mqtt-install.sh b/install/mqtt-install.sh deleted file mode 100644 index c9e90259..00000000 --- a/install/mqtt-install.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Mosquitto MQTT Broker" -wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key &>/dev/null -apt-key add mosquitto-repo.gpg.key &>/dev/null -cd /etc/apt/sources.list.d/ -wget http://repo.mosquitto.org/debian/mosquitto-bullseye.list &>/dev/null -apt-get update >/dev/null -apt-get -y install mosquitto &>/dev/null -apt-get -y install mosquitto-clients &>/dev/null -msg_ok "Installed Mosquitto MQTT Broker" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/mqtt-v5-install.sh b/install/mqtt-v5-install.sh index 7b2893bb..867fb2bb 100644 --- a/install/mqtt-v5-install.sh +++ b/install/mqtt-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -100,12 +96,11 @@ $STD apt-get -y install mosquitto $STD apt-get -y install mosquitto-clients msg_ok "Installed Mosquitto MQTT Broker" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -118,10 +113,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/n8n-install.sh b/install/n8n-install.sh deleted file mode 100644 index c700bdb0..00000000 --- a/install/n8n-install.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -sL https://deb.nodesource.com/setup_16.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing n8n (Patience)" -npm install --global n8n &>/dev/null -msg_ok "Installed n8n" - -msg_info "Creating Service" -cat </etc/systemd/system/n8n.service -[Unit] -Description=n8n - -[Service] -Type=simple -ExecStart=n8n start -[Install] -WantedBy=multi-user.target -EOF -sudo systemctl start n8n &>/dev/null -sudo systemctl enable n8n &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/n8n-v5-install.sh b/install/n8n-v5-install.sh index e03de40c..d72a9c2d 100644 --- a/install/n8n-v5-install.sh +++ b/install/n8n-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -115,12 +111,11 @@ EOF $STD systemctl enable --now n8n msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -133,10 +128,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/navidrome-install.sh b/install/navidrome-install.sh deleted file mode 100644 index e746cf32..00000000 --- a/install/navidrome-install.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies (patience)" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y ffmpeg &>/dev/null -msg_ok "Installed Dependencies" - -RELEASE=$(curl -s https://api.github.com/repos/navidrome/navidrome/releases/latest | - grep "tag_name" | - awk '{print substr($2, 3, length($2)-4) }') - -msg_info "Installing Navidrome" -sudo install -d -o root -g root /opt/navidrome -sudo install -d -o root -g root /var/lib/navidrome -wget https://github.com/navidrome/navidrome/releases/download/v${RELEASE}/navidrome_${RELEASE}_Linux_x86_64.tar.gz -O Navidrome.tar.gz &>/dev/null -sudo tar -xvzf Navidrome.tar.gz -C /opt/navidrome/ &>/dev/null -sudo chown -R root:root /opt/navidrome -mkdir -p /music -cat </var/lib/navidrome/navidrome.toml -MusicFolder = '/music' -EOF -msg_ok "Installed Navidrome" - -msg_info "Creating Service" -service_path="/etc/systemd/system/navidrome.service" - -echo "[Unit] -Description=Navidrome Music Server and Streamer compatible with Subsonic/Airsonic -After=remote-fs.target network.target -AssertPathExists=/var/lib/navidrome - -[Service] -User=root -Group=root -Type=simple -ExecStart=/opt/navidrome/navidrome --configfile '/var/lib/navidrome/navidrome.toml' -WorkingDirectory=/var/lib/navidrome -TimeoutStopSec=20 -KillMode=process -Restart=on-failure -DevicePolicy=closed -NoNewPrivileges=yes -PrivateTmp=yes -PrivateUsers=yes -ProtectControlGroups=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes -RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 -RestrictNamespaces=yes -RestrictRealtime=yes -SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap -ReadWritePaths=/var/lib/navidrome -ProtectSystem=full - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl daemon-reload -systemctl enable --now navidrome.service &>/dev/null - -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -rm -rf /root/Navidrome.tar.gz -msg_ok "Cleaned" diff --git a/install/navidrome-v5-install.sh b/install/navidrome-v5-install.sh index c035e760..519177bd 100644 --- a/install/navidrome-v5-install.sh +++ b/install/navidrome-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -143,11 +139,11 @@ $STD systemctl enable --now navidrome.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -160,10 +156,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/nextcloudpi-install.sh b/install/nextcloudpi-install.sh deleted file mode 100644 index 5ea6ffa3..00000000 --- a/install/nextcloudpi-install.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing NextCloudPi (Patience)" -curl -sSL https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/install.sh | bash &>/dev/null -sed -i "s/3 => 'nextcloudpi.lan',/3 => '0.0.0.0',/g" /var/www/nextcloud/config/config.php -sudo service apache2 restart -msg_ok "Installed NextCloudPi" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/nextcloudpi-v5-install.sh b/install/nextcloudpi-v5-install.sh index e0cb1628..fc3f7c74 100644 --- a/install/nextcloudpi-v5-install.sh +++ b/install/nextcloudpi-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -95,11 +91,11 @@ sed -i '{s|root:/usr/sbin/nologin|root:/bin/bash|g}' /etc/passwd service apache2 restart msg_ok "Installed NextCloudPi" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -112,10 +108,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/nginx-proxy-manager-install.sh b/install/nginx-proxy-manager-install.sh deleted file mode 100644 index c2dba3e7..00000000 --- a/install/nginx-proxy-manager-install.sh +++ /dev/null @@ -1,280 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get update &>/dev/null -apt-get -y install \ - sudo \ - curl \ - gnupg \ - make \ - g++ \ - gcc \ - ca-certificates \ - apache2-utils \ - logrotate \ - build-essential \ - python3-dev \ - git \ - lsb-release &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Python" -apt-get install -y -q --no-install-recommends python3 python3-pip python3-venv &>/dev/null -pip3 install --upgrade setuptools &>/dev/null -pip3 install --upgrade pip &>/dev/null -python3 -m venv /opt/certbot/ &>/dev/null -if [ "$(getconf LONG_BIT)" = "32" ]; then - python3 -m pip install --no-cache-dir -U cryptography==3.3.2 &>/dev/null -fi -python3 -m pip install --no-cache-dir cffi certbot &>/dev/null -msg_ok "Installed Python" - -msg_info "Installing Openresty" -wget -q -O - https://openresty.org/package/pubkey.gpg | apt-key add - &>/dev/null -codename=$(grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release) &>/dev/null -echo "deb http://openresty.org/package/debian $codename openresty" | tee /etc/apt/sources.list.d/openresty.list &>/dev/null -apt-get -y update &>/dev/null -apt-get -y install --no-install-recommends openresty &>/dev/null -msg_ok "Installed Openresty" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Yarn" -npm install --global yarn &>/dev/null -msg_ok "Installed Yarn" - -RELEASE=$(curl -s https://api.github.com/repos/NginxProxyManager/nginx-proxy-manager/releases/latest | - grep "tag_name" | - awk '{print substr($2, 3, length($2)-4) }') - -msg_info "Downloading Nginx Proxy Manager v${RELEASE}" -wget -q https://codeload.github.com/NginxProxyManager/nginx-proxy-manager/tar.gz/v${RELEASE} -O - | tar -xz &>/dev/null -cd ./nginx-proxy-manager-${RELEASE} -msg_ok "Downloaded Nginx Proxy Manager v${RELEASE}" - -msg_info "Setting up Enviroment" -ln -sf /usr/bin/python3 /usr/bin/python -ln -sf /usr/bin/certbot /opt/certbot/bin/certbot -ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx -ln -sf /usr/local/openresty/nginx/ /etc/nginx - -sed -i "s+0.0.0+${RELEASE}+g" backend/package.json -sed -i "s+0.0.0+${RELEASE}+g" frontend/package.json - -sed -i 's+^daemon+#daemon+g' docker/rootfs/etc/nginx/nginx.conf -NGINX_CONFS=$(find "$(pwd)" -type f -name "*.conf") -for NGINX_CONF in $NGINX_CONFS; do - sed -i 's+include conf.d+include /etc/nginx/conf.d+g' "$NGINX_CONF" -done - -mkdir -p /var/www/html /etc/nginx/logs -cp -r docker/rootfs/var/www/html/* /var/www/html/ -cp -r docker/rootfs/etc/nginx/* /etc/nginx/ -cp docker/rootfs/etc/letsencrypt.ini /etc/letsencrypt.ini -cp docker/rootfs/etc/logrotate.d/nginx-proxy-manager /etc/logrotate.d/nginx-proxy-manager -ln -sf /etc/nginx/nginx.conf /etc/nginx/conf/nginx.conf -rm -f /etc/nginx/conf.d/dev.conf - -mkdir -p /tmp/nginx/body \ - /run/nginx \ - /data/nginx \ - /data/custom_ssl \ - /data/logs \ - /data/access \ - /data/nginx/default_host \ - /data/nginx/default_www \ - /data/nginx/proxy_host \ - /data/nginx/redirection_host \ - /data/nginx/stream \ - /data/nginx/dead_host \ - /data/nginx/temp \ - /var/lib/nginx/cache/public \ - /var/lib/nginx/cache/private \ - /var/cache/nginx/proxy_temp - -chmod -R 777 /var/cache/nginx -chown root /tmp/nginx - -echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print ($2 ~ ":")? "["$2"]": $2}' /etc/resolv.conf);" >/etc/nginx/conf.d/include/resolvers.conf - -if [ ! -f /data/nginx/dummycert.pem ] || [ ! -f /data/nginx/dummykey.pem ]; then - echo -en "${GN} Generating dummy SSL Certificate... " - openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj "/O=Nginx Proxy Manager/OU=Dummy Certificate/CN=localhost" -keyout /data/nginx/dummykey.pem -out /data/nginx/dummycert.pem &>/dev/null -fi - -mkdir -p /app/global /app/frontend/images -cp -r backend/* /app -cp -r global/* /app/global -msg_ok "Set up Enviroment" - -msg_info "Building Frontend" -cd ./frontend -export NODE_ENV=development -yarn install --network-timeout=30000 &>/dev/null -yarn build &>/dev/null -cp -r dist/* /app/frontend -cp -r app-images/* /app/frontend/images -msg_ok "Built Frontend" - -msg_info "Initializing Backend" -rm -rf /app/config/default.json &>/dev/null -if [ ! -f /app/config/production.json ]; then - cat <<'EOF' >/app/config/production.json -{ - "database": { - "engine": "knex-native", - "knex": { - "client": "sqlite3", - "connection": { - "filename": "/data/database.sqlite" - } - } - } -} -EOF -fi -cd /app -export NODE_ENV=development -yarn install --network-timeout=30000 &>/dev/null -msg_ok "Initialized Backend" - -msg_info "Creating Service" -cat <<'EOF' >/lib/systemd/system/npm.service -[Unit] -Description=Nginx Proxy Manager -After=network.target -Wants=openresty.service - -[Service] -Type=simple -Environment=NODE_ENV=production -ExecStartPre=-mkdir -p /tmp/nginx/body /data/letsencrypt-acme-challenge -ExecStart=/usr/bin/node index.js --abort_on_uncaught_exception --max_old_space_size=250 -WorkingDirectory=/app -Restart=on-failure - -[Install] -WantedBy=multi-user.target -EOF -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Starting Services" -systemctl enable npm &>/dev/null -systemctl start openresty -systemctl start npm -msg_ok "Started Services" - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/nginxproxymanager-v5-install.sh b/install/nginxproxymanager-v5-install.sh index eacab824..ae45c980 100644 --- a/install/nginxproxymanager-v5-install.sh +++ b/install/nginxproxymanager-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -247,12 +243,11 @@ WantedBy=multi-user.target EOF msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -265,10 +260,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Starting Services" $STD systemctl enable --now openresty diff --git a/install/nocodb-install.sh b/install/nocodb-install.sh deleted file mode 100644 index 491eb153..00000000 --- a/install/nocodb-install.sh +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -sudo apt-get install -y nodejs git make g++ gcc &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing NocoDB" -git clone https://github.com/nocodb/nocodb-seed &>/dev/null -mv nocodb-seed /opt/nocodb -cd /opt/nocodb -npm install &>/dev/null -msg_ok "Installed NocoDB" - -msg_info "Creating Service" -service_path="/etc/systemd/system/nocodb.service" -echo "[Unit] -Description=nocodb - -[Service] -Type=simple -Restart=always -User=root -WorkingDirectory=/opt/nocodb -ExecStart=/usr/bin/npm start - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now nocodb.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/nocodb-v5-install.sh b/install/nocodb-v5-install.sh index 1700c038..340863f9 100644 --- a/install/nocodb-v5-install.sh +++ b/install/nocodb-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -122,12 +118,11 @@ WantedBy=multi-user.target" >$service_path systemctl enable --now nocodb.service &>/dev/null msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -140,10 +135,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/node-red-install.sh b/install/node-red-install.sh deleted file mode 100644 index 85df743b..00000000 --- a/install/node-red-install.sh +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Node-Red" -npm install -g --unsafe-perm node-red &>/dev/null -msg_ok "Installed Node-Red" - -msg_info "Creating Service" -service_path="/etc/systemd/system/nodered.service" -echo "[Unit] -Description=Node-RED -After=syslog.target network.target - -[Service] -ExecStart=/usr/bin/node-red --max-old-space-size=128 -v -Restart=on-failure -KillSignal=SIGINT - -SyslogIdentifier=node-red -StandardOutput=syslog - -WorkingDirectory=/root/ -User=root -Group=root - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now nodered.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/node-red-v5-install.sh b/install/node-red-v5-install.sh index 20359660..b9cb9bc9 100644 --- a/install/node-red-v5-install.sh +++ b/install/node-red-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -125,12 +121,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now nodered.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -143,10 +138,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/omada-install.sh b/install/omada-install.sh deleted file mode 100644 index bec67474..00000000 --- a/install/omada-install.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get -y install curl &>/dev/null -apt-get -y install sudo &>/dev/null -apt-get -y install gnupg &>/dev/null -apt-get -y install openjdk-8-jre-headless &>/dev/null -apt-get -y install jsvc &>/dev/null -wget -qL https://repo.mongodb.org/apt/ubuntu/dists/bionic/mongodb-org/3.6/multiverse/binary-amd64/mongodb-org-server_3.6.23_amd64.deb -sudo dpkg -i mongodb-org-server_3.6.23_amd64.deb &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Omada Controller v5.6.3" -wget -qL https://static.tp-link.com/upload/software/2022/202211/20221121/Omada_SDN_Controller_v5.7.4_Linux_x64.deb -sudo dpkg -i Omada_SDN_Controller_v5.7.4_Linux_x64.deb &>/dev/null -msg_ok "Installed Omada Controller" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/omada-v5-install.sh b/install/omada-v5-install.sh index 9dabc392..79fd4e5f 100644 --- a/install/omada-v5-install.sh +++ b/install/omada-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -99,11 +95,11 @@ wget -qL https://static.tp-link.com/upload/software/2022/202211/20221121/Omada_S $STD dpkg -i Omada_SDN_Controller_v5.7.4_Linux_x64.deb msg_ok "Installed Omada Controller" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -116,10 +112,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Omada_SDN_Controller_v5.7.4_Linux_x64.deb mongodb-org-server_3.6.23_amd64.deb diff --git a/install/omv-install.sh b/install/omv-install.sh deleted file mode 100644 index 0a98be6f..00000000 --- a/install/omv-install.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -export DEBIAN_FRONTEND=noninteractive -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing OpenMediaVault (Patience)" -wget -O "/etc/apt/trusted.gpg.d/openmediavault-archive-keyring.asc" https://packages.openmediavault.org/public/archive.key &>/dev/null -apt-key add "/etc/apt/trusted.gpg.d/openmediavault-archive-keyring.asc" &>/dev/null - -cat <>/etc/apt/sources.list.d/openmediavault.list -deb https://packages.openmediavault.org/public shaitan main -# deb https://downloads.sourceforge.net/project/openmediavault/packages shaitan main -## Uncomment the following line to add software from the proposed repository. -# deb https://packages.openmediavault.org/public shaitan-proposed main -# deb https://downloads.sourceforge.net/project/openmediavault/packages shaitan-proposed main -## This software is not part of OpenMediaVault, but is offered by third-party -## developers as a service to OpenMediaVault users. -# deb https://packages.openmediavault.org/public shaitan partner -# deb https://downloads.sourceforge.net/project/openmediavault/packages shaitan partner -EOF -apt-get update &>/dev/null -apt-get -y install openmediavault-keyring &>/dev/null -apt-get --yes --auto-remove --show-upgraded --allow-downgrades --allow-change-held-packages --no-install-recommends install openmediavault &>/dev/null -omv-confdbadm populate -msg_ok "Installed OpenMediaVault" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/omv-v5-install.sh b/install/omv-v5-install.sh index 19e6c069..90623f7c 100644 --- a/install/omv-v5-install.sh +++ b/install/omv-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi export DEBIAN_FRONTEND=noninteractive YW=$(echo "\033[33m") @@ -10,26 +11,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -111,11 +107,11 @@ $STD apt-get --yes --auto-remove --show-upgraded --allow-downgrades --allow-chan omv-confdbadm populate msg_ok "Installed OpenMediaVault" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -128,10 +124,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/openhab-install.sh b/install/openhab-install.sh deleted file mode 100644 index ef7dc48f..00000000 --- a/install/openhab-install.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -apt-get install -y apt-transport-https &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Azul Zulu" -apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9 &>/dev/null -curl -O https://cdn.azul.com/zulu/bin/zulu-repo_1.0.0-3_all.deb &>/dev/null -apt-get install ./zulu-repo_1.0.0-3_all.deb &>/dev/null -apt-get update &>/dev/null -apt-get -y install zulu11-jdk &>/dev/null -msg_ok "Installed Azul Zulu" - -msg_info "Installing openHAB" -curl -fsSL "https://openhab.jfrog.io/artifactory/api/gpg/key/public" | gpg --dearmor >openhab.gpg -mv openhab.gpg /usr/share/keyrings -chmod u=rw,g=r,o=r /usr/share/keyrings/openhab.gpg -echo 'deb [signed-by=/usr/share/keyrings/openhab.gpg] https://openhab.jfrog.io/artifactory/openhab-linuxpkg stable main' | tee /etc/apt/sources.list.d/openhab.list &>/dev/null -apt update &>/dev/null -apt-get -y install openhab &>/dev/null -systemctl daemon-reload -systemctl enable openhab.service &>/dev/null -systemctl start openhab.service -msg_ok "Installed openHAB" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/openhab-v5-install.sh b/install/openhab-v5-install.sh index 4ef6fe28..ca7a23d9 100644 --- a/install/openhab-v5-install.sh +++ b/install/openhab-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -110,11 +106,11 @@ systemctl daemon-reload $STD systemctl enable --now openhab.service msg_ok "Installed openHAB" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -127,10 +123,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/paperless-ngx-install.sh b/install/paperless-ngx-install.sh deleted file mode 100644 index 87d509eb..00000000 --- a/install/paperless-ngx-install.sh +++ /dev/null @@ -1,287 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Paperless-ngx Dependencies" -apt-get install -y --no-install-recommends \ - python3 \ - python3-pip \ - python3-dev \ - imagemagick \ - fonts-liberation \ - optipng \ - gnupg \ - libpq-dev \ - libmagic-dev \ - mime-support \ - libzbar0 \ - poppler-utils \ - default-libmysqlclient-dev \ - sudo &>/dev/null -msg_ok "Installed Paperless-ngx Dependencies" - -msg_info "Installing OCR Dependencies" -apt-get install -y --no-install-recommends \ - unpaper \ - ghostscript \ - icc-profiles-free \ - qpdf \ - liblept5 \ - libxml2 \ - pngquant \ - zlib1g \ - tesseract-ocr \ - tesseract-ocr-eng &>/dev/null -msg_ok "Installed OCR Dependencies" - -msg_info "Installing Extra Dependencies" -apt-get install -y --no-install-recommends \ - redis \ - postgresql \ - build-essential \ - python3-setuptools \ - python3-wheel &>/dev/null -msg_ok "Installed Extra Dependencies" - -msg_info "Installing JBIG2" -apt-get install -y --no-install-recommends \ - automake \ - libtool \ - pkg-config \ - git \ - curl \ - libtiff-dev \ - libpng-dev \ - libleptonica-dev &>/dev/null - -git clone https://github.com/agl/jbig2enc /opt/jbig2enc &>/dev/null -cd /opt/jbig2enc -/bin/bash -c "./autogen.sh" &>/dev/null && - /bin/bash -c "./configure && make" &>/dev/null && - /bin/bash -c "make install" &>/dev/null -rm -rf /opt/jbig2enc -msg_ok "Installed JBIG2" - -msg_info "Downloading Paperless-ngx" -Paperlessngx=$(wget -q https://github.com/paperless-ngx/paperless-ngx/releases/latest -O - | grep "title>Release" | cut -d " " -f 5) -cd /opt && - wget https://github.com/paperless-ngx/paperless-ngx/releases/download/$Paperlessngx/paperless-ngx-$Paperlessngx.tar.xz &>/dev/null && - tar -xf paperless-ngx-$Paperlessngx.tar.xz -C /opt/ &>/dev/null && - mv paperless-ngx paperless && - rm paperless-ngx-$Paperlessngx.tar.xz -cd /opt/paperless - -## python 3.10+ doesn't like the '-e', so we remove it from this the requirements file -sed -i -e 's|-e git+https://github.com/paperless-ngx/django-q.git|git+https://github.com/paperless-ngx/django-q.git|' /opt/paperless/requirements.txt - -/usr/bin/python3 -m pip install --upgrade pip &>/dev/null -/usr/bin/python3 -m pip install -r requirements.txt &>/dev/null -msg_ok "Downloaded Paperless-ngx" - -msg_info "Setting up database" -DB_USER=paperless -DB_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)" -DB_NAME=paperlessdb - -sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" &>/dev/null -sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;" &>/dev/null - -echo "Paperless-ngx Database User" >>~/paperless.creds -echo $DB_USER >>~/paperless.creds -echo "Paperless-ngx Database Password" >>~/paperless.creds -echo $DB_PASS >>~/paperless.creds -echo "Paperless-ngx Database Name" >>~/paperless.creds -echo $DB_NAME >>~/paperless.creds - -/bin/bash -c "mkdir -p {consume,media}" - -sed -i -e 's|#PAPERLESS_DBNAME=paperless|PAPERLESS_DBNAME=paperlessdb|' /opt/paperless/paperless.conf -sed -i -e "s|#PAPERLESS_DBPASS=paperless|PAPERLESS_DBPASS=$DB_PASS|" /opt/paperless/paperless.conf -SECRET_KEY="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)" -sed -i -e "s|#PAPERLESS_SECRET_KEY=change-me|PAPERLESS_SECRET_KEY=$SECRET_KEY|" /opt/paperless/paperless.conf - -cd /opt/paperless/src -/usr/bin/python3 manage.py migrate &>/dev/null -msg_ok "Set up database" - -msg_info "Setting up admin Paperless-ngx User & Password" -## From https://github.com/linuxserver/docker-paperless-ngx/blob/main/root/etc/cont-init.d/99-migrations -cat <>~/paperless.creds -echo "Paperless-ngx WebUI User" >>~/paperless.creds -echo admin >>~/paperless.creds -echo "Paperless-ngx WebUI Password" >>~/paperless.creds -echo $DB_PASS >>~/paperless.creds -msg_ok "Set up admin Paperless-ngx User & Password" - -cat </etc/systemd/system/paperless-scheduler.service -[Unit] -Description=Paperless Celery beat -Requires=redis.service - -[Service] -WorkingDirectory=/opt/paperless/src -ExecStart=celery --app paperless beat --loglevel INFO - -[Install] -WantedBy=multi-user.target -EOF - -cat </etc/systemd/system/paperless-task-queue.service -[Unit] -Description=Paperless Celery Workers -Requires=redis.service - -[Service] -WorkingDirectory=/opt/paperless/src -ExecStart=celery --app paperless worker --loglevel INFO - -[Install] -WantedBy=multi-user.target -EOF - -cat </etc/systemd/system/paperless-consumer.service -[Unit] -Description=Paperless consumer -Requires=redis.service - -[Service] -WorkingDirectory=/opt/paperless/src -ExecStart=python3 manage.py document_consumer - -[Install] -WantedBy=multi-user.target -EOF - -cat </etc/systemd/system/paperless-webserver.service -[Unit] -Description=Paperless webserver -After=network.target -Wants=network.target -Requires=redis.service - -[Service] -WorkingDirectory=/opt/paperless/src -ExecStart=/usr/local/bin/gunicorn -c /opt/paperless/gunicorn.conf.py paperless.asgi:application - -[Install] -WantedBy=multi-user.target -EOF - -sed -i -e 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml - -systemctl daemon-reload -systemctl enable --now paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue.service &>/dev/null - -msg_ok "Finished installing Paperless-ngx" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/paperless-ngx-v5-install.sh b/install/paperless-ngx-v5-install.sh index 2d3864e0..3eb5cb42 100644 --- a/install/paperless-ngx-v5-install.sh +++ b/install/paperless-ngx-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,7 +10,6 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" @@ -74,7 +74,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -267,12 +267,11 @@ $STD systemctl enable --now paperless-consumer paperless-webserver paperless-sch msg_ok "Created Services" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -285,6 +284,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/photoprism-install.sh b/install/photoprism-install.sh deleted file mode 100644 index 523bdf41..00000000 --- a/install/photoprism-install.sh +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -AVX=$(grep -o -m1 'avx[^ ]*' /proc/cpuinfo) -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies (Patience)" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gcc &>/dev/null -apt-get install -y g++ &>/dev/null -apt-get install -y git &>/dev/null -apt-get install -y gnupg &>/dev/null -apt-get install -y make &>/dev/null -apt-get install -y zip &>/dev/null -apt-get install -y unzip &>/dev/null -apt-get install -y exiftool &>/dev/null -apt-get install -y ffmpeg &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -sL https://deb.nodesource.com/setup_18.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Golang (Patience)" -wget https://golang.org/dl/go1.19.3.linux-amd64.tar.gz &>/dev/null -tar -xzf go1.19.3.linux-amd64.tar.gz -C /usr/local &>/dev/null -ln -s /usr/local/go/bin/go /usr/local/bin/go &>/dev/null -go install github.com/tianon/gosu@latest &>/dev/null -go install golang.org/x/tools/cmd/goimports@latest &>/dev/null -go install github.com/psampaz/go-mod-outdated@latest &>/dev/null -go install github.com/dsoprea/go-exif/v3/command/exif-read-tool@latest &>/dev/null -go install github.com/mikefarah/yq/v4@latest &>/dev/null -go install github.com/kyoh86/richgo@latest &>/dev/null -cp /root/go/bin/* /usr/local/go/bin/ -cp /usr/local/go/bin/richgo /usr/local/bin/richgo -cp /usr/local/go/bin/gosu /usr/local/sbin/gosu -chown root:root /usr/local/sbin/gosu -chmod 755 /usr/local/sbin/gosu -msg_ok "Installed Golang" - -msg_info "Installing Tensorflow" -if [[ "$AVX" =~ avx2 ]]; then - wget https://dl.photoprism.org/tensorflow/linux/libtensorflow-linux-avx2-1.15.2.tar.gz &>/dev/null - tar -C /usr/local -xzf libtensorflow-linux-avx2-1.15.2.tar.gz &>/dev/null -elif [[ "$AVX" =~ avx ]]; then - wget https://dl.photoprism.org/tensorflow/linux/libtensorflow-linux-avx-1.15.2.tar.gz &>/dev/null - tar -C /usr/local -xzf libtensorflow-linux-avx-1.15.2.tar.gz &>/dev/null -else - wget https://dl.photoprism.org/tensorflow/linux/libtensorflow-linux-cpu-1.15.2.tar.gz &>/dev/null - tar -C /usr/local -xzf libtensorflow-linux-cpu-1.15.2.tar.gz &>/dev/null -fi -ldconfig &>/dev/null -msg_ok "Installed Tensorflow" - -msg_info "Cloning PhotoPrism" -mkdir -p /opt/photoprism/bin -mkdir -p /var/lib/photoprism/storage -git clone https://github.com/photoprism/photoprism.git &>/dev/null -cd photoprism -git checkout release &>/dev/null -msg_ok "Cloned PhotoPrism" - -msg_info "Building PhotoPrism (Patience)" -NODE_OPTIONS=--max_old_space_size=2048 make all &>/dev/null -./scripts/build.sh prod /opt/photoprism/bin/photoprism &>/dev/null -cp -r assets/ /opt/photoprism/ &>/dev/null -msg_ok "Built PhotoPrism" - -env_path="/var/lib/photoprism/.env" -echo " -PHOTOPRISM_AUTH_MODE='password' -PHOTOPRISM_ADMIN_PASSWORD='changeme' -PHOTOPRISM_HTTP_HOST='0.0.0.0' -PHOTOPRISM_HTTP_PORT='2342' -PHOTOPRISM_SITE_CAPTION='https://tteck.github.io/Proxmox/' -PHOTOPRISM_STORAGE_PATH='/var/lib/photoprism/storage' -PHOTOPRISM_ORIGINALS_PATH='/var/lib/photoprism/photos/Originals' -PHOTOPRISM_IMPORT_PATH='/var/lib/photoprism/photos/Import' -" >$env_path - -msg_info "Creating Service" -service_path="/etc/systemd/system/photoprism.service" - -echo "[Unit] -Description=PhotoPrism service -After=network.target - -[Service] -Type=forking -User=root -WorkingDirectory=/opt/photoprism -EnvironmentFile=/var/lib/photoprism/.env -ExecStart=/opt/photoprism/bin/photoprism up -d -ExecStop=/opt/photoprism/bin/photoprism down - -[Install] -WantedBy=multi-user.target" >$service_path -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -rm -rf /var/{cache,log}/* \ - /photoprism \ - /go1.19.3.linux-amd64.tar.gz \ - /libtensorflow-linux-avx2-1.15.2.tar.gz \ - /libtensorflow-linux-avx-1.15.2.tar.gz \ - /libtensorflow-linux-cpu-1.15.2.tar.gz -msg_ok "Cleaned" - -msg_info "Starting PhotoPrism" -systemctl enable --now photoprism &>/dev/null diff --git a/install/photoprism-v5-install.sh b/install/photoprism-v5-install.sh index ca60b3df..48584dcb 100644 --- a/install/photoprism-v5-install.sh +++ b/install/photoprism-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi AVX=$(grep -o -m1 'avx[^ ]*' /proc/cpuinfo) YW=$(echo "\033[33m") @@ -10,26 +11,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -50,15 +43,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -75,7 +71,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -183,12 +179,11 @@ ExecStop=/opt/photoprism/bin/photoprism down WantedBy=multi-user.target" >$service_path msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -201,10 +196,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/pihole-install.sh b/install/pihole-install.sh deleted file mode 100644 index 3b7de2a2..00000000 --- a/install/pihole-install.sh +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -export DEBIAN_FRONTEND=noninteractive -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y ufw &>/dev/null -apt-get install -y ntp &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Pi-hole" -mkdir -p /etc/pihole/ -cat </etc/pihole/setupVars.conf -PIHOLE_INTERFACE=eth0 -PIHOLE_DNS_1=8.8.8.8 -PIHOLE_DNS_2=8.8.4.4 -QUERY_LOGGING=true -INSTALL_WEB_SERVER=true -INSTALL_WEB_INTERFACE=true -LIGHTTPD_ENABLED=true -CACHE_SIZE=10000 -DNS_FQDN_REQUIRED=true -DNS_BOGUS_PRIV=true -DNSMASQ_LISTENING=local -WEBPASSWORD=$(openssl rand -base64 48) -BLOCKING_ENABLED=true -EOF - -curl -sSL https://install.pi-hole.net | bash /dev/stdin --unattended &>/dev/null -msg_ok "Installed Pi-hole" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/pihole-v5-install.sh b/install/pihole-v5-install.sh index 2133980b..c1d93dd4 100644 --- a/install/pihole-v5-install.sh +++ b/install/pihole-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi export DEBIAN_FRONTEND=noninteractive YW=$(echo "\033[33m") @@ -10,26 +11,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -50,15 +43,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -75,7 +71,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -116,12 +112,11 @@ EOF $STD bash <(curl -fsSL https://install.pi-hole.net) /dev/stdin --unattended msg_ok "Installed Pi-hole" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -134,10 +129,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/plex-install.sh b/install/plex-install.sh deleted file mode 100644 index dc5ba5e2..00000000 --- a/install/plex-install.sh +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -msg_ok "Installed Dependencies" - -if [[ -z "$(grep -w "100000" /proc/self/uid_map)" ]]; then - msg_info "Setting Up Hardware Acceleration" - apt-get -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - beignet-opencl-icd &>/dev/null - - /bin/chgrp video /dev/dri - /bin/chmod 755 /dev/dri - /bin/chmod 660 /dev/dri/* - msg_ok "Set Up Hardware Acceleration" -fi - -msg_info "Setting Up Plex Media Server Repository" -wget -q https://downloads.plex.tv/plex-keys/PlexSign.key -O - | sudo apt-key add - &>/dev/null -echo "deb [arch=$(dpkg --print-architecture)] https://downloads.plex.tv/repo/deb/ public main" | tee /etc/apt/sources.list.d/plexmediaserver.list &>/dev/null -msg_ok "Set Up Plex Media Server Repository" - -msg_info "Installing Plex Media Server" -apt-get update &>/dev/null -apt-get -o Dpkg::Options::="--force-confold" install -y plexmediaserver &>/dev/null -msg_ok "Installed Plex Media Server" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/plex-v5-install.sh b/install/plex-v5-install.sh index 93bb66d3..b9a46f66 100644 --- a/install/plex-v5-install.sh +++ b/install/plex-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -113,11 +109,11 @@ $STD apt-get update $STD apt-get -o Dpkg::Options::="--force-confold" install -y plexmediaserver msg_ok "Installed Plex Media Server" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -130,10 +126,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/podman-homeassistant-install.sh b/install/podman-homeassistant-install.sh deleted file mode 100644 index 3cd1679d..00000000 --- a/install/podman-homeassistant-install.sh +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Podman" -apt-get -y install podman &>/dev/null -systemctl enable --now podman.socket &>/dev/null -msg_ok "Installed Podman" - -read -r -p "Would you like to add Yacht (Semifunctional)? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - YACHT="Y" -else - YACHT="N" -fi - -if [[ $YACHT == "Y" ]]; then - msg_info "Pulling Yacht Image" - podman pull docker.io/selfhostedpro/yacht:latest &>/dev/null - msg_ok "Pulled Yacht Image" - - msg_info "Installing Yacht" - podman volume create yacht >/dev/null - podman run -d \ - --privileged \ - --name yacht \ - --restart always \ - -v /var/run/podman/podman.sock:/var/run/docker.sock \ - -v yacht:/config \ - -v /etc/localtime:/etc/localtime:ro \ - -v /etc/timezone:/etc/timezone:ro \ - -p 8000:8000 \ - selfhostedpro/yacht:latest &>/dev/null - podman generate systemd \ - --new --name yacht \ - >/etc/systemd/system/yacht.service - systemctl enable yacht &>/dev/null - msg_ok "Installed Yacht" -fi -msg_info "Pulling Home Assistant Image" -podman pull docker.io/homeassistant/home-assistant:stable &>/dev/null -msg_ok "Pulled Home Assistant Image" - -msg_info "Installing Home Assistant" -podman volume create hass_config >/dev/null -podman run -d \ - --privileged \ - --name homeassistant \ - --restart unless-stopped \ - -v /dev:/dev \ - -v hass_config:/config \ - -v /etc/localtime:/etc/localtime:ro \ - -v /etc/timezone:/etc/timezone:ro \ - --net=host \ - homeassistant/home-assistant:stable &>/dev/null -podman generate systemd \ - --new --name homeassistant \ - >/etc/systemd/system/homeassistant.service -systemctl enable homeassistant &>/dev/null -msg_ok "Installed Home Assistant" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/podman-homeassistant-v5-install.sh b/install/podman-homeassistant-v5-install.sh index e7831240..277afab7 100644 --- a/install/podman-homeassistant-v5-install.sh +++ b/install/podman-homeassistant-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -115,12 +111,11 @@ podman generate systemd \ $STD systemctl enable --now homeassistant msg_ok "Installed Home Assistant" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -133,10 +128,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/podman-v5-install.sh b/install/podman-v5-install.sh index f893c4d0..98928d14 100644 --- a/install/podman-v5-install.sh +++ b/install/podman-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -94,11 +90,11 @@ $STD systemctl enable --now podman.socket echo -e 'unqualified-search-registries=["docker.io"]' >> /etc/containers/registries.conf msg_ok "Installed Podman" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -111,10 +107,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/postgresql-install.sh b/install/postgresql-install.sh deleted file mode 100644 index 4e0c8849..00000000 --- a/install/postgresql-install.sh +++ /dev/null @@ -1,243 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg2 &>/dev/null -apt-get install -y lsb-release &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up PostgreSQL Repository" -sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' &>/dev/null -wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - &>/dev/null -msg_ok "Setup PostgreSQL Repository" - -msg_info "Installing PostgreSQL" -apt-get update &>/dev/null -apt-get install -y postgresql &>/dev/null - -cat </etc/postgresql/15/main/pg_hba.conf -# PostgreSQL Client Authentication Configuration File -local all postgres peer -# TYPE DATABASE USER ADDRESS METHOD -# "local" is for Unix domain socket connections only -local all all peer -# IPv4 local connections: -host all all 127.0.0.1/32 scram-sha-256 -host all all 0.0.0.0/24 md5 -# IPv6 local connections: -host all all ::1/128 scram-sha-256 -host all all 0.0.0.0/0 md5 -# Allow replication connections from localhost, by a user with the -# replication privilege. -local replication all peer -host replication all 127.0.0.1/32 scram-sha-256 -host replication all ::1/128 scram-sha-256 -EOF - -cat </etc/postgresql/15/main/postgresql.conf -# ----------------------------- -# PostgreSQL configuration file -# ----------------------------- - -#------------------------------------------------------------------------------ -# FILE LOCATIONS -#------------------------------------------------------------------------------ - -data_directory = '/var/lib/postgresql/15/main' -hba_file = '/etc/postgresql/15/main/pg_hba.conf' -ident_file = '/etc/postgresql/15/main/pg_ident.conf' -external_pid_file = '/var/run/postgresql/15-main.pid' - -#------------------------------------------------------------------------------ -# CONNECTIONS AND AUTHENTICATION -#------------------------------------------------------------------------------ - -# - Connection Settings - - -listen_addresses = '*' -port = 5432 -max_connections = 100 -unix_socket_directories = '/var/run/postgresql' - -# - SSL - - -ssl = on -ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem' -ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key' - -#------------------------------------------------------------------------------ -# RESOURCE USAGE (except WAL) -#------------------------------------------------------------------------------ - -shared_buffers = 128MB -dynamic_shared_memory_type = posix - -#------------------------------------------------------------------------------ -# WRITE-AHEAD LOG -#------------------------------------------------------------------------------ - -max_wal_size = 1GB -min_wal_size = 80MB - -#------------------------------------------------------------------------------ -# REPORTING AND LOGGING -#------------------------------------------------------------------------------ - -# - What to Log - - -log_line_prefix = '%m [%p] %q%u@%d ' -log_timezone = 'Etc/UTC' - -#------------------------------------------------------------------------------ -# PROCESS TITLE -#------------------------------------------------------------------------------ - -cluster_name = '15/main' - -#------------------------------------------------------------------------------ -# CLIENT CONNECTION DEFAULTS -#------------------------------------------------------------------------------ - -# - Locale and Formatting - - -datestyle = 'iso, mdy' -timezone = 'Etc/UTC' -lc_messages = 'C' -lc_monetary = 'C' -lc_numeric = 'C' -lc_time = 'C' -default_text_search_config = 'pg_catalog.english' - -#------------------------------------------------------------------------------ -# CONFIG FILE INCLUDES -#------------------------------------------------------------------------------ - -include_dir = 'conf.d' -EOF - -sudo systemctl restart postgresql -msg_ok "Installed PostgreSQL" - -read -r -p "Would you like to add Adminer? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - ADMINER="Y" -else - ADMINER="N" -fi - -if [[ $ADMINER == "Y" ]]; then - msg_info "Installing Adminer" - sudo apt install adminer -y &>/dev/null - sudo a2enconf adminer &>/dev/null - sudo systemctl reload apache2 &>/dev/null - msg_ok "Installed Adminer" -fi - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/postgresql-v5-install.sh b/install/postgresql-v5-install.sh index 16a24da2..bc14a5dc 100644 --- a/install/postgresql-v5-install.sh +++ b/install/postgresql-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -217,11 +213,11 @@ if [[ $ADMINER == "Y" ]]; then msg_ok "Installed Adminer" fi -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -234,10 +230,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/prometheus-install.sh b/install/prometheus-install.sh deleted file mode 100644 index fd38a1b9..00000000 --- a/install/prometheus-install.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Prometheus" -mkdir -p /etc/prometheus -mkdir -p /var/lib/prometheus -wget https://github.com/prometheus/prometheus/releases/download/v2.36.2/prometheus-2.36.2.linux-amd64.tar.gz &>/dev/null -tar -xvf prometheus-2.36.2.linux-amd64.tar.gz &>/dev/null -cd prometheus-2.36.2.linux-amd64 -mv prometheus promtool /usr/local/bin/ -mv consoles/ console_libraries/ /etc/prometheus/ -mv prometheus.yml /etc/prometheus/prometheus.yml -msg_ok "Installed Prometheus" - -msg_info "Creating Service" -service_path="/etc/systemd/system/prometheus.service" -echo "[Unit] -Description=Prometheus -Wants=network-online.target -After=network-online.target - -[Service] -User=root -Restart=always -Type=simple -ExecStart=/usr/local/bin/prometheus \ - --config.file=/etc/prometheus/prometheus.yml \ - --storage.tsdb.path=/var/lib/prometheus/ \ - --web.console.templates=/etc/prometheus/consoles \ - --web.console.libraries=/etc/prometheus/console_libraries \ - --web.listen-address=0.0.0.0:9090 - -[Install] -WantedBy=multi-user.target" >$service_path -sudo systemctl enable --now prometheus &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -rm -rf /root/prometheus-2.36.2.linux-amd64 /root/prometheus-2.36.2.linux-amd64.tar.gz -msg_ok "Cleaned" diff --git a/install/prometheus-v5-install.sh b/install/prometheus-v5-install.sh index 5eaad18a..faf3d67a 100644 --- a/install/prometheus-v5-install.sh +++ b/install/prometheus-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -124,11 +120,11 @@ WantedBy=multi-user.target" >$service_path $STD sudo systemctl enable --now prometheus msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -141,10 +137,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/prowlarr-v5-install.sh b/install/prowlarr-v5-install.sh index ace1fe80..7fa6898b 100644 --- a/install/prowlarr-v5-install.sh +++ b/install/prowlarr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -117,11 +113,11 @@ systemctl -q daemon-reload systemctl enable --now -q prowlarr msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -134,10 +130,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Prowlarr.master.*.tar.gz diff --git a/install/radarr-v5-install.sh b/install/radarr-v5-install.sh index 57434a87..58f9c4a6 100644 --- a/install/radarr-v5-install.sh +++ b/install/radarr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -117,11 +113,11 @@ systemctl -q daemon-reload systemctl enable --now -q radarr msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -134,10 +130,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Radarr.master.*.tar.gz diff --git a/install/readarr-v5-install.sh b/install/readarr-v5-install.sh index b621cb7a..d4586f0d 100644 --- a/install/readarr-v5-install.sh +++ b/install/readarr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -117,11 +113,11 @@ systemctl -q daemon-reload systemctl enable --now -q readarr msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -134,10 +130,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Readarr.develop.*.tar.gz diff --git a/install/sabnzbd-v5-install.sh b/install/sabnzbd-v5-install.sh index 964f2de7..ccdf4923 100644 --- a/install/sabnzbd-v5-install.sh +++ b/install/sabnzbd-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -122,11 +118,11 @@ WantedBy=multi-user.target" >$service_path systemctl enable --now -q sabnzbd.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -139,10 +135,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/scrypted-install.sh b/install/scrypted-install.sh deleted file mode 100644 index 96380318..00000000 --- a/install/scrypted-install.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get -y install software-properties-common apt-utils &>/dev/null -apt-get -y update &>/dev/null -apt-get -y upgrade &>/dev/null -apt-get -y install \ - build-essential \ - gcc \ - gir1.2-gtk-3.0 \ - libcairo2-dev \ - libgirepository1.0-dev \ - libglib2.0-dev \ - libjpeg-dev \ - libgif-dev \ - libopenjp2-7 \ - libpango1.0-dev \ - librsvg2-dev \ - pkg-config \ - curl \ - sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing GStreamer" -apt-get -y install \ - gstreamer1.0-tools \ - libgstreamer1.0-dev \ - libgstreamer-plugins-base1.0-dev \ - libgstreamer-plugins-bad1.0-dev \ - gstreamer1.0-plugins-base \ - gstreamer1.0-plugins-good \ - gstreamer1.0-plugins-bad \ - gstreamer1.0-plugins-ugly \ - gstreamer1.0-libav \ - gstreamer1.0-alsa &>/dev/null -msg_ok "Installed GStreamer" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Python3" -apt-get -y install \ - python3 \ - python3-dev \ - python3-gi \ - python3-gst-1.0 \ - python3-matplotlib \ - python3-numpy \ - python3-opencv \ - python3-pil \ - python3-pip \ - python3-setuptools \ - python3-skimage \ - python3-wheel &>/dev/null -python3 -m pip install --upgrade pip &>/dev/null -python3 -m pip install aiofiles debugpy typing_extensions typing &>/dev/null -msg_ok "Installed Python3" - -read -r -p "Would you like to add Coral Edge TPU support? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - CORAL="Y" -else - CORAL="N" -fi - -if [[ $CORAL == "Y" ]]; then -msg_info "Adding Coral Edge TPU Support" -echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list &>/dev/null -curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - &>/dev/null -apt-get -y update &>/dev/null -apt-get -y install libedgetpu1-std &>/dev/null -msg_ok "Coral Edge TPU Support Added" -fi - -msg_info "Installing Scrypted" -sudo -u root npx -y scrypted@latest install-server &>/dev/null -msg_info "Installed Scrypted" - -msg_info "Creating Service" -service_path="/etc/systemd/system/scrypted.service" -echo "[Unit] -Description=Scrypted service -After=network.target - -[Service] -User=root -Group=root -Type=simple -ExecStart=/usr/bin/npx -y scrypted serve -Restart=on-failure -RestartSec=3 - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now scrypted.service &>/dev/null -msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/scrypted-v5-install.sh b/install/scrypted-v5-install.sh index 53c2e62d..c55bfba2 100644 --- a/install/scrypted-v5-install.sh +++ b/install/scrypted-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -182,11 +178,11 @@ RestartSec=3 WantedBy=multi-user.target" >$service_path $STD systemctl enable --now scrypted.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -199,10 +195,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/shinobi-install.sh b/install/shinobi-install.sh deleted file mode 100644 index 0c8510fa..00000000 --- a/install/shinobi-install.sh +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update --fix-missing &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -ubuntuversion=$(lsb_release -r | awk '{print $2}' | cut -d . -f1) -if [ "$ubuntuversion" = "18" ] || [ "$ubuntuversion" -le "18" ]; then - apt install sudo wget -y - sudo apt install -y software-properties-common - sudo add-apt-repository universe -y - apt update -y - apt update --fix-missing -y -fi - -msg_info "Installing Dependencies" -apt-get install -y curl sudo git &>/dev/null -apt-get install -y make zip net-tools &>/dev/null -apt-get install -y gcc g++ cmake &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing FFMPEG" -apt-get install -y ffmpeg &>/dev/null -msg_ok "Installed FFMPEG" - -msg_info "Clonning Shinobi" -cd /opt -git clone https://gitlab.com/Shinobi-Systems/Shinobi.git -b master Shinobi &>/dev/null -cd Shinobi -gitVersionNumber=$(git rev-parse HEAD) -theDateRightNow=$(date) -touch version.json -chmod 777 version.json -echo '{"Product" : "'"Shinobi"'" , "Branch" : "'"master"'" , "Version" : "'"$gitVersionNumber"'" , "Date" : "'"$theDateRightNow"'" , "Repository" : "'"https://gitlab.com/Shinobi-Systems/Shinobi.git"'"}' > version.json -msg_ok "Cloned Shinobi" - -msg_info "Installing Database" -sqlpass="" -echo "mariadb-server mariadb-server/root_password password $sqlpass" | debconf-set-selections -echo "mariadb-server mariadb-server/root_password_again password $sqlpass" | debconf-set-selections -apt-get install -y mariadb-server &>/dev/null -service mysql start -sqluser="root" -mysql -e "source sql/user.sql" || true -mysql -e "source sql/framework.sql" || true -msg_ok "Installed Database" -cp conf.sample.json conf.json -cronKey=$(head -c 1024 < /dev/urandom | sha256sum | awk '{print substr($1,1,29)}') -sed -i -e 's/Shinobi/'"$cronKey"'/g' conf.json -cp super.sample.json super.json - -msg_info "Installing Shinobi" -npm i npm -g &>/dev/null -npm install --unsafe-perm &>/dev/null -npm install pm2@latest -g &>/dev/null -chmod -R 755 . -touch INSTALL/installed.txt -ln -s /opt/Shinobi/INSTALL/shinobi /usr/bin/shinobi -node /opt/Shinobi/tools/modifyConfiguration.js addToConfig="{\"cron\":{\"key\":\"$(head -c 64 < /dev/urandom | sha256sum | awk '{print substr($1,1,60)}')\"}}" &>/dev/null -pm2 start camera.js &>/dev/null -pm2 start cron.js &>/dev/null -pm2 startup &>/dev/null -pm2 save &>/dev/null -pm2 list &>/dev/null -msg_ok "Installed Shinobi" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/shinobi-v5-install.sh b/install/shinobi-v5-install.sh index b78a3eb2..6a6c6d47 100644 --- a/install/shinobi-v5-install.sh +++ b/install/shinobi-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -151,11 +147,11 @@ $STD pm2 save $STD pm2 list msg_ok "Installed Shinobi" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -168,10 +164,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/sonarr-v5-install.sh b/install/sonarr-v5-install.sh index d70ec352..4d397510 100644 --- a/install/sonarr-v5-install.sh +++ b/install/sonarr-v5-install.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash export DEBIAN_FRONTEND=noninteractive +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -10,26 +11,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -98,11 +94,11 @@ $STD apt-get update $STD apt-get -o Dpkg::Options::="--force-confold" install -y sonarr msg_ok "Installed Sonarr" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -115,10 +111,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/syncthing-install.sh b/install/syncthing-install.sh deleted file mode 100644 index a6a09abd..00000000 --- a/install/syncthing-install.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gnupg &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Syncthing" -curl -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg &>/dev/null -echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list &>/dev/null -apt-get update &>/dev/null -apt-get install -y syncthing &>/dev/null -systemctl enable syncthing@root.service &>/dev/null -systemctl start syncthing@root.service -sleep 5 -sed -i "{s/127.0.0.1:8384/0.0.0.0:8384/g}" /root/.config/syncthing/config.xml -systemctl restart syncthing@root.service -msg_ok "Installed Syncthing" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/syncthing-v5-install.sh b/install/syncthing-v5-install.sh index 3a78362e..770fdc90 100644 --- a/install/syncthing-v5-install.sh +++ b/install/syncthing-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -101,11 +97,11 @@ sed -i "{s/127.0.0.1:8384/0.0.0.0:8384/g}" /root/.config/syncthing/config.xml systemctl restart syncthing@root.service msg_ok "Installed Syncthing" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -118,10 +114,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/tdarr-v5-install.sh b/install/tdarr-v5-install.sh index 0121ef51..35167dfc 100644 --- a/install/tdarr-v5-install.sh +++ b/install/tdarr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -144,11 +140,11 @@ systemctl enable --now -q tdarr-server.service systemctl enable --now -q tdarr-node.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -161,10 +157,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Tdarr_Updater.zip diff --git a/install/technitiumdns-install.sh b/install/technitiumdns-install.sh deleted file mode 100644 index 038275c2..00000000 --- a/install/technitiumdns-install.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Technitium DNS" -curl -sSL https://download.technitium.com/dns/install.sh | sudo bash &>/dev/null -msg_ok "Installed Technitium DNS" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/technitiumdns-v5-install.sh b/install/technitiumdns-v5-install.sh index 76abf611..a410e6cc 100644 --- a/install/technitiumdns-v5-install.sh +++ b/install/technitiumdns-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -96,12 +92,11 @@ ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf $STD bash <(curl -fsSL https://download.technitium.com/dns/install.sh) msg_ok "Installed Technitium DNS" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -114,10 +109,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/transmission-v5-install.sh b/install/transmission-v5-install.sh index 436f527a..db579d21 100644 --- a/install/transmission-v5-install.sh +++ b/install/transmission-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -96,11 +92,11 @@ sed -i '{s/"rpc-whitelist-enabled": true/"rpc-whitelist-enabled": false/g; s/"rp systemctl start transmission-daemon msg_ok "Installed Transmission" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -113,10 +109,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/trilium-install.sh b/install/trilium-install.sh deleted file mode 100644 index d18a33c2..00000000 --- a/install/trilium-install.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -RELEASE=$(curl -s https://api.github.com/repos/zadam/trilium/releases/latest | - grep "tag_name" | - awk '{print substr($2, 3, length($2)-4) }') - -msg_info "Installing Trilium" -wget -q https://github.com/zadam/trilium/releases/download/v$RELEASE/trilium-linux-x64-server-$RELEASE.tar.xz -tar -xvf trilium-linux-x64-server-$RELEASE.tar.xz &>/dev/null -mv trilium-linux-x64-server /opt/trilium -msg_ok "Installed Trilium" - -msg_info "Creating Service" -service_path="/etc/systemd/system/trilium.service" - -echo "[Unit] -Description=Trilium Daemon -After=syslog.target network.target - -[Service] -User=root -Type=simple -ExecStart=/opt/trilium/trilium.sh -WorkingDirectory=/opt/trilium/ -TimeoutStopSec=20 -Restart=always - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now -q trilium -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -rm -rf /root/trilium-linux-x64-server-$RELEASE.tar.xz -msg_ok "Cleaned" diff --git a/install/trilium-v5-install.sh b/install/trilium-v5-install.sh index b4fe4f89..4b266ec1 100644 --- a/install/trilium-v5-install.sh +++ b/install/trilium-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -118,11 +114,11 @@ WantedBy=multi-user.target" >$service_path systemctl enable --now -q trilium msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -135,10 +131,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/ubuntu-install.sh b/install/ubuntu-install.sh deleted file mode 100644 index 0b1564d0..00000000 --- a/install/ubuntu-install.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/ubuntu-v5-install.sh b/install/ubuntu-v5-install.sh index abb5e42f..ec35eb7f 100644 --- a/install/ubuntu-v5-install.sh +++ b/install/ubuntu-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -89,11 +85,11 @@ $STD apt-get install -y sudo $STD apt-get install -y mc msg_ok "Installed Dependencies" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -106,10 +102,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/umbrel-install.sh b/install/umbrel-install.sh deleted file mode 100644 index d63ff40a..00000000 --- a/install/umbrel-install.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -DOCKER_CONFIG_PATH='/etc/docker/daemon.json' -mkdir -p $(dirname $DOCKER_CONFIG_PATH) -cat >$DOCKER_CONFIG_PATH <<'EOF' -{ - "log-driver": "journald" -} -EOF - -msg_info "Installing Umbrel (Patience)" -if [ "$ST" == "yes" ]; then -VER=$(curl -s https://api.github.com/repos/containers/fuse-overlayfs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -cd /usr/local/bin -curl -sSL -o fuse-overlayfs https://github.com/containers/fuse-overlayfs/releases/download/$VER/fuse-overlayfs-x86_64 -chmod 755 /usr/local/bin/fuse-overlayfs -cd ~ -fi -curl -sL https://umbrel.sh | bash &>/dev/null -systemctl daemon-reload -systemctl enable --now umbrel-startup.service &>/dev/null -msg_ok "Installed Umbrel" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/umbrel-v5-install.sh b/install/umbrel-v5-install.sh index 448920c3..3c0e217b 100644 --- a/install/umbrel-v5-install.sh +++ b/install/umbrel-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -107,12 +103,11 @@ systemctl daemon-reload $STD systemctl enable --now umbrel-startup.service msg_ok "Installed Umbrel" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -125,10 +120,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove $STD apt-get autoclean diff --git a/install/unifi-install.sh b/install/unifi-install.sh deleted file mode 100644 index da6e91fd..00000000 --- a/install/unifi-install.sh +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -#https://community.ui.com/questions/UniFi-Installation-Scripts-or-UniFi-Easy-Update-Script-or-UniFi-Lets-Encrypt-or-UniFi-Easy-Encrypt-/ccbc7530-dd61-40a7-82ec-22b17f027776 -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -read -r -p "Local Controller? " prompt -if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - LOCAL="--local-controller" -else - LOCAL="" -fi - -msg_info "Installing UniFi Network Application (Patience)" -wget -qL https://get.glennr.nl/unifi/install/install_latest/unifi-latest.sh && bash unifi-latest.sh --skip --add-repository $LOCAL &>/dev/null -msg_ok "Installed UniFi Network Application" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/unifi-v5-install.sh b/install/unifi-v5-install.sh index 80b4562d..afc4930a 100644 --- a/install/unifi-v5-install.sh +++ b/install/unifi-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi #https://community.ui.com/questions/UniFi-Installation-Scripts-or-UniFi-Easy-Update-Script-or-UniFi-Lets-Encrypt-or-UniFi-Easy-Encrypt-/ccbc7530-dd61-40a7-82ec-22b17f027776 YW=$(echo "\033[33m") @@ -10,26 +11,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -50,15 +43,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -75,7 +71,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -102,12 +98,11 @@ wget -qL https://get.glennr.nl/unifi/install/install_latest/unifi-latest.sh $STD bash unifi-latest.sh --skip --add-repository $LOCAL msg_ok "Installed UniFi Network Application" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -120,10 +115,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/uptimekuma-install.sh b/install/uptimekuma-install.sh deleted file mode 100644 index d314ad3c..00000000 --- a/install/uptimekuma-install.sh +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -sudo apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Uptime Kuma" -git clone https://github.com/louislam/uptime-kuma.git &>/dev/null -mv uptime-kuma /opt/uptime-kuma -cd /opt/uptime-kuma -npm run setup &>/dev/null -msg_ok "Installed Uptime Kuma" - -msg_info "Creating Service" -service_path="/etc/systemd/system/uptime-kuma.service" -echo "[Unit] -Description=uptime-kuma - -[Service] -Type=simple -Restart=always -User=root -WorkingDirectory=/opt/uptime-kuma -ExecStart=/usr/bin/npm start - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now uptime-kuma.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/uptimekuma-v5-install.sh b/install/uptimekuma-v5-install.sh index 29af2997..69baf541 100644 --- a/install/uptimekuma-v5-install.sh +++ b/install/uptimekuma-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -122,12 +118,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now uptime-kuma.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -140,10 +135,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/vaultwarden-install.sh b/install/vaultwarden-install.sh deleted file mode 100644 index 0710c1ef..00000000 --- a/install/vaultwarden-install.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get update &>/dev/null -apt-get -qqy install \ - git \ - build-essential \ - pkgconf \ - libssl-dev \ - libmariadb-dev-compat \ - libpq-dev \ - curl \ - sudo &>/dev/null -msg_ok "Installed Dependencies" - -WEBVAULT=$(curl -s https://api.github.com/repos/dani-garcia/bw_web_builds/releases/latest | - grep "tag_name" | - awk '{print substr($2, 2, length($2)-3) }') - -VAULT=$(curl -s https://api.github.com/repos/dani-garcia/vaultwarden/releases/latest | - grep "tag_name" | - awk '{print substr($2, 2, length($2)-3) }') - -msg_info "Installing Rust" -curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal &>/dev/null -echo 'export PATH=~/.cargo/bin:$PATH' >>~/.bashrc &>/dev/null -export PATH=~/.cargo/bin:$PATH &>/dev/null -which rustc &>/dev/null -msg_ok "Installed Rust" - -msg_info "Building Vaultwarden ${VAULT} (Patience)" -git clone https://github.com/dani-garcia/vaultwarden &>/dev/null -cd vaultwarden -cargo build --features "sqlite,mysql,postgresql" --release &>/dev/null -msg_ok "Built Vaultwarden ${VAULT}" - -addgroup --system vaultwarden &>/dev/null -adduser --system --home /opt/vaultwarden --shell /usr/sbin/nologin --no-create-home --gecos 'vaultwarden' --ingroup vaultwarden --disabled-login --disabled-password vaultwarden &>/dev/null -mkdir -p /opt/vaultwarden/bin -mkdir -p /opt/vaultwarden/data -cp target/release/vaultwarden /opt/vaultwarden/bin/ - -msg_info "Downloading Web-Vault ${WEBVAULT}" -curl -fsSLO https://github.com/dani-garcia/bw_web_builds/releases/download/$WEBVAULT/bw_web_$WEBVAULT.tar.gz &>/dev/null -tar -xzf bw_web_$WEBVAULT.tar.gz -C /opt/vaultwarden/ &>/dev/null -msg_ok "Downloaded Web-Vault ${WEBVAULT}" - -cat </opt/vaultwarden/.env -ADMIN_TOKEN=$(openssl rand -base64 48) -ROCKET_ADDRESS=0.0.0.0 -DATA_FOLDER=/opt/vaultwarden/data -DATABASE_MAX_CONNS=10 -WEB_VAULT_FOLDER=/opt/vaultwarden/web-vault -WEB_VAULT_ENABLED=true -EOF - -msg_info "Creating Service" -chown -R vaultwarden:vaultwarden /opt/vaultwarden/ -chown root:root /opt/vaultwarden/bin/vaultwarden -chmod +x /opt/vaultwarden/bin/vaultwarden -chown -R root:root /opt/vaultwarden/web-vault/ -chmod +r /opt/vaultwarden/.env -service_path="/etc/systemd/system/vaultwarden.service" &>/dev/null - -echo "[Unit] -Description=Bitwarden Server (Powered by Vaultwarden) -Documentation=https://github.com/dani-garcia/vaultwarden -After=network.target -[Service] -User=vaultwarden -Group=vaultwarden -EnvironmentFile=-/opt/vaultwarden/.env -ExecStart=/opt/vaultwarden/bin/vaultwarden -LimitNOFILE=65535 -LimitNPROC=4096 -PrivateTmp=true -PrivateDevices=true -ProtectHome=true -ProtectSystem=strict -DevicePolicy=closed -ProtectControlGroups=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes -RestrictNamespaces=yes -RestrictRealtime=yes -MemoryDenyWriteExecute=yes -LockPersonality=yes -WorkingDirectory=/opt/vaultwarden -ReadWriteDirectories=/opt/vaultwarden/data -AmbientCapabilities=CAP_NET_BIND_SERVICE -[Install] -WantedBy=multi-user.target" >$service_path -systemctl daemon-reload -systemctl enable --now vaultwarden.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/vaultwarden-v5-install.sh b/install/vaultwarden-v5-install.sh index 4ad15ac4..aeaab763 100644 --- a/install/vaultwarden-v5-install.sh +++ b/install/vaultwarden-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -179,12 +175,11 @@ systemctl daemon-reload $STD systemctl enable --now vaultwarden.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -197,10 +192,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/whisparr-v5-install.sh b/install/whisparr-v5-install.sh index 9cd11da7..1c037d5c 100644 --- a/install/whisparr-v5-install.sh +++ b/install/whisparr-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -117,11 +113,11 @@ systemctl -q daemon-reload systemctl enable --now -q whisparr msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -134,10 +130,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm -rf Whisparr.develop.*.tar.gz diff --git a/install/whoogle-install.sh b/install/whoogle-install.sh deleted file mode 100644 index 758ae265..00000000 --- a/install/whoogle-install.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Python3-pip" -apt-get install python3-pip -y &>/dev/null -msg_ok "Installed Python3-pip" - -msg_info "Installing Whoogle" -pip install brotli &>/dev/null -pip install whoogle-search &>/dev/null - -service_path="/etc/systemd/system/whoogle.service" -echo "[Unit] -Description=Whoogle-Search -After=network.target -[Service] -ExecStart=/usr/local/bin/whoogle-search --host 0.0.0.0 -Restart=always -User=root -[Install] -WantedBy=multi-user.target" >$service_path - -systemctl enable --now whoogle.service &>/dev/null -msg_ok "Installed Whoogle" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/whoogle-v5-install.sh b/install/whoogle-v5-install.sh index 659b2d36..891c28c1 100644 --- a/install/whoogle-v5-install.sh +++ b/install/whoogle-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -111,11 +107,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now whoogle.service msg_ok "Installed Whoogle" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -128,10 +124,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/wikijs-install.sh b/install/wikijs-install.sh deleted file mode 100644 index 947ddbab..00000000 --- a/install/wikijs-install.sh +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -sL https://deb.nodesource.com/setup_16.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Installing Wiki.js" -mkdir -p /opt/wikijs -cd /opt/wikijs -wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz &>/dev/null -tar xzf wiki-js.tar.gz -rm wiki-js.tar.gz - -cat </opt/wikijs/config.yml -bindIP: 0.0.0.0 -port: 3000 -db: - type: sqlite - storage: /opt/wikijs/db.sqlite -logLevel: info -logFormat: default -dataPath: /opt/wikijs/data -bodyParserLimit: 5mb -EOF -npm rebuild sqlite3 &>/dev/null -msg_ok "Installed Wiki.js" - -msg_info "Creating Service" -service_path="/etc/systemd/system/wikijs.service" - -echo "[Unit] -Description=Wiki.js -After=network.target - -[Service] -Type=simple -ExecStart=/usr/bin/node server -Restart=always -User=root -Environment=NODE_ENV=production -WorkingDirectory=/opt/wikijs - -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable --now wikijs &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/wikijs-v5-install.sh b/install/wikijs-v5-install.sh index b90beae5..5cbaeb91 100644 --- a/install/wikijs-v5-install.sh +++ b/install/wikijs-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -139,11 +135,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable --now wikijs msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -156,10 +152,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/wireguard-install.sh b/install/wireguard-install.sh deleted file mode 100644 index b71dad3b..00000000 --- a/install/wireguard-install.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -OPTIONS_PATH='/options.conf' -cat >$OPTIONS_PATH <<'EOF' -IPv4dev=eth0 -install_user=root -VPN=wireguard -pivpnNET=10.6.0.0 -subnetClass=24 -ALLOWED_IPS="0.0.0.0/0, ::0/0" -pivpnMTU=1420 -pivpnPORT=51820 -pivpnDNS1=1.1.1.1 -pivpnDNS2=8.8.8.8 -pivpnHOST= -pivpnPERSISTENTKEEPALIVE=25 -UNATTUPG=1 -EOF - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y gunicorn &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing WireGuard (using pivpn.io)" -curl -s -L https://install.pivpn.io >install.sh -chmod +x install.sh -./install.sh --unattended options.conf &>/dev/null -msg_ok "Installed WireGuard" - -msg_info "Installing Python3-pip" -apt-get install python3-pip -y &>/dev/null -pip install flask &>/dev/null -pip install ifcfg &>/dev/null -pip install flask_qrcode &>/dev/null -pip install icmplib &>/dev/null -msg_ok "Installed Python3-pip" - -msg_info "Installing WGDashboard" -WGDREL=$(curl -s https://api.github.com/repos/donaldzou/WGDashboard/releases/latest | - grep "tag_name" | - awk '{print substr($2, 2, length($2)-3) }') - -git clone -b ${WGDREL} https://github.com/donaldzou/WGDashboard.git /etc/wgdashboard &>/dev/null -cd /etc/wgdashboard/src -sudo chmod u+x wgd.sh -sudo ./wgd.sh install &>/dev/null -sudo chmod -R 755 /etc/wireguard -msg_ok "Installed WGDashboard" - -msg_info "Creating Service" -service_path="/etc/systemd/system/wg-dashboard.service" -echo "[Unit] -After=netword.service - -[Service] -WorkingDirectory=/etc/wgdashboard/src -ExecStart=/usr/bin/python3 /etc/wgdashboard/src/dashboard.py -Restart=always - - -[Install] -WantedBy=default.target" >$service_path -sudo chmod 664 /etc/systemd/system/wg-dashboard.service -sudo systemctl daemon-reload -sudo systemctl enable wg-dashboard.service &>/dev/null -sudo systemctl start wg-dashboard.service -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/wireguard-v5-install.sh b/install/wireguard-v5-install.sh index 06d3cc3f..b7647b7b 100644 --- a/install/wireguard-v5-install.sh +++ b/install/wireguard-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -111,12 +107,11 @@ msg_info "Installing WireGuard (using pivpn.io)" $STD bash <(curl -fsSL https://install.pivpn.io) --unattended options.conf msg_ok "Installed WireGuard" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -129,10 +124,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/yunohost-v5-install.sh b/install/yunohost-v5-install.sh index 02ec6fc8..2510ebc1 100644 --- a/install/yunohost-v5-install.sh +++ b/install/yunohost-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -48,15 +41,18 @@ function msg_error() { msg_info "Setting up Container OS" sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -73,7 +69,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -98,11 +94,11 @@ wget -q -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg $STD bash <(curl -fsSL https://install.yunohost.org) -a msg_ok "Installed YunoHost" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - chmod -x /etc/update-motd.d/* + OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -115,10 +111,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/zigbee2mqtt-install.sh b/install/zigbee2mqtt-install.sh deleted file mode 100644 index 38f70952..00000000 --- a/install/zigbee2mqtt-install.sh +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y git &>/dev/null -apt-get install -y make &>/dev/null -apt-get install -y g++ &>/dev/null -apt-get install -y gcc &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Setting up Node.js Repository" -curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &>/dev/null -msg_ok "Set up Node.js Repository" - -msg_info "Installing Node.js" -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js" - -msg_info "Setting up Zigbee2MQTT Repository" -git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt &>/dev/null -msg_ok "Set up Zigbee2MQTT Repository" - -read -r -p "Switch to Edge/dev branch? (y/N) " prompt -if [[ $prompt == "y" ]]; then - DEV="y" -else - DEV="n" -fi - -msg_info "Installing Zigbee2MQTT" -cd /opt/zigbee2mqtt &>/dev/null -if [[ $DEV == "y" ]]; then - git checkout dev &>/dev/null -fi -npm ci &>/dev/null -msg_ok "Installed Zigbee2MQTT" - -msg_info "Creating Service" -service_path="/etc/systemd/system/zigbee2mqtt.service" -echo "[Unit] -Description=zigbee2mqtt -After=network.target -[Service] -Environment=NODE_ENV=production -ExecStart=/usr/bin/npm start -WorkingDirectory=/opt/zigbee2mqtt -StandardOutput=inherit -StandardError=inherit -Restart=always -User=root -[Install] -WantedBy=multi-user.target" >$service_path -systemctl enable zigbee2mqtt.service &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/zigbee2mqtt-v5-install.sh b/install/zigbee2mqtt-v5-install.sh index 8eae1c36..dfe49bdd 100644 --- a/install/zigbee2mqtt-v5-install.sh +++ b/install/zigbee2mqtt-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -138,12 +134,11 @@ WantedBy=multi-user.target" >$service_path $STD systemctl enable zigbee2mqtt.service msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -156,10 +151,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" $STD apt-get autoremove diff --git a/install/zwave-js-ui-install.sh b/install/zwave-js-ui-install.sh deleted file mode 100644 index a101ffe6..00000000 --- a/install/zwave-js-ui-install.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash -if [ "$VERBOSE" == "yes" ]; then set -x; fi -YW=$(echo "\033[33m") -RD=$(echo "\033[01;31m") -BL=$(echo "\033[36m") -GN=$(echo "\033[1;92m") -CL=$(echo "\033[m") -RETRY_NUM=10 -RETRY_EVERY=3 -NUM=$RETRY_NUM -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" -BFR="\\r\\033[K" -HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} - -function msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} - -function msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} - -function msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -msg_info "Setting up Container OS " -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do - echo 1>&2 -en "${CROSS}${RD} No Network! " - sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi -done -msg_ok "Set up Container OS" -msg_ok "Network Connected: ${BL}$(hostname -I)" - -set +e -alias die='' -if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" - else - echo -e " 🖧 Check Network Settings" - exit 1 - fi -fi -RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi -alias die='EXIT=$? LINE=$LINENO error_exit' -set -e - -msg_info "Updating Container OS" -apt-get update &>/dev/null -apt-get -y upgrade &>/dev/null -msg_ok "Updated Container OS" - -msg_info "Installing Dependencies" -apt-get install -y curl &>/dev/null -apt-get install -y sudo &>/dev/null -apt-get install -y unzip &>/dev/null -msg_ok "Installed Dependencies" - -msg_info "Installing Z-Wave JS UI" -mkdir /opt/zwave-js-ui -cd /opt/zwave-js-ui -RELEASE=$(curl -s https://api.github.com/repos/zwave-js/zwave-js-ui/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -wget https://github.com/zwave-js/zwave-js-ui/releases/download/${RELEASE}/zwave-js-ui-${RELEASE}-linux.zip &>/dev/null -unzip zwave-js-ui-${RELEASE}-linux.zip &>/dev/null -msg_ok "Installed Z-Wave JS UI" - -msg_info "Creating Service" -service_path="/etc/systemd/system/zwave-js-ui.service" -echo "[Unit] -Description=zwave-js-ui -Wants=network-online.target -After=network-online.target -[Service] -User=root -WorkingDirectory=/opt/zwave-js-ui -ExecStart=/opt/zwave-js-ui/zwave-js-ui-linux -[Install] -WantedBy=multi-user.target" >$service_path -systemctl start zwave-js-ui -systemctl enable zwave-js-ui &>/dev/null -msg_ok "Created Service" - -PASS=$(grep -w "root" /etc/shadow | cut -b6) -echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then - msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname - touch ~/.hushlogin - GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" - mkdir -p $(dirname $GETTY_OVERRIDE) - cat <$GETTY_OVERRIDE -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM -EOF - systemctl daemon-reload - systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') - msg_ok "Customized Container" -fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi - -msg_info "Cleaning up" -rm zwave-js-ui-${RELEASE}-linux.zip -apt-get autoremove >/dev/null -apt-get autoclean >/dev/null -msg_ok "Cleaned" diff --git a/install/zwave-js-ui-v5-install.sh b/install/zwave-js-ui-v5-install.sh index 3ce383d8..63125469 100644 --- a/install/zwave-js-ui-v5-install.sh +++ b/install/zwave-js-ui-v5-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +if [ "$VERBOSE" == "yes" ]; then set -x; STD=""; fi +if [ "$VERBOSE" != "yes" ]; then STD="silent"; fi silent() { "$@" > /dev/null 2>&1; } -if [ "$VERBOSE" == "yes" ]; then set -x; fi if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi YW=$(echo "\033[33m") RD=$(echo "\033[01;31m") @@ -9,26 +10,18 @@ GN=$(echo "\033[1;92m") CL=$(echo "\033[m") RETRY_NUM=10 RETRY_EVERY=3 -NUM=$RETRY_NUM CM="${GN}✓${CL}" CROSS="${RD}✗${CL}" BFR="\\r\\033[K" HOLD="-" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occurred." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT +set -Eeuo pipefail +trap 'error_handler $LINENO "$BASH_COMMAND"' ERR +function error_handler() { + local exit_code="$?" + local line_number="$1" + 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" } function msg_info() { @@ -49,15 +42,18 @@ function msg_error() { msg_info "Setting up Container OS " sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen locale-gen >/dev/null -while [ "$(hostname -I)" = "" ]; do +for ((i=RETRY_NUM; i>0; i--)); do + if [ "$(hostname -I)" != "" ]; then + break + fi echo 1>&2 -en "${CROSS}${RD} No Network! " sleep $RETRY_EVERY - ((NUM--)) - if [ $NUM -eq 0 ]; then - echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" - exit 1 - fi done +if [ "$(hostname -I)" = "" ]; then + echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}" + echo -e " 🖧 Check Network Settings" + exit 1 +fi msg_ok "Set up Container OS" msg_ok "Network Connected: ${BL}$(hostname -I)" @@ -74,7 +70,7 @@ if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else fi fi RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs) -if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi +if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi alias die='EXIT=$? LINE=$LINENO error_exit' set -e @@ -114,12 +110,11 @@ systemctl start zwave-js-ui $STD systemctl enable zwave-js-ui msg_ok "Created Service" -PASS=$(grep -w "root" /etc/shadow | cut -b6) echo "export TERM='xterm-256color'" >>/root/.bashrc -if [[ $PASS != $ ]]; then +if ! getent shadow root | grep -q "^root:[^\!*]"; then msg_info "Customizing Container" - rm /etc/motd - rm /etc/update-motd.d/10-uname +OS=$(grep "^ID=" /etc/os-release | cut -d'=' -f2) +if [ "$OS" == "debian" ]; then rm /etc/motd /etc/update-motd.d/10-uname; else chmod -x /etc/update-motd.d/*; fi touch ~/.hushlogin GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf" mkdir -p $(dirname $GETTY_OVERRIDE) @@ -132,10 +127,7 @@ EOF systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//') msg_ok "Customized Container" fi -if [[ "${SSH_ROOT}" == "yes" ]]; then - sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config - systemctl restart sshd -fi +if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi msg_info "Cleaning up" rm zwave-js-ui-${RELEASE}-linux.zip