diff --git a/seqs/pyload.cfg.example b/seqs/pyload.cfg.example new file mode 100644 index 0000000..0e4a334 --- /dev/null +++ b/seqs/pyload.cfg.example @@ -0,0 +1,5 @@ +#!/bin/bash + +PYL_USER="pyload" +PYL_INSTALL_DIR="/opt/pyload" +PYL_CONFIG_DIR="/home/pyload" diff --git a/seqs/pyload.sh b/seqs/pyload.sh index d8e4e74..b3555d9 100755 --- a/seqs/pyload.sh +++ b/seqs/pyload.sh @@ -1,12 +1,33 @@ #!/bin/bash toolName="pyload" -toolUser="${toolName}" toolBranch="stable" -toolLoc=/opt/pyload toolDownload="https://github.com/pyload/pyload.git" toolDeps="git liblept5 python python-crypto python-pycurl python-imaging python-sleekxmpp tesseract-ocr zip unzip python-openssl libmozjs-24-bin" +toolDepsDebian="sudo git python-cryptodome python-pycurl python-pil python-sleekxmpp tesseract-ocr zip unzip pyhton-openssl libmozjs-60-dev" toolBuildDeps="rar unrar-nonfree" +# Get script working directory +# (when called from a different directory) +WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)" +APTOPT= +CONFIG=0 +SCRIPT_NAME=$(basename -- $0) +SCRIPT_NAME=${SCRIPT_NAME%%.*} +CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg" +CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" + +step_config() { + initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" + if [ $? -eq 0 ] ; then + CONFIG=1 + else + # End if no configuration file exists + [ $DRY -eq 0 ] && return 1 + fi + [ $QUIET -ne 0 ] && APTOPT="-y" + return 0 +} + step_1_info() { echo "Apt sources.list check and update"; } step_1_alias() { ALIAS="install"; } step_1() { @@ -17,15 +38,10 @@ step_1() { exe apt update } -step_2_info() { echo "Install dependencies $toolDeps $toolBuildDeps"; } +step_2_info() { echo "Install unrar-nonfree from source"; } step_2() { - exe apt-get install ${toolDeps} - exe apt-get build-dep ${toolBuildDeps} - saveReturn $? - endReturn - cd /usr/bin - exe ln -s js24 js - cd /tmp + exe apt-get build-dep ${toolBuildDeps} $APTOPT + exe cd /tmp exe apt-get source -b unrar-nonfree saveReturn $? endReturn @@ -33,47 +49,88 @@ step_2() { exe rm -rf unrar-* } -step_3_info() { echo "Get $toolName from $toolDownload and create dedicated user"; } +step_3_info() { + echo "Install dependencies for [TARGET]" + echoinfo " [TARGET] (default: raspi)" + echoinfo " raspi: Raspberry Pi OS" + echoinfo " debian: Debian" +} +step_3_alias() { ALIAS="deps"; } step_3() { - exe git clone -b $toolBranch $toolDownload "$toolLoc" - endReturn -o $? "Git clone failed" - exe adduser --system "$toolUser" + shift + local lDeps="$toolDeps" + case "$1" in + debian) + lDeps="$toolDepsDebian";; + raspi);; + *) + echoerr " [E] Unrecognized target" + return 1;; + esac + exe apt-get install ${lDeps} $APTOPT + saveReturn $? + endReturn + case "$1" in + raspi) + exe cd /usr/bin + exe ln -s js24 js;; + debian) + exe cd /usr/bin + exe ln -s js60 js;; + esac } -step_4_info() { echo "Make initial configuration"; } +step_4_info() { echo "Get $toolName from $toolDownload and create dedicated user"; } step_4() { + exe git clone -b $toolBranch $toolDownload "$PYL_INSTALL_DIR" + endReturn -o $? "Git clone failed" + exe adduser --system --home "$PYL_CONFIG_DIR" "$PYL_USER" +} + +step_5_info() { echo "Make initial configuration"; } +step_5() { echo "Webinterface server \"threaded\" is recommended on a raspberry pi." exe read -p "Press Enter to continue: " - exe cd "$toolLoc" - exe sudo -u $toolUser python pyLoadCore.py + exe cd "$PYL_INSTALL_DIR" + exe sudo -u $PYL_USER python pyLoadCore.py } -step_5_info() { echo "Create systemd service"; } -step_5() { - addConf -c "$toolService" "$toolServiceLoc" +step_6_info() { echo "Create systemd service"; } +step_6() { + local lService=`eval "echo \"$toolService\""` + addConf -c "$lService" "$toolServiceLoc" } toolServiceLoc="/etc/systemd/system/pyload.service" -toolService="\ -[Unit] +toolService="[Unit] Description=Python Downloader After=network.target [Service] User=pyload -ExecStart=/usr/bin/python /opt/pyload/pyLoadCore.py +ExecStart=/usr/bin/python \${PYL_INSTALL_DIR}/pyLoadCore.py [Install] WantedBy=multi-user.target" +step_7_info() { echo "Add ufw rules"; } +step_7_alias() { ALIAS="ufw"; } +step_7() { + echoseq " [I] Port 9666 needs to be forwarded to the target machine with ssh" + echoseq " ssh -L 9666:localhost:9666 user@host -N" + exe ufw allow in on eth0 to any port 8000 proto tcp comment "pyload webinterface" + exe ufw allow in on eth0 to any port 7227 proto tcp comment "pyload remotes" + exe ufw allow out on eth0 to 192.168.23.20 port 5222 proto tcp comment "XMPP Connection" +} + step_10_info() { echo "Upgrade to latest version of branch $toolBranch"; } step_10_alias() { ALIAS="upgrade"; } step_10() { exe service $toolName stop - exe cd $toolLoc + exe cd "$PYL_INSTALL_DIR" exe git pull echo " [I] Service is not started automatically" echo " Do so manually with: service $toolName start" } -VERSION_SEQREV=10 +VERSION_SEQREV=12 . /usr/local/bin/sequencer.sh