summarylogtreecommitdiffstats
path: root/JDownloaderHeadless
blob: c3d4130920b694c461603ba54db67e698e8eaf5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -u
THIS_PATH="$(dirname "$(readlink -f "$0")")"
source "$THIS_PATH/functions.sh"

changeUser
changePath
downloadJDownloader

function showFailure(){
  local FAILURE="$1"
  if [ -t 0 ] ; then
    echo "WARNING: $FAILURE"
  else
    echo "ERROR: $FAILURE"
    echo "You could run \"JDownloaderHeadlessCleanLogin\" to remove entire MyJDownloader Settings."
    echo "Afterwards you should run \"JDownloaderHeadless\" in a terminal"
    exit 2
  fi
}
AS_DAEMON=2
if [ "${1:-}" == "--daemon" ]; then
  AS_DAEMON=0
  shift
fi

#check for config
if [ ! -f "cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json" ]; then
  showFailure "Configurationfile not set"
fi


grep email "cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json" >/dev/null
if [ $? -ne 0 ]; then
   showFailure "Email seems not to be set"
fi

grep password "cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json" >/dev/null
if [ $? -ne 0 ]; then
   showFailure "Password seems not to be set"
fi

LOGFILE="JDownloader.service.log"
if [ -t 0 -a "${AS_DAEMON}" -eq 2 ] ; then
  exec java -Djava.awt.headless=true -jar JDownloader.jar -norestart "$@"
else
  if [ -f "$LOGFILE" ]; then
    # Save the old Logfile (this automatically removes the n-2 one, if there is one)
    mv "${LOGFILE}" "${LOGFILE}.old"
  fi 
  echo "All output is redirected to \"$(readlink -f "${LOGFILE}")\"" 
  if [ "${AS_DAEMON}" -eq 0 ]; then
    nohup java -Djava.awt.headless=true -jar JDownloader.jar "$@" >"${LOGFILE}" 2>&1 &
  else
    exec java -Djava.awt.headless=true -jar JDownloader.jar "$@" >"${LOGFILE}" 2>&1 
  fi
fi
sleep 5