Files
shell_sequencer/seqs/pyload.sh

139 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
toolName="pyload"
toolBranch="stable"
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"
# python-cryptography shall be implemented in future releases and replace pyhton-crypto
toolDepsDebian="sudo git python-crypto 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() {
echo "Make sure you have the \"deb-src\" entry active in your /etc/apt/sources.list"
echo "Especially check for \"non-free\""
exe read -p "Press Enter to continue: "
exe vi /etc/apt/sources.list
exe apt update
}
step_2_info() { echo "Install unrar-nonfree from source"; }
step_2() {
exe apt-get build-dep ${toolBuildDeps} $APTOPT
exe cd /tmp
exe apt-get source -b unrar-nonfree
saveReturn $?
endReturn
exe dpkg -i unrar_*_armhf.deb
exe rm -rf unrar-*
}
step_3_info() {
echoinfoArgs "[TARGET]"
echo "Install dependencies"
echoinfo " [TARGET] (default: raspi)"
echoinfo " raspi: Raspberry Pi OS"
echoinfo " debian: Debian"
}
step_3_alias() { ALIAS="deps"; }
step_3() {
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 "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 "$PYL_INSTALL_DIR"
exe sudo -u $PYL_USER python pyLoadCore.py
}
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]
Description=Python Downloader
After=network.target
[Service]
User=pyload
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 "$PYL_INSTALL_DIR"
exe git pull
echo " [I] Service is not started automatically"
echo " Do so manually with: service $toolName start"
}
VERSION_SEQREV=14
. /usr/local/bin/sequencer.sh