#!/bin/bash # Script: osmc-java-jdownloader-installer.sh # Author: Jozef Pažin # Description: Wizard to install the current version of jdownloader on raspberry pi running osmc kodi. # License: MIT # How to run: # - Check it first if this code is correct because this script need to be run under root # and run gist from web is not recommended procedure in terms of security # https://gist.github.com/atiris/34dc670264274b3a472f2a718e4de83a # - And then run it: # curl https://gist.github.com/atiris/34dc670264274b3a472f2a718e4de83a/raw | sudo bash # or # wget https://gist.github.com/atiris/34dc670264274b3a472f2a718e4de83a/raw | sudo bash # Inspiration: # - https://gist.github.com/ribasco/fff7d30b31807eb02b32bcf35164f11f # - https://github.com/PlusMinus0/headless-jd2-docker # - https://gist.github.com/leosuncin/50367b3c905fe8699b13bd85ad26071b if [[ "$EUID" -ne 0 ]]; then echo "" echo "Please login as root: sudo su" echo "" return fi # Colors NC='\033[0m' RED='\033[0;91m' GREEN='\033[0;92m' BLUE='\033[0;94m' YELLOW='\033[0;93m' echo "" # Java JAVA_VERSION_LOCAL=`echo $(java -version 2>&1)| awk -F \" '{print $2}'` if [[ $JAVA_VERSION_LOCAL = *[!\ ]* ]]; then echo -e "Local java version is ""$BLUE""$JAVA_VERSION_LOCAL""$NC" response="n" read -r -p $'\e[91mInstall java anyway?\e[0m [y/N] ' response response=${response,,} else echo -e "$YELLOW""Java is not installed.""$GREEN"" I will run the installation for you.""$NC" response="y" fi if [[ $response =~ ^(yes|y) ]] || [[ -z $response ]]; then echo "-----BEGIN PGP PUBLIC KEY BLOCK----- Version: SKS 1.1.5 Comment: Hostname: keyserver.ubuntu.com mI0ES9/P3AEEAPbI+9BwCbJucuC78iUeOPKl/HjAXGV49FGat0PcwfDd69MVp6zUtIMbLgkU OxIlhiEkDmlYkwWVS8qy276hNg9YKZP37ut5+GPObuS6ZWLpwwNus5PhLvqeGawVJ/obu7d7 gM8mBWTgvk0ErnZDaqaU2OZtHataxbdeW8qH/9FJABEBAAG0DUxhdW5jaHBhZCBWTEOImwQQ AQIABgUCVsN4HQAKCRAEC6TrO3+B2tJkA/jM3b7OysTwptY7P75sOnIu+nXLPlzvja7qH7Wn A23itdSker6JmyJrlQeQZu7b9x2nFeskNYlnhCp9mUGu/kbAKOx246pBtlaipkZdGmL4qXBi +bi6+5Rw2AGgKndhXdEjMxx6aDPq3dftFXS68HyBM3HFSJlf7SmMeJCkhNRwiLYEEwECACAF Akvfz9wCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDCUYJI7qFIhucGBADQnY4V1xKT 1Gz+3ERly+nBb61BSqRx6KUgvTSEPasSVZVCtjY5MwghYU8T0h1PCx2qSir4nt3vpZL1luW2 xTdyLkFCrbbIAZEHtmjXRgQu3VUcSkgHMdn46j/7N9qtZUcXQ0TOsZUJRANY/eHsBvUg1cBm 3RnCeN4C8QZrir1CeA== =CziK -----END PGP PUBLIC KEY BLOCK-----" > temporarykey.txt apt-key add temporarykey.txt rm -f temporarykey.txt echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list apt-get update apt-get install -y oracle-java8-installer apt-get install -y oracle-java8-set-default echo "" echo -e "$GREEN""Java installation is complete.""$NC" echo "Actual java vesion on your system is:" java -version else echo "Java installation skipped." fi echo "" # JDownloader if [ -e /opt/JDownloader/JDownloader.jar ]; then FILE_DATE=$(date -r /opt/JDownloader/JDownloader.jar +%Y-%m-%d) echo -e "JDownloader already installed. File date is ""$BLUE""$FILE_DATE""$NC""." echo "" response="n" read -r -p $'\e[0mRemove it and install actual JDownloader anyway?\e[0m [y/N] ' response response=${response,,} else echo -e "$YELLOW""JDownloader is not installed.""$GREEN"" Let me run it.""$NC" response="y" fi if [[ $response =~ ^(yes|y) ]] || [[ -z $response ]]; then echo -e "$BLUE" echo "I'll download JDownloader from official site jdownloader.org." echo "Then I will run the installation process several times, until JDownloader" echo "ask you for login and password. Please press \"y\" at that time, and set" echo "your credentials from my.jdownloader.org (you must first be registered)." echo "Then wait some time (few seconds) until JDownloader save this settings" echo "and interrupt JDownloader installation by pressing \"CTRL+C\"." echo "You can continue in next step with installation of daemon," echo "to start JDownloader automatically on reboot or after crash." echo -e "$NC" read -p "Press enter to OK" echo "" RUN_AS_USER=root if [[ "$RUN_AS_USER" == 'root' ]] && [[ `id -u osmc 2>/dev/null || echo -1` -ge 0 ]]; then echo "Install JDownloader with 'osmc' user rights." RUN_AS_USER=osmc fi if [[ "$RUN_AS_USER" == 'root' ]] && [[ `id -u pi 2>/dev/null || echo -1` -ge 0 ]]; then echo "Install JDownloader with 'pi' user rights." RUN_AS_USER=pi fi if [ "$RUN_AS_USER" == 'root' ]; then echo "Installing as 'root'." fi if [ ! -d /opt/JDownloader ]; then mkdir -p /opt/JDownloader echo "Folder /opt/JDownloader created." else rm -rf /opt/JDownloader/* echo "Folder for JDownloader cleaned." fi chown -fR $RUN_AS_USER:users /opt/JDownloader sudo -u $RUN_AS_USER wget -O /opt/JDownloader/JDownloader.jar --progress=bar:force http://installer.jdownloader.org/JDownloader.jar echo -e "$BLUE" echo "Starting JDownloader installation." echo "Wait for the login / password request." echo "Register here: https://my.jdownloader.org/" echo -e "$NC" doNextLoop=1 while [ $doNextLoop -eq 1 ] do doNextLoop=0 sudo -u $RUN_AS_USER java -jar /opt/JDownloader/JDownloader.jar -norestart echo "" read -r -p $'\e[0mYou have already seen a request to enter your login information?\e[0m [y/N] ' response response=${response,,} if [[ $response =~ ^(no|n| ) ]] || [[ -z $response ]]; then doNextLoop=1 fi done echo -e "$GREEN""JDownloader instalation is complete.""$NC" else echo "JDownloader installation skipped." fi echo "" # Service systemd jdownloader if [ -e /etc/systemd/system/jdownloader.service ]; then FILE_DATE=$(date -r /etc/systemd/system/jdownloader.service +%Y-%m-%d) echo "Service jdownloader already exists. File changed at $FILE_DATE." echo "" response="n" read -r -p $'\e[0mReplace existing with default service implementation?\e[0m [y/N] ' response response=${response,,} else echo -e "$YELLOW""Service for jdownloader not exists yet.""$GREEN""No worries, I will create it.""$NC" response="y" fi if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then echo "" touch /opt/JDownloader/JDownloader.pid echo "[Unit] Description=JDownloader2 headless server daemon with autorestart. After=network.target [Service] Type=simple Environment=\"DIR=/opt/JDownloader\" WorkingDirectory=\${DIR} ExecStart=/usr/bin/java -Djava.awt.headless=true -jar \${DIR}/JDownloader.jar Restart=on-failure RestartSec=10s [Install] WantedBy=multi-user.target " > /etc/systemd/system/jdownloader.service if [ -e /etc/systemd/system/jdownloader.service ]; then systemctl daemon-reload echo -e "Service /etc/systemd/user/jdownloader.service > ""$GREEN""created OK""$NC" systemctl enable jdownloader echo -e "Service jdownloader enabled > ""$GREEN""OK""$NC" systemctl start jdownloader SERVICE_STATE=$(pgrep mysql | wc -l) if ["$SERVICE_STATE" -eq 0]; then echo -e "$RED""WARNING! Service jdownloader is down.""$NC" else echo "Service jdownloader started > ""$GREEN""OK""$NC" fi echo "" echo -e "$GREEN""Service installation is complete.""$NC" echo "You can check service status with: systemctl status jdownloader" else echo -e "$RED""ERROR! I can not create a service.""$NC" fi else echo "Service installation skipped." fi echo "" # Final message echo -e "$GREEN""That's all, I hope everything works for you.""$NC" echo -e "$GREEN""Now you can check JDownloader on https://my.jdownloader.org/""$NC"