summarylogtreecommitdiffstats
path: root/functions.sh
blob: dcac4f3ad1c061e39d5703620eeaf9d61b3a729e (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
#!/usr/bin/env bash

function changePath(){
  # check the groups of the current loggedin users
  groups | grep -q -E '(\s|^)jdownloader(\s|$)' >/dev/null
  if [ "$?" -eq  0 ] || isRoot ; then
    export JD_SCOPE="global"
    echo "[global JDownloader scope]"
    umask u=rwx,g=rwx,o=rx
    cd '/opt/JDownloader'
  else
    export JD_SCOPE="user"
    echo "[user JDownloader scope]"
    mkdir -p "${HOME}/.jd"
    cd "${HOME}/.jd"
  fi
}

function changeUser(){
  if isRoot ; then
    #restart as user jdownloader
    echo "changing to user \"jdownloader\""
    runuser jdownloader -c "/bin/bash $0 $@" -s /bin/bash
    exit $?
  fi
  
}

function isRoot(){
  if [ "$(id -u)" -eq "0" ]; then
    return 0
  fi
  return 2
}


function downloadJDownloader(){
  changePath
  if [ ! -f "JDownloader.jar" ]; then
    wget -O JDownloader.jar http://installer.jdownloader.org/JDownloader.jar
    if [ $? -ne 0 ]; then
      echo "Cannot download Jdownloader!"
      exit 2
    fi
  fi
}
LOGFILE="JDownloader.service.log"