From 9860dda3a0fda1ceada801ef9cc97e2ea028bf6d Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 10:50:10 +0100 Subject: [PATCH 1/9] Added jdownloader2_container.sh and jdownloader2_setup.sh --- jdownloader2_container.sh | 159 ++++++++++++++++++++++++++++++++++++++ jdownloader2_setup.sh | 73 +++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 jdownloader2_container.sh create mode 100644 jdownloader2_setup.sh diff --git a/jdownloader2_container.sh b/jdownloader2_container.sh new file mode 100644 index 0000000..da3046a --- /dev/null +++ b/jdownloader2_container.sh @@ -0,0 +1,159 @@ +#!/usr/bin/env bash + +while true; do + read -p "This will create a new jdownloader2 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/jdownloader2/jdownloader2_setup.sh +#wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_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=32G +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=jdownloader2 +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 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 + +echo -e "${CHECKMARK} \e[1;92m Starting LXC Container... \e[0m" +pct start $CTID +pct push $CTID jdownloader2_setup.sh /jdownloder2_setup.sh -perms 755 +pct exec $CTID /jdownloader2_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/jdownloader2_setup.sh b/jdownloader2_setup.sh new file mode 100644 index 0000000..f4b4f80 --- /dev/null +++ b/jdownloader2_setup.sh @@ -0,0 +1,73 @@ +#!/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 \ + wget \ + sudo \ + openjdk-11-jre-headless &>/dev/null + +echo -e "${CHECKMARK} \e[1;92m Create user for jdownloader2... \e[0m" +useradd -s /sbin/nologin jdown2 + +echo -e "${CHECKMARK} \e[1;92m Create folder for jdownloader2... \e[0m" +mkdir /opt/jdown2 +chown jdown2. /opt/jdown2 +cd /opt/jdown2 + +echo -e "${CHECKMARK} \e[1;92m Downloading jdownloader2... \e[0m" +sudo -u jdown2 wget http://installer.jdownloader.org/JDownloader.jar +wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2_setup.sh +#wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_setup.sh + +echo -e "${CHECKMARK} \e[1;92m Enable and start systemd service for jdownloader2... \e[0m" +systemctl daemon-reload +systemctl enable --now jdownloader2 + +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 /jdownloader2_setup.sh /var/{cache,log}/* /var/lib/apt/lists/* From 269766ff3eb4a31b8cfee908d9e0748ca2663f29 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 10:50:29 +0100 Subject: [PATCH 2/9] Added jdownloader2.service --- jdownloader2.service | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 jdownloader2.service diff --git a/jdownloader2.service b/jdownloader2.service new file mode 100644 index 0000000..9a33d2f --- /dev/null +++ b/jdownloader2.service @@ -0,0 +1,14 @@ +[Unit] +Description=jDownloader2 Java Daemon +After=network.target + +[Service] +User=jdown2 +Group=jdown2 +Type=simple +ExecStart=/usr/bin/java -jar /opt/jdown2/JDownloader.jar -norestart +TimeoutStopSec=20 +KillSignal=SIGABRT + +[Install] +WantedBy=multi-user.target \ No newline at end of file From 1979281be8a766e8a67c9c7e8fa30cf762ac003d Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 10:54:15 +0100 Subject: [PATCH 3/9] Updated README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 0d369f4..46ed2d9 100644 --- a/README.md +++ b/README.md @@ -161,3 +161,21 @@ dpkg-reconfigure tvheadend ____________________________________________________________________________________________ + +
+Jellyfin Server LXC + +

Jellyfin Server LXC

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

Default Settings: 2GB RAM - 32GB 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. + +____________________________________________________________________________________________ + +
From e7a6dc33f956575786047ddb513d225289fe4538 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 10:59:44 +0100 Subject: [PATCH 4/9] Updated jdownloader2_container.sh --- jdownloader2_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdownloader2_container.sh b/jdownloader2_container.sh index da3046a..f9b3279 100644 --- a/jdownloader2_container.sh +++ b/jdownloader2_container.sh @@ -155,5 +155,5 @@ pct push $CTID jdownloader2_setup.sh /jdownloder2_setup.sh -perms 755 pct exec $CTID /jdownloader2_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 Jellyfin LXC Container to $CTID at IP Address ${IP}" From c42cfef0a626770545d7352e1579aba0a6d36142 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 11:16:32 +0100 Subject: [PATCH 5/9] Updated jdownloader2_setup.sh --- jdownloader2_setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdownloader2_setup.sh b/jdownloader2_setup.sh index f4b4f80..4c8b3e4 100644 --- a/jdownloader2_setup.sh +++ b/jdownloader2_setup.sh @@ -49,8 +49,8 @@ cd /opt/jdown2 echo -e "${CHECKMARK} \e[1;92m Downloading jdownloader2... \e[0m" sudo -u jdown2 wget http://installer.jdownloader.org/JDownloader.jar -wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2_setup.sh -#wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_setup.sh +wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2_service.sh +#wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_service.sh echo -e "${CHECKMARK} \e[1;92m Enable and start systemd service for jdownloader2... \e[0m" systemctl daemon-reload From 44a2d56fea0996de7989eff629377c355d897844 Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 11:18:03 +0100 Subject: [PATCH 6/9] Updated jdownloader2_container.sh --- jdownloader2_setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdownloader2_setup.sh b/jdownloader2_setup.sh index 4c8b3e4..a02673e 100644 --- a/jdownloader2_setup.sh +++ b/jdownloader2_setup.sh @@ -49,8 +49,8 @@ cd /opt/jdown2 echo -e "${CHECKMARK} \e[1;92m Downloading jdownloader2... \e[0m" sudo -u jdown2 wget http://installer.jdownloader.org/JDownloader.jar -wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2_service.sh -#wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_service.sh +wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2.service +#wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2.service echo -e "${CHECKMARK} \e[1;92m Enable and start systemd service for jdownloader2... \e[0m" systemctl daemon-reload From 71b04eec3bea50cb9383b8abe3af1714df42da1d Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 11:30:17 +0100 Subject: [PATCH 7/9] Updated jdownloader2_container.sh --- jdownloader2_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdownloader2_container.sh b/jdownloader2_container.sh index f9b3279..a730b9c 100644 --- a/jdownloader2_container.sh +++ b/jdownloader2_container.sh @@ -151,7 +151,7 @@ pct unmount $CTID && unset MOUNT echo -e "${CHECKMARK} \e[1;92m Starting LXC Container... \e[0m" pct start $CTID -pct push $CTID jdownloader2_setup.sh /jdownloder2_setup.sh -perms 755 +pct push $CTID jdownloader2_setup.sh /jdownloader2_setup.sh -perms 755 pct exec $CTID /jdownloader2_setup.sh IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}') From 718c436a48d71df494a040f3bd810289a29e918a Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 11:39:39 +0100 Subject: [PATCH 8/9] Updated jdownloader2_container.sh and jdownloader2_setup.sh before merge --- jdownloader2_container.sh | 4 +--- jdownloader2_setup.sh | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/jdownloader2_container.sh b/jdownloader2_container.sh index a730b9c..92ae464 100644 --- a/jdownloader2_container.sh +++ b/jdownloader2_container.sh @@ -72,8 +72,7 @@ function load_module() { TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null -wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2_setup.sh -#wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_setup.sh +wget -qL https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2_setup.sh load_module overlay @@ -156,4 +155,3 @@ pct exec $CTID /jdownloader2_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}" - diff --git a/jdownloader2_setup.sh b/jdownloader2_setup.sh index a02673e..134dd8f 100644 --- a/jdownloader2_setup.sh +++ b/jdownloader2_setup.sh @@ -49,8 +49,7 @@ cd /opt/jdown2 echo -e "${CHECKMARK} \e[1;92m Downloading jdownloader2... \e[0m" sudo -u jdown2 wget http://installer.jdownloader.org/JDownloader.jar -wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/jdownloader2/jdownloader2.service -#wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2.service +wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2.service echo -e "${CHECKMARK} \e[1;92m Enable and start systemd service for jdownloader2... \e[0m" systemctl daemon-reload From 75f9547adf7de90ff60b242db3ce7bab336b540d Mon Sep 17 00:00:00 2001 From: Steven Seifried Date: Sat, 15 Jan 2022 11:48:15 +0100 Subject: [PATCH 9/9] Updated files --- README.md | 8 ++++++++ jdownloader2_setup.sh | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 46ed2d9..116f2a7 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,14 @@ 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. +**You must setup jdownloader2 in LXC console first** + +Run from the LXC console and follow the instructions: + +``` +sudo -u jdown2 java -jar /opt/jdown2/JDownloader.jar -norestart +``` + ____________________________________________________________________________________________ diff --git a/jdownloader2_setup.sh b/jdownloader2_setup.sh index 134dd8f..37bf4cb 100644 --- a/jdownloader2_setup.sh +++ b/jdownloader2_setup.sh @@ -49,11 +49,11 @@ cd /opt/jdown2 echo -e "${CHECKMARK} \e[1;92m Downloading jdownloader2... \e[0m" sudo -u jdown2 wget http://installer.jdownloader.org/JDownloader.jar -wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2.service +wget -O /etc/systemd/system/jdownloader2.service https://raw.githubusercontent.com/StevenSeifried/proxmox-scripts/main/jdownloader2.service &>/dev/null echo -e "${CHECKMARK} \e[1;92m Enable and start systemd service for jdownloader2... \e[0m" -systemctl daemon-reload -systemctl enable --now jdownloader2 +systemctl daemon-reload &>/dev/null +systemctl enable jdownloader2 &>/dev/null echo -e "${CHECKMARK} \e[1;92m Customizing Container... \e[0m" rm /etc/motd