jdownloader on qnap

to install jdownloader on a qnap and using it over the webinterface you need to follow this steps

first you need to install „Entware“ with this script https://raw.githubusercontent.com/Entware/installer.sh/master/generic.sh

then you need to install JRE over the QNAP Store

register an account on https://my.jdownloader.org

now you need to run this code

#!/bin/bash

clear

/bin/echo ""
/bin/echo "============================================================="
/bin/echo "            JDownloader2 QPKG Installer script"
/bin/echo "============================================================="
/bin/echo ""

JAVA_HOME_TEST=$(/bin/cat /etc/profile | awk '/JAVA_HOME=/ { print $2 }' | tail -c +11)
CONF=/etc/config/qpkg.conf
QPKG_NAME="JDownloader2"
QPKG_DIR=$(/sbin/getcfg $QPKG_NAME Install_Path -f $CONF)
JD2_UPDATE_FILE="jd2_update"
JD2_UPDATE_LINK="https://www.dropbox.com/s/gmp6wu95b3wyecm/$JD2_UPDATE_FILE"
JD2_JAR_FILE="http://installer.jdownloader.org/JDownloader.jar"
JAR_FILENAME=`/bin/echo $JD2_JAR_FILE | cut -d'/' -f 4`

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

if [ ! -z $QPKG_DIR ] ; then
  /bin/echo "===================================================================================="
  /bin/echo "JDownloader2 is already installed, please remove it if you want to install it again!"
  /bin/echo "===================================================================================="
  /sbin/write_log "JDownloader2 is already installed, please remove it if you want to install it again!" 1
  exit
fi

QPKG_DIR=

# Determine BASE installation location according to smb.conf
BASE=
publicdir=`/sbin/getcfg Public path -f /etc/config/smb.conf`
if [ ! -z $publicdir ] && [ -d $publicdir ];then
  publicdirp1=`/bin/echo $publicdir | /bin/cut -d "/" -f 2`
  publicdirp2=`/bin/echo $publicdir | /bin/cut -d "/" -f 3`
  publicdirp3=`/bin/echo $publicdir | /bin/cut -d "/" -f 4`
  if [ ! -z $publicdirp1 ] && [ ! -z $publicdirp2 ] && [ ! -z $publicdirp3 ]; then
    [ -d "/${publicdirp1}/${publicdirp2}/Public" ] && BASE="/${publicdirp1}/${publicdirp2}"
  fi
fi

# Determine BASE installation location by checking where the Public folder is.
if [ -z $BASE ]; then
  for datadirtest in /share/HDA_DATA /share/HDB_DATA /share/HDC_DATA /share/HDD_DATA /share/MD0_DATA; do
    [ -d $datadirtest/Public ] && BASE="$datadirtest"
  done
fi
if [ -z $BASE ] ; then
  /bin/echo "The Public share not found."
  exit
fi

#JD2_TMP_DIR="$publicdir/$JD2_DIR"

CheckForOpt(){ #Does /opt exist? if not check if it's optware that's installed or opkg, and start the package 
  /bin/echo -n " Checking for /opt..."
  if [ ! -d /opt/bin ]; then
    if [ -x /etc/init.d/Optware.sh ]; then #if optware ,start optware
      /bin/echo "  Starting Optware..."
      /etc/init.d/Optware.sh start
      sleep 2
    elif [ -x /etc/init.d/opkg.sh ]; then #if opkg, start opkg  
      /bin/echo "  Starting Opkg..."    
      /etc/init.d/opkg.sh start
      sleep 2
    elif [ -x /etc/init.d/Entware-ng.sh ]; then #if Entware-ng, start Entware-ng  
      /bin/echo "  Starting Entware-ng..."    
      /etc/init.d/Entware-ng.sh start
      sleep 2
    else #catch all
      /bin/echo "  No Optware or Opkg or Entware-ng found, please install one of them"    
      /sbin/write_log "Failed to start $QPKG_NAME, no Optware or Opkg or Entware-ng found. Please re-install one of those packages" 1 
      exit 1
    fi
  else
    /bin/echo "  Found!"
  fi
  }

pid_check() {
  # Check if process is already running
  PROCESS_PID=0
  for pid in $(/bin/pidof java); do
    # Try to find if the process is JDownloader
    /bin/grep -q "JDownloader" /proc/$pid/cmdline
    if [ $? -eq 0 ]; then
    # Process found, save PID and exit loop
    PROCESS_PID=$pid
    break
    fi
  done
  # Print result
  #/bin/echo "Pid of process = $PROCESS_PID"
  }

Shutdown_jd2() { #kills a proces based on a PID in a given PID file
  pid_check
  /bin/echo -n "Checking if $QPKG_NAME is running... "
  if [[ $PROCESS_PID -eq 0 ]]; then
    /bin/echo "$QPKG_NAME is not running!"
  else
    /bin/echo "Shutting down $QPKG_NAME... "
    i=0
    /bin/kill $PROCESS_PID
    /bin/echo -n "Waiting for $QPKG_NAME to shut down: "
    while [ -d /proc/$PROCESS_PID ]; do
      /bin/sleep 1
      let i+=1
      /bin/echo -n "$i, "
      if [ $i = 45 ]; then
        /bin/echo "   Tired of waiting, killing $QPKG_NAME now"
        /bin/kill -9 $PROCESS_PID
        exit 1
      fi
    done
    /bin/echo "Done"
  fi
  }

java_check() {
  /bin/echo -n "Checking for Java... "
  if [ -z "$JAVA_HOME_TEST" ]; then
    /bin/echo "Java PATH not found. Please install JRE QPKG from http://goo.gl/ayMIbE or via the Qnap App Center"
    /bin/echo "NOTE: If you have just installed Java, close and reopen your session to update (putty)."
    exit 1
  else
    /bin/echo "Found... exporting variables"
    export JAVA_HOME=$JAVA_HOME_TEST
  fi

  # Store JAVA binary path
  JAVA_BIN=${JAVA_HOME_TEST}/bin/java
  
  # Check if Java runs correctly
  /bin/echo -n "Checking for Java executable... "
  if ! $JAVA_BIN -version 2>&1 | /bin/grep -q "Java(TM)"; then
    /bin/echo "Java does not run correctly. Please test the Java environment and try again."
    exit 2
  fi
    /bin/echo "All OK!"
  }

countdown() {
  local OLD_IFS="${IFS}"
  IFS=":"
  local ARR=( $1 ) ; shift
  IFS="${OLD_IFS}"
  local PREFIX="$*" ; [ -n "${PREFIX}" ] && PREFIX="${PREFIX} > "
  local SECONDS=$((  (ARR[0] * 60 * 60) + (ARR[1] * 60) + ARR[2]  ))
  local START=$(date +%s)
  local END=$((START + SECONDS))
  local CUR=$START
 
  while [[ $CUR -lt $END ]]
  do
          CUR=$(date +%s)
          LEFT=$((END-CUR))

          printf "\r${PREFIX}%02d:%02d:%02d" \
                  $((LEFT/3600)) $(( (LEFT/60)%60)) $((LEFT%60))

          /bin/sleep 1
  done
  printf "\nOk, now I resume the installation\n"
  }

jar_download() {
  if [[ ! -d $JD2_DEST_DIR ]]; then
    /bin/mkdir -p $JD2_DEST_DIR
  fi
  /bin/echo -n "Info: Downloading $QPKG_NAME Jar file... "
  if /usr/bin/wget --no-check-certificate $JD2_JAR_FILE --directory-prefix=$JD2_DEST_DIR 1>/dev/null 2>&1 ; then
    /bin/echo "Done"
    /bin/sleep 2
  else
    /bin/echo "Error!"
    /bin/echo "Couldn't download $QPKG_NAME Jar file. Please check your internet connection and try again."
    exit 0
  fi
  }

cleanup() {
if [[ -f "$publicdir/$JD2_UPDATE_FILE" ]]; then
  rm -rf "$publicdir/$JD2_UPDATE_FILE"
fi
if [[ -f "$publicdir/$QPKG_FILE" ]]; then
  rm -rf "$publicdir/$QPKG_FILE"
fi
  }

set_variables() {
QPKG_DIR=$(/sbin/getcfg $QPKG_NAME Install_Path -f $CONF)
JD2_DEST_DIR="$QPKG_DIR/jd2"
  }

qpkg_download_and_install() {
  echo -n "Info: Downloading update file ... "
  if /usr/bin/wget --no-check-certificate $JD2_UPDATE_LINK --directory-prefix=$publicdir 1>/dev/null 2>&1 ; then
    echo "Done."
  else
    echo "Failed."
    /bin/echo "Oops, couldn't download JDownloader2 update file. Please check your internet connection."
    exit 0
  fi
  
  export DLINK=`/sbin/getcfg JDownloader2 dl_link -f $publicdir/$JD2_UPDATE_FILE`
  QPKG_FILE=`echo $DLINK | cut -d'/' -f 6`

  echo "Info: Starting download QPKG ... "
  
  if [[ -f "$publicdir/$JD2_UPDATE_FILE" ]]; then
    rm -rf "$publicdir/$JD2_UPDATE_FILE"
  fi

  if /usr/bin/wget --no-check-certificate -O $publicdir/$QPKG_FILE $DLINK 1>/dev/null 2>&1 ; then
    echo "Info: Download completed succesfully"
  else
    echo "Failed."
    /bin/echo "Oops, couldn't download JDownloader2 QPKG file."
    exit 0
  fi
      echo "Info: Installing the QPKG ..."
      /bin/sh $publicdir/$QPKG_FILE
      if [ "$?" != "0" ]; then
        echo "Info: Installation succesfully completed."
        /sbin/write_log "JDownloader2 QPKG succesfully installed." 4
      else 
        echo "Error occured during JDownloader2 QPKG installation."
        /sbin/write_log "Error occured during JDownloader2 QPKG installation!" 1
        rm -rf "$publicdir/$QPKG_FILE"
        exit 0
      fi
    }

umask 000
CheckForOpt
java_check
qpkg_download_and_install
set_variables
jar_download
cd $JD2_DEST_DIR && $JAVA_BIN -Djava.awt.headless=true -jar $JD2_DEST_DIR/$JAR_FILENAME
countdown "00:00:10" "Please Wait ..."
Shutdown_jd2
cd $JD2_DEST_DIR && $JAVA_BIN -Djava.awt.headless=true -jar $JD2_DEST_DIR/$JAR_FILENAME
Shutdown_jd2
cleanup
/bin/echo "=========================================================================================="
/bin/echo "All done!!! Remember to log-in to https://my.jdownloader.org/login.html and configure JD2!"
/bin/echo "=========================================================================================="
/bin/echo ""
read -s -n 1 -p "Ok, now press any key to continue, then you can terminate this ssh session. Have a Good Download!!!"
/etc/init.d/JDownloader2.sh start &
exit

during the setup you need to register your account

now you can manage your download over the webinterdace on myjdownloader