TringaliLuca

Install JDownloader2 headless (no gui) on a RaspberryPi

May 15th, 2017
766
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if [ "$(whoami)" == "root" ] ; then
  2.     echo "You are root, good."
  3. else
  4.     echo "Please run this script with sudo"
  5.     exit 1
  6. fi
  7.  
  8. if [ ! -f "/opt/jd2/JDownloader.jar" ]; then
  9.     echo "Start to download JDownloader2"
  10.     apt-get update
  11.     apt-get install openjdk-8-jre openjdk-8-jre-headless openjdk-8-jdk pv
  12.     #apt-get install -f
  13.  
  14.     jd2jar="http://installer.jdownloader.org/JDownloader.jar"
  15.  
  16.     mkdir /opt/jd2
  17.     cd /opt/jd2
  18. #    jd2jar='https://mega.nz/#!2A0EiA6B!wS9K4_31luGG4HzClQlnVpfRpbtCSdYkiqsUIXE6_c0'
  19. #    git clone https://github.com/tonikelope/megadown.git
  20. #    chmod +x /opt/jd2/megadown/megadown
  21. #    /opt/jd2/megadown/megadown $jd2jar -o /opt/jd2/JDownloader.jar
  22.  
  23.     wget -O /opt/jd2/JDownloader.jar $jd2jar
  24.     chmod -R 777 /opt/jd2
  25. fi
  26.  
  27. if [ ! -f "/lib/systemd/system/jdownloader2.service" ]; then
  28. echo "Build system service for JDownloader2"
  29.  
  30. cat << EOF > /opt/jd2/jd2.sh
  31. #!/bin/bash
  32. #/usr/bin/java -Djava.awt.headless=true -jar /opt/jd2/JDownloader.jar
  33. kill $(cat /opt/jd2/JDownloader.pid)
  34.  
  35. if [ ! -f '/opt/jd2/JDownloader.jar' ]; then
  36. cp /opt/jd2/JDownloader.jar.backup.1 /opt/jd2/JDownloader.jar
  37. fi
  38. /usr/bin/java -jar /opt/jd2/JDownloader.jar $1
  39. EOF
  40.  
  41. cat << EOF > /lib/systemd/system/jdownloader2.service
  42. [Unit]
  43. Description=JDownloader2 without GUI
  44. [Service]
  45. ExecStart=/opt/jd2/jd2.sh
  46. StandardOutput=null
  47. [Install]
  48. WantedBy=multi-user.target
  49. Alias=jdownloader2.service
  50. EOF
  51. #Add:
  52. #User=pi
  53. #Group=users
  54. #in [Service] section if you want to run jd2 as a different user than root
  55.  
  56. fi
  57.  
  58. configfile="/opt/jd2/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json"
  59.  
  60. configured="0"
  61.  
  62. while [ $configured -lt 1 ]
  63. do
  64. if [ ! -f /opt/jd2/JDownloader.jar ]; then
  65.     configured=2
  66. fi
  67.  
  68. if [ ! -f $configfile ] || [ $(less $configfile | grep '"email" : null') ]; then
  69.     echo "Configure JDownloader2"
  70.     java -jar /opt/jd2/JDownloader.jar -norestart
  71.     sleep 10
  72. else
  73.     configured=2
  74. fi
  75. done
  76.  
  77.  
  78. chmod -R 777 /opt/jd2
  79.  
  80. echo "Now please run:"
  81. echo "sudo systemctl enable jdownloader2.service"
  82. echo "sudo systemctl start jdownloader2.service"
RAW Paste Data