This repository has been archived on 2022-12-04. You can view files and clone it, but cannot push or open issues or pull requests.
rsync-docker/rsync.sh

49 lines
1.4 KiB
Bash
Raw Normal View History

2020-04-12 21:43:33 +00:00
#!/bin/sh
# rsync.sh - a script to configure the rsync job in the container
### PREPARATION
echo "Preparation steps started."
# Create an account for rsync
## this is recommended when rsync is not asked to preserve file ownership
if [ "$RSYNC_UID" != "" ] && [ "$RSYNC_GID" != "" ]; then
# UID and GID provided, create user
echo "UID and GID provided: $RSYNC_UID and $RSYNC_GID. Creating the user"
2022-12-04 08:43:07 +00:00
echo "rsyncuser:x:$RSYNC_UID:$RSYNC_GID::/home/rsyncuser:/bin/sh" >> /etc/passwd
echo "users:x:$RSYNC_GID:rsyncuser" >> /etc/group
RSYNC_USER=rsyncuser
2020-04-12 21:43:33 +00:00
else
# UID and GID not provided
echo "UID and GID are NOT provided. Proceeding as the root user."
RSYNC_USER=root
2020-04-12 21:43:33 +00:00
fi
# run as a cron job?
if [ "$RSYNC_CRONTAB" != "" ]; then
# using cron
echo "Running rsync with cron and with a provided crontab selected."
echo "The crontab file is expected to be at /rsync/$RSYNC_CRONTAB ."
echo "Any provided rsync arguments will be ignored, specify them in the crontab file instead"
# define the crontab file location
crontab -u $RSYNC_USER /rsync/$RSYNC_CRONTAB
2020-04-12 21:43:33 +00:00
else
# no cron job
echo "Running rsync as a cron job NOT selected."
fi
echo "Preparation steps completed."
### EXECUTION
if [ "$RSYNC_CRONTAB" != "" ]; then
2020-04-12 21:43:33 +00:00
# run as a cron job, start the cron daemon
echo "Starting the cron daemon..."
crond -f
else
# one time run
echo "Executing rsync as an one time run..."
eval rsync $@
2020-04-12 21:43:33 +00:00
fi