docker-swag/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/run

39 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-01-20 23:42:13 -05:00
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
2023-03-02 14:21:27 -05:00
# make folders
mkdir -p \
/config/crontabs
2023-01-20 23:42:13 -05:00
2023-03-02 14:21:27 -05:00
## root
# if crontabs do not exist in config
2023-01-20 23:42:13 -05:00
if [[ ! -f /config/crontabs/root ]]; then
2023-03-02 14:21:27 -05:00
# copy crontab from system
if crontab -l -u root; then
crontab -l -u root >/config/crontabs/root
fi
2023-01-20 23:42:13 -05:00
2023-03-02 14:21:27 -05:00
# if crontabs still do not exist in config (were not copied from system)
# copy crontab from included defaults (using -n, do not overwrite an existing file)
cp -n /etc/crontabs/root /config/crontabs/ 2> >(grep -v 'cp: not replacing')
2023-01-25 20:42:05 -05:00
fi
2023-03-02 14:21:27 -05:00
# set permissions and import user crontabs
lsiown root:root /config/crontabs/root
crontab -u root /config/crontabs/root
2023-01-25 20:42:05 -05:00
2023-03-02 14:21:27 -05:00
## abc
# if crontabs do not exist in config
2023-01-25 20:42:05 -05:00
if [[ ! -f /config/crontabs/abc ]]; then
2023-03-02 14:21:27 -05:00
# copy crontab from system
if crontab -l -u abc; then
crontab -l -u abc >/config/crontabs/abc
fi
2023-01-25 20:42:05 -05:00
2023-03-02 14:21:27 -05:00
# if crontabs still do not exist in config (were not copied from system)
# copy crontab from included defaults (using -n, do not overwrite an existing file)
cp -n /etc/crontabs/abc /config/crontabs/ 2> >(grep -v 'cp: not replacing')
2023-03-02 14:21:27 -05:00
fi
# set permissions and import user crontabs
lsiown abc:abc /config/crontabs/abc
2023-01-25 20:42:05 -05:00
crontab -u abc /config/crontabs/abc