summarylogtreecommitdiffstats
path: root/functions.sh
blob: 39082286b7396ea6a2096684b6f7a38e5105110b (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
#!/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
		if ! curl -o JDownloader.jar https://installer.jdownloader.org/JDownloader.jar; then
			echo "Cannot download JDownloader!"
			exit 2
		fi
	fi
}

LOGFILE="JDownloader.service.log"