-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsarotund.sh
156 lines (128 loc) · 3.11 KB
/
sarotund.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# https://github.com/maximuskowalski/maxmisc/blob/master/sarotund.sh
# an sarotate installer
# https://github.com/saltydk/SARotate
set -Eeuo pipefail
IFS=$'\n\t'
# Grab service files dir
# and semi config... maybe later
# systemd? maybe var
#________ VARS
APP=sarotate
APPDIR=/opt
SYSDINST=true # creates systemd file and enables but does not start
#________ DONT CHANGE
MNTPNT=${APPDIR}/${APP}
CRNTVERS=https://github.com/saltydk/SARotate/releases/download/v1.0.1/SARotate
CONFIGUS="${MNTPNT}/config.yaml.sample"
#________ FUNCTIONS
rooter() {
if [ "$(whoami)" = root ]; then
echo "${BRED} Running as root or with sudo is not supported. Exiting.${RESET}"
exit
fi
}
checkoff() {
([ -d "${MNTPNT}" ] || dirmkr)
}
dirmkr() {
sudo mkdir -p "${MNTPNT}" && sudo chown "${USER}":"${USER}" "${MNTPNT}"
}
fetching() {
wget -c "${CRNTVERS}" -O ${MNTPNT}/SARotate
chmod +x ${MNTPNT}/SARotate
}
configo() {
cat >"${CONFIGUS}" <<EOF
rclone:
rclone_config: "/home/${USER}/.config/rclone/rclone.conf"
rc_user: "user"
rc_pass: "pass"
sleeptime: 300
remotes:
'/opt/sa':
seedbox-drive: localhost:5575
'/opt/sa2':
Movies: localhost:5575
Movies-4K: localhost:5575
Movies-Danish: localhost:5575
TV: localhost:5575
TV-4K: localhost:5575
TV-Anime: localhost:5575
notification:
errors_only: y
apprise:
- 'discord://<webhook>'
EOF
}
sysdcheck() {
([ $SYSDINST = true ] && sysdmaker && enabler) || :
}
sysdmaker() {
sudo bash -c 'cat > /etc/systemd/system/sarotate.service' <<EOF
# /etc/systemd/system/sarotate.service
[Unit]
Description=sarotate
After=network-online.target
[Service]
User=${USER}
Group=${USER}
Type=simple
WorkingDirectory=${MNTPNT}
ExecStart=${MNTPNT}/SARotate
ExecStartPre=/bin/sleep 30
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
EOF
sudo bash -c 'cat > /etc/systemd/system/sarotate.timer' <<EOF
# /etc/systemd/system/sarotate.timer
[Unit]
Description=sarotate boot delay
[Timer]
OnBootSec=10min
[Install]
WantedBy=timers.target
EOF
}
enabler() {
sudo systemctl enable sarotate.service && sudo systemctl enable sarotate.timer && sudo systemctl daemon-reload
echo
echo
echo
echo " systemd file created and enabled"
echo " WARNING: SARotate service will be"
echo " started on the next reboot."
echo " or after editing and comfirming valid config"
echo " to start the system service manually now "
echo " sudo systemctl start sarotate.service"
}
messaging() {
echo
echo " For documentation see"
echo " https://github.com/saltydk/SARotate"
echo
echo " a sample configuration is files is located here"
echo " ${MNTPNT}/config.yaml.sample"
echo " copy and edit or create ${MNTPNT}/config.yaml"
echo " before attempting to start"
echo
}
fin() {
echo
echo " **************************"
echo " * ---------------------- *"
echo " * - install completed! - *"
echo " * ---------------------- *"
echo " **************************"
echo
}
#________ RUNLIST
rooter
checkoff
fetching
configo
sysdcheck
messaging
fin