-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemd-setup.sh
executable file
·106 lines (86 loc) · 2.85 KB
/
systemd-setup.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#===================================================================
#
#
# setup script for first time setup of dynup as a systemd
# service.
#
# Reed Bell - [email protected]
#
#
#===================================================================
service_script='./dynup-template.service'
actual_script='dynup.service'
systemd_path_def="$PWD"
log_path_def="$PWD"
update_def=600
verbosity_def="0"
dynup_dir_def="$PWD"
[ ! -f $service_script ] && echo "service script not found! Exiting" && exit -1
# First, we check whether this has already been done before (i.e.
# systemd service already running/.service script already exists)
printf "Checking if dynup is already setup...\n"
(systemctl is-active --quiet dynup)
stat_exit=$?
# Grab parameters
if [ $stat_exit -ne 0 ]; then
# Path to place service script
printf "Input full path to place the systemd service script [default: $systemd_path_def]\n\n"
printf "Directory: "
read -e systemd_path
[ ! -d $systemd_path ] && echo "$systemd_path is not a valid directory! Exiting..." && exit -1
if [ -z $systemd_path ]; then systemd_path=$systemd_path_def;fi
# Path to logfile
printf "Input full path to place the log file [default: $log_path_def]\n\n"
printf "Directory: "
read -e log_path
[ ! -d $log_path ] && echo "$log_path is not a valid directory! Exiting..." && exit -1
if [ -z $log_path ]; then log_path=$log_path_def;fi
# FreeDNS query
printf "Input https FreeDNS query\n\n"
printf "Query: "
read -e query
if [[ ${query} != "https:"* ]]; then echo "Query is not HTTPS or invalid. Exiting..." && exit -1; fi
# Update interval
printf "Input integer update time (min) [default: $update_def]\n\n"
printf "Update: "
read -e update
if [[ $update =~ ^-?[0-9]+$ ]];
then
: ; # Do nothing
else
echo "No valid interval entered. Using default update interval";
update=$update_def
fi
# Verbosity
printf "Input verbosity level (0, 1) [default: $verbosity_def]\n\n"
printf "Verbosity: "
read -e verbosity
if [ $verbosity == 1 ];
then
verbosity="-v"
else
echo "Using default [$verbosity_def]\n\n"
verbosity=""
fi
# dynup script placement
if [ ! -d "$HOME/bin" ];
then
printf "User bin folder not detected. Enter a location to copy dynup [default: $dynup_dir_def ]\n\n"
printf "Directory: "
read dynup_dir
if [ -z $dynup_dir ];
then
dynup_dir=$dynup_dir_def
fi
else
dynup_dir="$HOME/bin/"
fi
else
printf "dynup already setup with systemd! Exiting...\n"
exit 0
fi
[ ! -f "$dynup_dir/dynup" ] && echo "Copying dynup script to $dynup_dir" && cp "$dynup_dir_def/dynup" "$dynup_dir"
replace="ExecStart=$dynup_dir/dynup -l ${log_path}/dynup-log.log -q ${query} -f ${update} ${verbosity}"
sed "/ExecStart=/c\\${replace}" ${service_script} > ${systemd_path}/${actual_script}
echo "Created ${actual_script} and placed into ${systemd_path}/"