-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·302 lines (267 loc) · 9.38 KB
/
init
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
### GLOBAL VARIABLES
REPOSITORY_URL="https://raw.githubusercontent.com/chadwagoner/alpine-linux-pdc/main"
HEADER_NO_CACHE="Cache-Control: no-cache, no-store"
### GLOBAL FUNCTIONS
create_directory () {
mkdir -p $1
}
create_file () {
touch $1
}
set_ownership () {
chown $2:$2 $1
}
set_permission () {
chmod $2 $1
}
### INSTALL REQUIRED BASE PACKAGES
echo -e "INSTALLING BASE PACKAGES"
apk add -U curl lm-sensors ncurses yq --quiet
echo -e ""
### CREATE CONFIG DIRECTORY
if [[ ! -d /root/.config/alpine-linux-pdc ]]; then
echo -e "CONFIG DIRECTORY MISSING, CREATING..."
create_directory /root/.config/alpine-linux-pdc
echo -e ""
else
echo -e "CONFIG DIRECTORY EXISTS, SKIPPING..."
echo -e ""
fi
### SET CONFIG DIRECTORY OWNERSHIP
if [[ "$(stat -c '%U:%G' /root/.config/alpine-linux-pdc)" != "root:root" ]]; then
echo -e "CONFIG DIRECTORY OWNERSHIP IS WRONG, CHANGING..."
set_ownership /root/.config/alpine-linux-pdc root
echo -e ""
else
echo -e "CONFIG DIRECTORY OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET CONFIG DIRECTORY PERMISSIONS
if [[ "$(stat -c '%a' /root/.config/alpine-linux-pdc)" != 600 ]]; then
echo -e "CONFIG DIRECTORY PERMISSIONS ARE WRONG, CHANGING..."
set_permission /root/.config/alpine-linux-pdc 600
echo -e ""
else
echo -e "CONFIG DIRECTORY PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
### CREATE CONFIG FILE
if [[ ! -f /root/.config/alpine-linux-pdc/config.yaml ]]; then
echo -e "CONFIG FILE MISSING, CREATING..."
create_file /root/.config/alpine-linux-pdc/config.yaml
echo -e ""
else
echo -e "CONFIG FILE EXISTS, SKIPPING..."
echo -e ""
fi
### SET CONFIG FILE OWNERSHIP
if [[ "$(stat -c '%U:%G' /root/.config/alpine-linux-pdc/config.yaml)" != "root:root" ]]; then
echo -e "CONFIG FILE OWNERSHIP IS WRONG, CHANGING..."
set_ownership /root/.config/alpine-linux-pdc/config.yaml root
echo -e ""
else
echo -e "CONFIG FILE OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET CONFIG FILE PERMISSIONS
if [[ "$(stat -c '%a' /root/.config/alpine-linux-pdc/config.yaml)" != 600 ]]; then
echo -e "CONFIG FILE PERMISSIONS ARE WRONG, CHANGING..."
set_permission /root/.config/alpine-linux-pdc/config.yaml 600
echo -e ""
else
echo -e "CONFIG FILE PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
### UPDATE CRON SCHEDULES
LOCAL_ROOT=$(cat /etc/crontabs/root | sha256sum | awk '{print $1}')
REMOTE_ROOT=$(curl -sL -H '$HEADER_NO_CACHE' $REPOSITORY_URL/templates/crontab/root | sha256sum | awk '{print $1}')
if [[ $LOCAL_ROOT != $REMOTE_ROOT ]]; then
echo -e "CRON FILE MISMATCH, UPDATING..."
curl -sL -o /etc/crontabs/root -H '$HEADER_NO_CACHE' $REPOSITORY_URL/templates/crontab/root
echo -e ""
### SET CRON FILE OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/crontabs/root)" != "root:root" ]]; then
echo -e "CRON FILE OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/crontabs/root root
echo -e ""
else
echo -e "CRON FILE OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET CRON FILE PERMISSIONS
if [[ "$(stat -c '%a' /etc/crontabs/root)" != 600 ]]; then
echo -e "CRON FILE PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/crontabs/root 600
echo -e ""
else
echo -e "CRON FILE PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
### RESTART CRON SERVICE
echo -e "CRON FILE UPDATED, RESTARTING..."
rc-service crond restart --quiet
echo -e ""
else
echo -e "CRON FILE LATEST, SKIPPING..."
echo -e ""
fi
### INSTALL OS-UPDATER
if [[ ! -f /etc/periodic/monthly/os-updater ]]; then
echo -e "OS-UPDATER MISSING, INSTALLING..."
curl -sL -o /etc/periodic/monthly/os-updater -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/os-updater
echo -e ""
### SET OS-UPDATER OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/periodic/monthly/os-updater)" != "root:root" ]]; then
echo -e "OS-UPDATER OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/periodic/monthly/os-updater root
echo -e ""
else
echo -e "OS-UPDATER OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET OS-UPDATER PERMISSIONS
if [[ "$(stat -c '%a' /etc/periodic/monthly/os-updater)" != 700 ]]; then
echo -e "OS-UPDATER PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/periodic/monthly/os-updater 700
echo -e ""
else
echo -e "OS-UPDATER PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
else
LOCAL_OS_UPDATER=$(cat /etc/periodic/monthly/os-updater | sha256sum | awk '{print $1}')
REMOTE_OS_UPDATER=$(curl -sL -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/os-updater | sha256sum | awk '{print $1}')
if [[ $LOCAL_OS_UPDATER != $REMOTE_OS_UPDATER ]]; then
echo -e "OS-UPDATER MISMATCH, UPDATING..."
curl -sL -o /etc/periodic/monthly/os-updater -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/os-updater
echo -e ""
### SET OS-UPDATER OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/periodic/monthly/os-updater)" != "root:root" ]]; then
echo -e "OS-UPDATER OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/periodic/monthly/os-updater root
echo -e ""
else
echo -e "OS-UPDATER OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET OS-UPDATER PERMISSIONS
if [[ "$(stat -c '%a' /etc/periodic/monthly/os-updater)" != 700 ]]; then
echo -e "OS-UPDATER PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/periodic/monthly/os-updater 700
echo -e ""
else
echo -e "OS-UPDATER PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
else
echo -e "OS-UPDATER LATEST, SKIPPING..."
echo -e ""
fi
fi
### INSTALL PDC
if [[ ! -f /etc/periodic/hourly/pdc ]]; then
echo -e "PDC MISSING, INSTALLING..."
curl -sL -o /etc/periodic/hourly/pdc -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/pdc
echo -e ""
### SET PDC OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/periodic/hourly/pdc)" != "root:root" ]]; then
echo -e "PDC OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/periodic/hourly/pdc root
echo -e ""
else
echo -e "PDC OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET PDC PERMISSIONS
if [[ "$(stat -c '%a' /etc/periodic/hourly/pdc)" != 700 ]]; then
echo -e "PDC PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/periodic/hourly/pdc 700
echo -e ""
else
echo -e "PDC PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
else
LOCAL_PDC=$(cat /etc/periodic/hourly/pdc | sha256sum | awk '{print $1}')
REMOTE_PDC=$(curl -sL -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/pdc | sha256sum | awk '{print $1}')
if [[ $LOCAL_PDC != $REMOTE_PDC ]]; then
echo -e "PDC MISMATCH, UPDATING..."
curl -sL -o /etc/periodic/hourly/pdc -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/pdc
echo -e ""
### SET PDC OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/periodic/hourly/pdc)" != "root:root" ]]; then
echo -e "PDC OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/periodic/hourly/pdc root
echo -e ""
else
echo -e "PDC OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET PDC PERMISSIONS
if [[ "$(stat -c '%a' /etc/periodic/hourly/pdc)" != 700 ]]; then
echo -e "PDC PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/periodic/hourly/pdc 700
echo -e ""
else
echo -e "PDC PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
else
echo -e "PDC LATEST, SKIPPING..."
echo -e ""
fi
fi
### INSTALL PDC-UPDATER
if [[ ! -f /etc/periodic/15min/pdc-updater ]]; then
echo -e "PDC-UPDATER MISSING, INSTALLING..."
curl -sL -o /etc/periodic/15min/pdc-updater -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/pdc-updater
echo -e ""
### SET PDC-UPDATER OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/periodic/15min/pdc-updater)" != "root:root" ]]; then
echo -e "PDC-UPDATER OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/periodic/15min/pdc-updater root
echo -e ""
else
echo -e "PDC-UPDATER OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET PDC-UPDATER PERMISSIONS
if [[ "$(stat -c '%a' /etc/periodic/15min/pdc-updater)" != 700 ]]; then
echo -e "PDC-UPDATER PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/periodic/15min/pdc-updater 700
echo -e ""
else
echo -e "PDC-UPDATER PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
else
LOCAL_PDC_UPDATER=$(cat /etc/periodic/15min/pdc-updater | sha256sum | awk '{print $1}')
REMOTE_PDC_UPDATER=$(curl -sL -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/pdc-updater | sha256sum | awk '{print $1}')
if [[ $LOCAL_PDC_UPDATER != $REMOTE_PDC_UPDATER ]]; then
echo -e "PDC-UPDATER MISMATCH, UPDATING..."
curl -sL -o /etc/periodic/15min/pdc-updater -H '$HEADER_NO_CACHE' $REPOSITORY_URL/scripts/pdc-updater
echo -e ""
### SET PDC-UPDATER OWNERSHIP
if [[ "$(stat -c '%U:%G' /etc/periodic/15min/pdc-updater)" != "root:root" ]]; then
echo -e "PDC-UPDATER OWNERSHIP IS WRONG, CHANGING..."
set_ownership /etc/periodic/15min/pdc-updater root
echo -e ""
else
echo -e "PDC-UPDATER OWNERSHIP IS CORRECT, SKIPPING..."
echo -e ""
fi
### SET PDC-UPDATER PERMISSIONS
if [[ "$(stat -c '%a' /etc/periodic/15min/pdc-updater)" != 700 ]]; then
echo -e "PDC-UPDATER PERMISSIONS ARE WRONG, CHANGING..."
set_permission /etc/periodic/15min/pdc-updater 700
echo -e ""
else
echo -e "PDC-UPDATER PERMISSIONS ARE CORRECT, SKIPPING..."
echo -e ""
fi
else
echo -e "PDC-UPDATER LATEST, SKIPPING..."
echo -e ""
fi
fi