-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_tools_autoupdate_service.sh
executable file
·64 lines (55 loc) · 1.92 KB
/
setup_tools_autoupdate_service.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
#!/bin/bash
# Save current pwd
currentpath=$(pwd)
# Determine toolpath if not set already
relativepath="./" # Define relative path to go from this script to the root level of the tool
if [[ ! -v toolpath ]]; then scriptpath=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ); toolpath=$(realpath --canonicalize-missing ${scriptpath}/${relativepath}); fi
# Load functions
source ${toolpath}/functions.sh
# Define user
if [[ -z "${user}" ]]
then
# If it's not passed as argument then use the current User
user=$(whoami)
fi
# Define mode
if [[ -z "${schedulemode}" ]]
then
if [[ "${user}" == "root" ]]
then
schedulemode=${2:-'cron'}
else
schedulemode='systemd'
fi
fi
# Get homedir
homedir=$(get_homedir "${user}")
# Get Systemdconfigdir
systemdconfigdir=$(get_systemdconfigdir "${user}")
if [[ "${schedulemode}" == "cron" ]]
then
# Setup CRON to automatically generate updated Systemd Service files
destination="/etc/cron.d/podman-tools-autoupdate"
cp "cron/podman-tools-autoupdate" "${destination}"
chmod +x "${destination}"
replace_text "${destination}" "toolpath" "${homedir}/podman-tools" "user" "${user}"
elif [[ "${schedulemode}" == "systemd" ]]
then
# Copy Systemd Service File
filename="podman-tools-autoupdate.service"
destination="${systemdconfigdir}/${filename}"
cp "systemd/services/${filename}" "${destination}"
chmod +x "${destination}"
replace_text "${destination}" "toolpath" "${homedir}/podman-tools" "user" "${user}"
systemd_reload_enable "${user}" "${filename}"
# Copy Systemd Timer File
filename="podman-tools-autoupdate.timer"
destination="${systemdconfigdir}/${filename}"
cp "systemd/timers/${filename}" "${destination}"
chmod +x "${destination}"
replace_text "${destination}" "toolpath" "${homedir}/podman-tools" "user" "${user}"
systemd_reload_enable "${user}" "${filename}"
else
# Error
schedule_mode_not_supported "${schedulemode}"
fi