|
1 | 1 | #!/usr/bin/with-contenv bash |
2 | 2 | # shellcheck shell=bash |
3 | 3 |
|
4 | | -# if root crontabs do not exist in config |
5 | | -# copy root crontab from system |
6 | | -if [[ ! -f /config/crontabs/root ]] && crontab -l -u root; then |
7 | | - crontab -l -u root >/config/crontabs/root |
8 | | -fi |
| 4 | +# make folders |
| 5 | +mkdir -p \ |
| 6 | + /config/crontabs |
9 | 7 |
|
10 | | -# if root crontabs still do not exist in config (were not copied from system) |
11 | | -# copy root crontab from included defaults |
| 8 | +## root |
| 9 | +# if crontabs do not exist in config |
12 | 10 | if [[ ! -f /config/crontabs/root ]]; then |
13 | | - cp /etc/crontabs/root /config/crontabs/ |
14 | | -fi |
| 11 | + # copy crontab from system |
| 12 | + if crontab -l -u root; then |
| 13 | + crontab -l -u root >/config/crontabs/root |
| 14 | + fi |
15 | 15 |
|
16 | | -# if abc crontabs do not exist in config |
17 | | -# copy abc crontab from system |
18 | | -if [[ ! -f /config/crontabs/abc ]] && crontab -l -u abc; then |
19 | | - crontab -l -u abc >/config/crontabs/abc |
| 16 | + # if crontabs still do not exist in config (were not copied from system) |
| 17 | + # copy crontab from included defaults (using -n, do not overwrite an existing file) |
| 18 | + cp -n /etc/crontabs/root /config/crontabs/ |
20 | 19 | fi |
| 20 | +# set permissions and import user crontabs |
| 21 | +lsiown root:root /config/crontabs/root |
| 22 | +crontab -u root /config/crontabs/root |
21 | 23 |
|
22 | | -# if abc crontabs still do not exist in config (were not copied from system) |
23 | | -# copy abc crontab from included defaults |
| 24 | +## abc |
| 25 | +# if crontabs do not exist in config |
24 | 26 | if [[ ! -f /config/crontabs/abc ]]; then |
25 | | - cp /etc/crontabs/abc /config/crontabs/ |
26 | | -fi |
| 27 | + # copy crontab from system |
| 28 | + if crontab -l -u abc; then |
| 29 | + crontab -l -u abc >/config/crontabs/abc |
| 30 | + fi |
27 | 31 |
|
28 | | -# import user crontabs |
29 | | -crontab -u root /config/crontabs/root |
| 32 | + # if crontabs still do not exist in config (were not copied from system) |
| 33 | + # copy crontab from included defaults (using -n, do not overwrite an existing file) |
| 34 | + cp -n /etc/crontabs/abc /config/crontabs/ |
| 35 | +fi |
| 36 | +# set permissions and import user crontabs |
| 37 | +lsiown abc:abc /config/crontabs/abc |
30 | 38 | crontab -u abc /config/crontabs/abc |
0 commit comments