From 84b244395c15a078141b5bd34d0ebcae96aef32f Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 04:53:14 +0100 Subject: [PATCH 1/8] Added tvheadend_container.sh & tvheadend_setup.sh --- adguard_container.sh | 157 ++++++++++++++++++++++++++++++++++++++++ adguard_setup.sh | 58 +++++++++++++++ tvheadend_container.sh | 159 +++++++++++++++++++++++++++++++++++++++++ tvheadend_setup.sh | 71 ++++++++++++++++++ 4 files changed, 445 insertions(+) create mode 100644 adguard_container.sh create mode 100644 adguard_setup.sh create mode 100644 tvheadend_container.sh create mode 100644 tvheadend_setup.sh diff --git a/adguard_container.sh b/adguard_container.sh new file mode 100644 index 0000000..2f0e54f --- /dev/null +++ b/adguard_container.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash + +while true; do + read -p "This will create a New AdGuard Home LXC. Proceed(y/n)?" yn + case $yn in + [Yy]* ) break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no.";; + esac +done + +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +trap cleanup EXIT + +function error_exit() { + trap - ERR + local DEFAULT='Unknown failure occured.' + local REASON="\e[97m${1:-$DEFAULT}\e[39m" + local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" + msg "$FLAG $REASON" + [ ! -z ${CTID-} ] && cleanup_ctid + exit $EXIT +} +function warn() { + local REASON="\e[97m$1\e[39m" + local FLAG="\e[93m[WARNING]\e[39m" + msg "$FLAG $REASON" +} +function info() { + local REASON="$1" + local FLAG="\e[36m[INFO]\e[39m" + msg "$FLAG $REASON" +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" +} +function cleanup_ctid() { + if [ ! -z ${MOUNT+x} ]; then + pct unmount $CTID + fi + if $(pct status $CTID &>/dev/null); then + if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then + pct stop $CTID + fi + pct destroy $CTID + elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then + pvesm free $ROOTFS + fi +} +function cleanup() { + popd >/dev/null + rm -rf $TEMP_DIR +} +function load_module() { + if ! $(lsmod | grep -Fq $1); then + modprobe $1 &>/dev/null || \ + die "Failed to load '$1' module." + fi + MODULES_PATH=/etc/modules + if ! $(grep -Fxq "$1" $MODULES_PATH); then + echo "$1" >> $MODULES_PATH || \ + die "Failed to add '$1' module to load at boot." + fi +} +TEMP_DIR=$(mktemp -d) +pushd $TEMP_DIR >/dev/null + +wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/adguard_setup.sh + +load_module overlay + +while read -r line; do + TAG=$(echo $line | awk '{print $1}') + TYPE=$(echo $line | awk '{printf "%-10s", $2}') + FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}') + ITEM=" Type: $TYPE Free: $FREE " + OFFSET=2 + if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then + MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) + fi + STORAGE_MENU+=( "$TAG" "$ITEM" "OFF" ) +done < <(pvesm status -content rootdir | awk 'NR>1') +if [ $((${#STORAGE_MENU[@]}/3)) -eq 0 ]; then + warn "'Container' needs to be selected for at least one storage location." + die "Unable to detect valid storage location." +elif [ $((${#STORAGE_MENU[@]}/3)) -eq 1 ]; then + STORAGE=${STORAGE_MENU[0]} +else + while [ -z "${STORAGE:+x}" ]; do + STORAGE=$(whiptail --title "Storage Pools" --radiolist \ + "Which storage pool you would like to use for the container?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit + done +fi +info "Using '$STORAGE' for storage location." + +CTID=$(pvesh get /cluster/nextid) +info "LXC ID is $CTID." + +msg "Updating LXC template list..." +pveam update >/dev/null +msg "Downloading LXC template..." +OSTYPE=debian +OSVERSION=${OSTYPE}-11 +mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($OSVERSION.*\)/\1/p" | sort -t - -k 2 -V) +TEMPLATE="${TEMPLATES[-1]}" +pveam download local $TEMPLATE >/dev/null || + die "A problem occured while downloading the LXC template." + +STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +case $STORAGE_TYPE in + dir|nfs) + DISK_EXT=".raw" + DISK_REF="$CTID/" + ;; + zfspool) + DISK_PREFIX="subvol" + DISK_FORMAT="subvol" + ;; +esac +DISK=${DISK_PREFIX:-vm}-${CTID}-disk-0${DISK_EXT-} +ROOTFS=${STORAGE}:${DISK_REF-}${DISK} + +msg "Creating LXC..." +DISK_SIZE=4G +pvesm alloc $STORAGE $CTID $DISK $DISK_SIZE --format ${DISK_FORMAT:-raw} >/dev/null +if [ "$STORAGE_TYPE" == "zfspool" ]; then + warn "Some containers may not work properly due to ZFS not supporting 'fallocate'." +else + mkfs.ext4 $(pvesm path $ROOTFS) &>/dev/null +fi +ARCH=$(dpkg --print-architecture) +HOSTNAME=adguard +TEMPLATE_STRING="local:vztmpl/${TEMPLATE}" +pct create $CTID $TEMPLATE_STRING -arch $ARCH -features nesting=1 \ + -hostname $HOSTNAME -net0 name=eth0,bridge=vmbr0,ip=dhcp -onboot 1 -cores 1 -memory 1024 \ + -ostype $OSTYPE -rootfs $ROOTFS,size=$DISK_SIZE -storage $STORAGE >/dev/null + +MOUNT=$(pct mount $CTID | cut -d"'" -f 2) +ln -fs $(readlink /etc/localtime) ${MOUNT}/etc/localtime +pct unmount $CTID && unset MOUNT + +msg "Starting LXC..." +pct start $CTID +pct push $CTID adguard_setup.sh /adguard_setup.sh -perms 755 +pct exec $CTID /adguard_setup.sh + +IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') +info "Successfully created a AdGuard Home LXC to $CTID at IP Address ${IP}" diff --git a/adguard_setup.sh b/adguard_setup.sh new file mode 100644 index 0000000..e29e9a5 --- /dev/null +++ b/adguard_setup.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +trap 'die "Script interrupted."' INT + +function error_exit() { + trap - ERR + local DEFAULT='Unknown failure occured.' + local REASON="\e[97m${1:-$DEFAULT}\e[39m" + local FLAG="\e[91m[ERROR:LXC] \e[93m$EXIT@$LINE" + msg "$FLAG $REASON" + exit $EXIT +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" +} + +msg "Setting up Container OS..." +sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen +locale-gen >/dev/null +apt-get -y purge openssh-{client,server} >/dev/null +apt-get autoremove >/dev/null + +msg "Updating Container OS..." +apt update &>/dev/null +apt-get -qqy upgrade &>/dev/null + +msg "Installing Prerequisites..." +apt-get -y install \ + curl \ + sudo &>/dev/null + +msg "Installing AdGuard Home.." +curl -sSL https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh &>/dev/null + +msg "Customizing LXC..." +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 << EOF > $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 "Cleanup..." +rm -rf /adguard_setup.sh /var/{cache,log}/* /var/lib/apt/lists/* diff --git a/tvheadend_container.sh b/tvheadend_container.sh new file mode 100644 index 0000000..ddf9924 --- /dev/null +++ b/tvheadend_container.sh @@ -0,0 +1,159 @@ +#!/usr/bin/env bash + +while true; do + read -p "This will create a new Tvheadend LXC Container. Proceed (y/n)?" yn + case $yn in + [Yy]* ) break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no.";; + esac +done +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +CHECKMARK='\033[0;32m\xE2\x9C\x94\033[0m' +trap cleanup EXIT + +function error_exit() { + trap - ERR + local DEFAULT='Unknown failure occured.' + local REASON="\e[97m${1:-$DEFAULT}\e[39m" + local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" + msg "$FLAG $REASON" + [ ! -z ${CTID-} ] && cleanup_ctid + exit $EXIT +} +function warn() { + local REASON="\e[97m$1\e[39m" + local FLAG="\e[93m[WARNING]\e[39m" + msg "$FLAG $REASON" +} +function info() { + local REASON="$1" + local FLAG="\e[36m[INFO]\e[39m" + msg "$FLAG $REASON" +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" +} +function cleanup_ctid() { + if [ ! -z ${MOUNT+x} ]; then + pct unmount $CTID + fi + if $(pct status $CTID &>/dev/null); then + if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then + pct stop $CTID + fi + pct destroy $CTID + elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then + pvesm free $ROOTFS + fi +} +function cleanup() { + popd >/dev/null + rm -rf $TEMP_DIR +} +function load_module() { + if ! $(lsmod | grep -Fq $1); then + modprobe $1 &>/dev/null || \ + die "Failed to load '$1' module." + fi + MODULES_PATH=/etc/modules + if ! $(grep -Fxq "$1" $MODULES_PATH); then + echo "$1" >> $MODULES_PATH || \ + die "Failed to add '$1' module to load at boot." + fi +} +TEMP_DIR=$(mktemp -d) +pushd $TEMP_DIR >/dev/null + +wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/tvheadend/tvheadend_setup.sh +#wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/tvheadend_setup.sh + +load_module overlay + +while read -r line; do + TAG=$(echo $line | awk '{print $1}') + TYPE=$(echo $line | awk '{printf "%-10s", $2}') + FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}') + ITEM=" Type: $TYPE Free: $FREE " + OFFSET=2 + if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then + MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) + fi + STORAGE_MENU+=( "$TAG" "$ITEM" "OFF" ) +done < <(pvesm status -content rootdir | awk 'NR>1') +if [ $((${#STORAGE_MENU[@]}/3)) -eq 0 ]; then + warn "'Container' needs to be selected for at least one storage location." + die "Unable to detect valid storage location." +elif [ $((${#STORAGE_MENU[@]}/3)) -eq 1 ]; then + STORAGE=${STORAGE_MENU[0]} +else + while [ -z "${STORAGE:+x}" ]; do + STORAGE=$(whiptail --title "Storage Pools" --radiolist \ + "Which storage pool you would like to use for the container?\n\n" \ + 16 $(($MSG_MAX_LENGTH + 23)) 6 \ + "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit + done +fi +info "Using '$STORAGE' for Storage Location." + +CTID=$(pvesh get /cluster/nextid) +info "Container ID is $CTID." + +echo -e "${CHECKMARK} \e[1;92m Updating LXC Template List... \e[0m" +pveam update >/dev/null +echo -e "${CHECKMARK} \e[1;92m Downloading LXC Template... \e[0m" +OSTYPE=debian +OSVERSION=${OSTYPE}-11 +mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($OSVERSION.*\)/\1/p" | sort -t - -k 2 -V) +TEMPLATE="${TEMPLATES[-1]}" +pveam download local $TEMPLATE >/dev/null || + die "A problem occured while downloading the LXC template." + +STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +case $STORAGE_TYPE in + dir|nfs) + DISK_EXT=".raw" + DISK_REF="$CTID/" + ;; + zfspool) + DISK_PREFIX="subvol" + DISK_FORMAT="subvol" + ;; +esac +DISK=${DISK_PREFIX:-vm}-${CTID}-disk-0${DISK_EXT-} +ROOTFS=${STORAGE}:${DISK_REF-}${DISK} + +echo -e "${CHECKMARK} \e[1;92m Creating LXC Container... \e[0m" +DISK_SIZE=8G +pvesm alloc $STORAGE $CTID $DISK $DISK_SIZE --format ${DISK_FORMAT:-raw} >/dev/null +if [ "$STORAGE_TYPE" == "zfspool" ]; then + warn "Some containers may not work properly due to ZFS not supporting 'fallocate'." +else + mkfs.ext4 $(pvesm path $ROOTFS) &>/dev/null +fi +ARCH=$(dpkg --print-architecture) +HOSTNAME=tvheadend +TEMPLATE_STRING="local:vztmpl/${TEMPLATE}" +pct create $CTID $TEMPLATE_STRING -arch $ARCH -features nesting=1 \ + -hostname $HOSTNAME -net0 name=eth0,bridge=vmbr0,ip=dhcp -onboot 1 -cores 2 -memory 2048\ + -ostype $OSTYPE -rootfs $ROOTFS,size=$DISK_SIZE -storage $STORAGE >/dev/null + +MOUNT=$(pct mount $CTID | cut -d"'" -f 2) +ln -fs $(readlink /etc/localtime) ${MOUNT}/etc/localtime +pct unmount $CTID && unset MOUNT + +echo -e "${CHECKMARK} \e[1;92m Starting LXC Container... \e[0m" +pct start $CTID +pct push $CTID jellyfin_setup.sh /jellyfin_setup.sh -perms 755 +pct exec $CTID /jellyfin_setup.sh + +IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') +info "Successfully created a Jellyfin LXC Container to $CTID at IP Address ${IP}:8096" + diff --git a/tvheadend_setup.sh b/tvheadend_setup.sh new file mode 100644 index 0000000..91aade5 --- /dev/null +++ b/tvheadend_setup.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +CHECKMARK='\033[0;32m\xE2\x9C\x94\033[0m' +trap 'die "Script interrupted."' INT + +function error_exit() { + trap - ERR + local DEFAULT='Unknown failure occured.' + local REASON="\e[97m${1:-$DEFAULT}\e[39m" + local FLAG="\e[91m[ERROR:LXC] \e[93m$EXIT@$LINE" + msg "$FLAG $REASON" + exit $EXIT +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" +} + +echo -e "${CHECKMARK} \e[1;92m Setting up Container OS... \e[0m" +sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen +locale-gen >/dev/null +apt-get -y purge openssh-{client,server} >/dev/null +apt-get autoremove >/dev/null + +echo -e "${CHECKMARK} \e[1;92m Updating Container OS... \e[0m" +apt-get update &>/dev/null +apt-get -qqy upgrade &>/dev/null + +echo -e "${CHECKMARK} \e[1;92m Installing Prerequisites... \e[0m" +apt-get -qqy install \ + curl \ + sudo \ + coreutils \ + wget \ + apt-transport-https \ + lsb-release \ + ca-certificates &>/dev/null + +echo -e "${CHECKMARK} \e[1;92m Adding Tvheadend Repo... \e[0m" +cat < /etc/apt/sources.list.d/tvheadend.list.list +deb [arch=amd64] https://apt.tvheadend.org/unstable bullseye main +EOF + +wget -qO- https://doozer.io/keys/tvheadend/tvheadend/pgp | tee /etc/apt/trusted.gpg.d/tvheadend.asc &>/dev/null + +echo -e "${CHECKMARK} \e[1;92m Installing Tvheadend... \e[0m" +apt-get update &>/dev/null +apt-get -y install tvheadend &>/dev/null + +echo -e "${CHECKMARK} \e[1;92m Customizing Container... \e[0m" +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 << EOF > $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//') +echo -e "${CHECKMARK} \e[1;92m Cleanup... \e[0m" +rm -rf /tvheadend_setup.sh /var/{cache,log}/* /var/lib/apt/lists/* From 216fa06c8a990cd3bb7d62a3df06f5d1b5f03e6b Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 04:54:08 +0100 Subject: [PATCH 2/8] Added tvheadend_container.sh & tvheadend_setup.sh --- adguard_container.sh | 157 ------------------------------------------- adguard_setup.sh | 58 ---------------- 2 files changed, 215 deletions(-) delete mode 100644 adguard_container.sh delete mode 100644 adguard_setup.sh diff --git a/adguard_container.sh b/adguard_container.sh deleted file mode 100644 index 2f0e54f..0000000 --- a/adguard_container.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash - -while true; do - read -p "This will create a New AdGuard Home LXC. Proceed(y/n)?" yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "Please answer yes or no.";; - esac -done - -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -trap cleanup EXIT - -function error_exit() { - trap - ERR - local DEFAULT='Unknown failure occured.' - local REASON="\e[97m${1:-$DEFAULT}\e[39m" - local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" - msg "$FLAG $REASON" - [ ! -z ${CTID-} ] && cleanup_ctid - exit $EXIT -} -function warn() { - local REASON="\e[97m$1\e[39m" - local FLAG="\e[93m[WARNING]\e[39m" - msg "$FLAG $REASON" -} -function info() { - local REASON="$1" - local FLAG="\e[36m[INFO]\e[39m" - msg "$FLAG $REASON" -} -function msg() { - local TEXT="$1" - echo -e "$TEXT" -} -function cleanup_ctid() { - if [ ! -z ${MOUNT+x} ]; then - pct unmount $CTID - fi - if $(pct status $CTID &>/dev/null); then - if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then - pct stop $CTID - fi - pct destroy $CTID - elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then - pvesm free $ROOTFS - fi -} -function cleanup() { - popd >/dev/null - rm -rf $TEMP_DIR -} -function load_module() { - if ! $(lsmod | grep -Fq $1); then - modprobe $1 &>/dev/null || \ - die "Failed to load '$1' module." - fi - MODULES_PATH=/etc/modules - if ! $(grep -Fxq "$1" $MODULES_PATH); then - echo "$1" >> $MODULES_PATH || \ - die "Failed to add '$1' module to load at boot." - fi -} -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null - -wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/adguard_setup.sh - -load_module overlay - -while read -r line; do - TAG=$(echo $line | awk '{print $1}') - TYPE=$(echo $line | awk '{printf "%-10s", $2}') - FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}') - ITEM=" Type: $TYPE Free: $FREE " - OFFSET=2 - if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then - MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET)) - fi - STORAGE_MENU+=( "$TAG" "$ITEM" "OFF" ) -done < <(pvesm status -content rootdir | awk 'NR>1') -if [ $((${#STORAGE_MENU[@]}/3)) -eq 0 ]; then - warn "'Container' needs to be selected for at least one storage location." - die "Unable to detect valid storage location." -elif [ $((${#STORAGE_MENU[@]}/3)) -eq 1 ]; then - STORAGE=${STORAGE_MENU[0]} -else - while [ -z "${STORAGE:+x}" ]; do - STORAGE=$(whiptail --title "Storage Pools" --radiolist \ - "Which storage pool you would like to use for the container?\n\n" \ - 16 $(($MSG_MAX_LENGTH + 23)) 6 \ - "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit - done -fi -info "Using '$STORAGE' for storage location." - -CTID=$(pvesh get /cluster/nextid) -info "LXC ID is $CTID." - -msg "Updating LXC template list..." -pveam update >/dev/null -msg "Downloading LXC template..." -OSTYPE=debian -OSVERSION=${OSTYPE}-11 -mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($OSVERSION.*\)/\1/p" | sort -t - -k 2 -V) -TEMPLATE="${TEMPLATES[-1]}" -pveam download local $TEMPLATE >/dev/null || - die "A problem occured while downloading the LXC template." - -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') -case $STORAGE_TYPE in - dir|nfs) - DISK_EXT=".raw" - DISK_REF="$CTID/" - ;; - zfspool) - DISK_PREFIX="subvol" - DISK_FORMAT="subvol" - ;; -esac -DISK=${DISK_PREFIX:-vm}-${CTID}-disk-0${DISK_EXT-} -ROOTFS=${STORAGE}:${DISK_REF-}${DISK} - -msg "Creating LXC..." -DISK_SIZE=4G -pvesm alloc $STORAGE $CTID $DISK $DISK_SIZE --format ${DISK_FORMAT:-raw} >/dev/null -if [ "$STORAGE_TYPE" == "zfspool" ]; then - warn "Some containers may not work properly due to ZFS not supporting 'fallocate'." -else - mkfs.ext4 $(pvesm path $ROOTFS) &>/dev/null -fi -ARCH=$(dpkg --print-architecture) -HOSTNAME=adguard -TEMPLATE_STRING="local:vztmpl/${TEMPLATE}" -pct create $CTID $TEMPLATE_STRING -arch $ARCH -features nesting=1 \ - -hostname $HOSTNAME -net0 name=eth0,bridge=vmbr0,ip=dhcp -onboot 1 -cores 1 -memory 1024 \ - -ostype $OSTYPE -rootfs $ROOTFS,size=$DISK_SIZE -storage $STORAGE >/dev/null - -MOUNT=$(pct mount $CTID | cut -d"'" -f 2) -ln -fs $(readlink /etc/localtime) ${MOUNT}/etc/localtime -pct unmount $CTID && unset MOUNT - -msg "Starting LXC..." -pct start $CTID -pct push $CTID adguard_setup.sh /adguard_setup.sh -perms 755 -pct exec $CTID /adguard_setup.sh - -IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -info "Successfully created a AdGuard Home LXC to $CTID at IP Address ${IP}" diff --git a/adguard_setup.sh b/adguard_setup.sh deleted file mode 100644 index e29e9a5..0000000 --- a/adguard_setup.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -trap 'die "Script interrupted."' INT - -function error_exit() { - trap - ERR - local DEFAULT='Unknown failure occured.' - local REASON="\e[97m${1:-$DEFAULT}\e[39m" - local FLAG="\e[91m[ERROR:LXC] \e[93m$EXIT@$LINE" - msg "$FLAG $REASON" - exit $EXIT -} -function msg() { - local TEXT="$1" - echo -e "$TEXT" -} - -msg "Setting up Container OS..." -sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen -locale-gen >/dev/null -apt-get -y purge openssh-{client,server} >/dev/null -apt-get autoremove >/dev/null - -msg "Updating Container OS..." -apt update &>/dev/null -apt-get -qqy upgrade &>/dev/null - -msg "Installing Prerequisites..." -apt-get -y install \ - curl \ - sudo &>/dev/null - -msg "Installing AdGuard Home.." -curl -sSL https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh &>/dev/null - -msg "Customizing LXC..." -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 << EOF > $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 "Cleanup..." -rm -rf /adguard_setup.sh /var/{cache,log}/* /var/lib/apt/lists/* From 5e42adae5f4a3b59baf3c866efd70e5b4655e1cd Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 04:57:57 +0100 Subject: [PATCH 3/8] Updated README.md --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index aef0f63..355b815 100644 --- a/README.md +++ b/README.md @@ -133,3 +133,23 @@ After the script completes, If you're dissatisfied with the default settings, cl ____________________________________________________________________________________________ + +
+Tvheadend Server LXC + +

Tvheadend Server LXC

+ +To create a new Tvheadend Server LXC, run the following in the Proxmox web shell. + +``` +bash -c "$(wget -qLO - https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/tvheadend_container.sh)" +``` +

Default Settings: 2GB RAM - 8GB Storage - 2vCPU

+ +After the script completes, If you're dissatisfied with the default settings, click on the LXC, then on the **_Resources_** tab and change the **_Memory_**, **_Cores_** and **_Root Disk_** (Resize disk) settings to what you desire. Changes are immediate. + +**Tvheadedn Server Interface - IP:8096** + +____________________________________________________________________________________________ + +
From f9aa96981f77b3e8fa9bfdc52c528cb58da69662 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 04:59:22 +0100 Subject: [PATCH 4/8] Updated tvheadend_container.sh --- tvheadend_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tvheadend_container.sh b/tvheadend_container.sh index ddf9924..b3ff827 100644 --- a/tvheadend_container.sh +++ b/tvheadend_container.sh @@ -151,8 +151,8 @@ pct unmount $CTID && unset MOUNT echo -e "${CHECKMARK} \e[1;92m Starting LXC Container... \e[0m" pct start $CTID -pct push $CTID jellyfin_setup.sh /jellyfin_setup.sh -perms 755 -pct exec $CTID /jellyfin_setup.sh +pct push $CTID tvheadend_setup.sh /tvheadend_setup.sh -perms 755 +pct exec $CTID /tvheadend_setup.sh IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') info "Successfully created a Jellyfin LXC Container to $CTID at IP Address ${IP}:8096" From e3346eafb664afc1aa01d6e0f8288bb60ffacbe6 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 05:01:10 +0100 Subject: [PATCH 5/8] Updated Tvheadend port in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 355b815..48bc829 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ bash -c "$(wget -qLO - https://raw.githubusercontent.com/StevenSeifried/proxmox- After the script completes, If you're dissatisfied with the default settings, click on the LXC, then on the **_Resources_** tab and change the **_Memory_**, **_Cores_** and **_Root Disk_** (Resize disk) settings to what you desire. Changes are immediate. -**Tvheadedn Server Interface - IP:8096** +**Tvheadedn Server Interface - IP:9981** ____________________________________________________________________________________________ From d8ae1abc9d08dee7b0780a2cfcbec92629ce8ee3 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 05:02:11 +0100 Subject: [PATCH 6/8] Updated Tvheadend port in tvheadend_container.sh --- tvheadend_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tvheadend_container.sh b/tvheadend_container.sh index b3ff827..33a675c 100644 --- a/tvheadend_container.sh +++ b/tvheadend_container.sh @@ -155,5 +155,5 @@ pct push $CTID tvheadend_setup.sh /tvheadend_setup.sh -perms 755 pct exec $CTID /tvheadend_setup.sh IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') -info "Successfully created a Jellyfin LXC Container to $CTID at IP Address ${IP}:8096" +info "Successfully created a Tvheadend LXC Container to $CTID at IP Address ${IP}:9981" From e0fd475cdca2f376720b7148765dff5c0b798513 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 05:26:27 +0100 Subject: [PATCH 7/8] Updated tvheadend_setup.sh --- tvheadend_setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tvheadend_setup.sh b/tvheadend_setup.sh index 91aade5..7e9a055 100644 --- a/tvheadend_setup.sh +++ b/tvheadend_setup.sh @@ -51,8 +51,9 @@ EOF wget -qO- https://doozer.io/keys/tvheadend/tvheadend/pgp | tee /etc/apt/trusted.gpg.d/tvheadend.asc &>/dev/null echo -e "${CHECKMARK} \e[1;92m Installing Tvheadend... \e[0m" +export DEBIAN_FRONTEND=noninteractive apt-get update &>/dev/null -apt-get -y install tvheadend &>/dev/null +apt-get -yq install tvheadend &>/dev/null echo -e "${CHECKMARK} \e[1;92m Customizing Container... \e[0m" rm /etc/motd From e3fb2d27f2e10d5b34f0a7e9c40e446b3be1cbea Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Mon, 10 Jan 2022 05:31:18 +0100 Subject: [PATCH 8/8] Updated README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 48bc829..0d369f4 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,15 @@ bash -c "$(wget -qLO - https://raw.githubusercontent.com/StevenSeifried/proxmox- After the script completes, If you're dissatisfied with the default settings, click on the LXC, then on the **_Resources_** tab and change the **_Memory_**, **_Cores_** and **_Root Disk_** (Resize disk) settings to what you desire. Changes are immediate. -**Tvheadedn Server Interface - IP:9981** +**You must setup Tvheadend in LXC console first** + +Run from the LXC console and follow the instructions: + +``` +dpkg-reconfigure tvheadend +``` + +**Tvheadend Server Interface - IP:9981** ____________________________________________________________________________________________