-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·81 lines (70 loc) · 2.37 KB
/
install.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# check the script is run as root
if [ `whoami` != "root" ] ; then
echo "ERROR: the installation program must be run by the 'root' user"
exit 1
fi
# check the user home dir is specified
if [ ! -d "$1" ] ; then
user_dir=`grep '1000:1000' /etc/passwd | awk -F ':' '{print $6}'`
if [ ! -d "${user_dir}" ] ; then
echo "ERROR: could not determine the user's home directory."
echo "The script must be called with one parameter, the location of the user's home directory."
exit 2
fi
else
user_dir="$1"
fi
# Install autovpn
props="${user_dir}/.config/autovpn.properties"
repo="https://raw.githubusercontent.com/RobinKnipe/autovpn/master/"
script_dir=/usr/share/autovpn
unit_dir=/etc/systemd/system
# ensure the "inotify-tools" package is installed
function install_prerequisits {
if ! which inotifywait > /dev/null ; then
echo 'Installing inotify-tools package'
apt update
apt install -y inotify-tools
fi
}
# setup the properties file
function install_properties {
# ...unless it already exists
if [ ! -e "${props}" ] ; then
mkdir -p "${user_dir}/.config"
echo "# the location of the user's downloads folder monitored by autovpn" > ${props}
echo "download_dir=${user_dir}/Downloads" >> ${props}
chown `ls -ld ${user_dir}/ | awk '{print $3":"$4}'` "${user_dir}/.config" "${props}"
fi
}
# download the main autovpn script file
function install_main_script {
echo 'Installing the main autovpn script file'
mkdir -p "${script_dir}"
curl -Lso "${script_dir}/autovpn" "${repo}autovpn"
chmod +x "${script_dir}/autovpn"
}
# download and activate the autovpn systemd unit
function install_unit_files {
# stop the service if it is already installed
if [ -f "${unit_dir}/autovpn.service" ] ; then
systemctl stop autovpn.service
systemctl disable autovpn.service
systemctl daemon-reload
fi
echo 'Installing the autovpn systemd unit file'
mkdir -p "${unit_dir}/autovpn.service.d"
unit_env="${unit_dir}/autovpn.service.d/env.conf"
echo "[Service]" > ${unit_env}
echo "Environment=\"USER_HOME=${user_dir}\"" >> ${unit_env}
echo "Environment=\"PROPS_FILE=${props}\"" >> ${unit_env}
curl -Lso "${unit_dir}/autovpn.service" "${repo}/autovpn.service"
systemctl daemon-reload
systemctl start autovpn.service
systemctl enable autovpn.service
}
install_prerequisits
install_properties
install_main_script
install_unit_files