Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update my docker-rclone fork with pfidr34 fork because bcardiff is outdated and not maintained. #3

Merged
merged 73 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2c93060
update to latest version
pfidr34 Apr 30, 2019
08f7928
Update LICENSE.md
pfidr34 Apr 30, 2019
45856a4
Update README.md
pfidr34 Apr 30, 2019
917800c
Update README.md
pfidr34 Apr 30, 2019
afdd7dc
Update Dockerfile
pfidr34 May 1, 2019
3361e6c
Merge branch 'master' of https://github.com/pfidr34/docker-rclone
pfidr34 May 1, 2019
d56274e
Create FAIL_URL handling proposed by @dantebarba
pfidr34 May 1, 2019
91d6297
Add 'move' as a acceptable rclone operation.
pfidr34 May 1, 2019
dc37ad8
typo
pfidr34 May 1, 2019
25fe6e9
Add ability to roate logs after x days
pfidr34 May 1, 2019
d3fb318
Change variable name
pfidr34 May 1, 2019
4a8f9de
Autobuild for Rclone 1.48
pfidr34 Jun 23, 2019
9283a0c
Simplifies `apk add`
tlex Jul 17, 2019
1f68e69
Merge pull request #1 from tlex/simplify-apk-add
pfidr34 Jul 19, 2019
13c5663
Fix log rotation
pfidr34 Aug 19, 2019
e411ad0
Add change log to readme.md
pfidr34 Aug 20, 2019
3f9aecb
Healthchecks.io enhancements
pfidr34 Aug 20, 2019
52719b4
Update README.md
pfidr34 Aug 29, 2019
0b1738c
Update sync.sh
pfidr34 Sep 9, 2019
dc45a62
Change log directory check
pfidr34 Sep 10, 2019
2af0423
Add env variable SYNC_OPTS_EVAL.
Sep 12, 2019
43a204e
Add documentation for SYNC_OPTS_EVAL.
Sep 12, 2019
950864f
Fix typos in README.
Sep 12, 2019
afd083e
Merge pull request #5 from mistermult/eval-args
pfidr34 Sep 19, 2019
63509eb
Update SYNC_EVAL logic
pfidr34 Sep 19, 2019
c870f54
Update README.MD
pfidr34 Sep 19, 2019
2969596
Add ability to sync once then exit
pfidr34 Sep 23, 2019
e1e85ad
Update README.md
pfidr34 Sep 23, 2019
6583f02
Update README.md
pfidr34 Sep 23, 2019
af616c7
Update README.md
pfidr34 Sep 23, 2019
ef5c482
Increment version
pfidr34 Oct 1, 2019
2d144b3
Version update
pfidr34 Oct 27, 2019
d8d7a55
Update version
pfidr34 Nov 6, 2019
64e0f8e
Initial support for passing UID/GID
Nov 14, 2019
ab32406
typo
Nov 14, 2019
ad02bcf
Don't assume root, and switch to user if they arleady exist
Nov 15, 2019
b178f94
Merge pull request #10 from mikeburgh/master
pfidr34 Nov 18, 2019
19c6e1b
Update Readme
pfidr34 Nov 18, 2019
d32a6b2
Update version
pfidr34 Nov 20, 2019
a2a6d7d
Use correct user for Docker Hub image
JakeWharton Jan 28, 2020
4709799
Merge pull request #11 from JakeWharton/patch-2
pfidr34 Jan 28, 2020
262fd1a
Update rclone version
pfidr34 Feb 1, 2020
2df3451
Handle spaces in SYNC_SRC and SYNC_DEST options
pfidr34 May 17, 2020
5b4abe8
Change how sync.sh handles errors from rclone
pfidr34 May 18, 2020
0bf2c95
Remove DEBUG echo
pfidr34 May 18, 2020
5d9fbc0
Various updates, see README.md
pfidr34 May 28, 2020
7af4ba1
Updated to Rclone 1.52.0 and added build script
pfidr34 May 28, 2020
8476c6c
eval rclone command | set error handling on source dir check
pfidr34 Jun 9, 2020
e9a6f89
Fix whitespace issues in SYNC_SRC and SYNC_DEST
pfidr34 Jun 9, 2020
de665fb
Revert last change
pfidr34 Jun 9, 2020
3a214d2
Update to Rclone 1.52.1
pfidr34 Jun 11, 2020
0a66a61
Update to 1.52.2
pfidr34 Jun 25, 2020
0fd259a
Update to 1.52.3
pfidr34 Aug 21, 2020
afb75ca
Add ability to send log data to healthchecks.io
pfidr34 Aug 31, 2020
8ad2acc
Update to 1.53.0
pfidr34 Sep 5, 2020
949a7dc
Update to 1.53.1
pfidr34 Sep 13, 2020
bb1f665
Update to 1.53.2
pfidr34 Oct 28, 2020
f5ca4af
Update to 1.53.3
pfidr34 Nov 23, 2020
760b8bc
Update to 1.53.4
pfidr34 Jan 22, 2021
5d2a808
Update to 1.54.0
pfidr34 Feb 5, 2021
30d4e8b
Update to 1.54.1
pfidr34 Mar 10, 2021
e284c5b
Update to 1.55.0 & 1.55.1
pfidr34 Jun 26, 2021
531570b
Update to 1.56.0
pfidr34 Aug 25, 2021
39e4cb4
Update to 1.56.1
pfidr34 Sep 27, 2021
2c0e712
Update to 1.56.2
pfidr34 Oct 4, 2021
b322fcc
Update to 1.57.0
pfidr34 Nov 18, 2021
46c8215
Fix wrong healtcheck for DIR_CHECK, no OUTPUT_LOG.
mistermult Feb 3, 2022
492642c
Merge pull request #29 from mistermult/fix-return-code
pfidr34 Apr 25, 2022
86bfdd7
Update to 1.58.0
pfidr34 Apr 25, 2022
3d39e35
Update to 1.59.0
pfidr34 Jul 18, 2022
2fb9c19
Update to 1.61.1
pfidr34 Feb 7, 2023
c59baf3
Update to version 1.63.0
pfidr34 Jul 6, 2023
831432b
Merge remote-tracking branch 'fork/master' into pfidr34/docker-rclone
dantebarba Jul 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
ARG BASE=alpine:3.9
ARG BASE=alpine:latest
FROM ${BASE}

LABEL maintainer="Brian J. Cardiff <bcardiff@gmail.com>"
LABEL maintainer="pfidr"

ARG RCLONE_VERSION=current
ARG ARCH=amd64
ENV SYNC_SRC=
ENV SYNC_DEST=
ENV SYNC_OPTS=-v
ENV SYNC_OPTS_EVAL=
ENV SYNC_ONCE=
ENV RCLONE_CMD=sync
ENV RCLONE_DIR_CMD=ls
ENV RCLONE_DIR_CMD_DEPTH=-1
ENV RCLONE_DIR_CHECK_SKIP=
ENV RCLONE_OPTS="--config /config/rclone.conf"
ENV OUTPUT_LOG=
ENV ROTATE_LOG=
ENV CRON=
ENV CRON_ABORT=
ENV FORCE_SYNC=
ENV CHECK_URL=
ENV FAIL_URL=
ENV HC_LOG=
ENV TZ=
ENV COMMAND=sync
ENV UID=
ENV GID=

RUN apk -U add ca-certificates fuse wget dcron tzdata \
&& rm -rf /var/cache/apk/*
RUN apk --no-cache add ca-certificates fuse wget dcron tzdata

RUN URL=http://downloads.rclone.org/${RCLONE_VERSION}/rclone-${RCLONE_VERSION}-linux-${ARCH}.zip ; \
URL=${URL/\/current/} ; \
Expand All @@ -33,6 +42,7 @@ COPY sync.sh /
COPY sync-abort.sh /

VOLUME ["/config"]
VOLUME ["/logs"]

ENTRYPOINT ["/entrypoint.sh"]

Expand Down
2 changes: 2 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Copyright 2019 Pfidr34

Copyright 2017 Brian J. Cardiff

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand Down
133 changes: 122 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,138 @@ A first run of the container can help in the creation of the file, but feel free

```
$ mkdir config
$ docker run --rm -it -v $(pwd)/config:/config bcardiff/rclone
$ docker run --rm -it -v $(pwd)/config:/config pfidr/rclone
```

### Perform sync in a daily basis

A few environment variables allow you to customize the behavior of the sync:
A few environment variables allow you to customize the behavior of rclone:

* `COMMAND` `rclone` command, e.g `sync`, `copy`, `move`.
Defaults to `sync`
* `SYNC_SRC` source location for `rclone sync` command
* `SYNC_DEST` destination location for `rclone sync` command
* `CRON` crontab schedule `0 0 * * *` to perform sync every midnight
* `SYNC_SRC` source location for `rclone sync/copy/move` command. Directories with spaces should be wrapped in single quotes.
* `SYNC_DEST` destination location for `rclone sync/copy/move` command. Directories with spaces should be wrapped in single quotes.
* `SYNC_OPTS` additional options for `rclone sync/copy/move` command. Defaults to `-v`
* `SYNC_OPTS_EVAL` further additional options for `rclone sync/copy/move` command. The variables and commands in the string are first interpolated like in a shell. The interpolated string is appended to SYNC_OPTS. That means '--backup-dir /old\`date -I\`' first evaluates to '--backup-dir /old2019-09-12', which is then appended to SYNC_OPTS. The evaluation happens immediately before rclone is called.
* `SYNC_ONCE` set variable to only run the sync one time and then exit the container
* `RCLONE_CMD` set variable to `sync` `copy` or `move` when running rclone. Defaults to `sync`
* `RCLONE_DIR_CMD` set variable to `ls` or `lsf` for source directory check style. Defaults to `ls`
* `RCLONE_DIR_CMD_DEPTH` set the limit of the recursion depth to this. Defaults to `-1` (rclone default)
* `RCLONE_DIR_CHECK_SKIP` set variable to skip source directory check before sync. *Use with caution*
* `CRON` crontab schedule `0 0 * * *` to perform sync every midnight. Also supprorts cron shortcuts: `@yearly` `@monthly` `@weekly` `@daily` `@hourly`
* `CRON_ABORT` crontab schedule `0 6 * * *` to abort sync at 6am
* `FORCE_SYNC` set variable to perform a sync upon boot
* `CHECK_URL` [healthchecks.io](https://healthchecks.io) url or similar cron monitoring to perform a `GET` after a successful sync
* `FAIL_URL` Fail URL to perform a `GET` after unsuccessful execution. Default: `CHECK_URL` with appended "/fail" at the end
* `SYNC_OPTS` additional options for `rclone sync` command. Defaults to `-v`
* `TZ` set the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to use for the cron and log `America/Argentina/Buenos_Aires`
* `FAIL_URL` Fail URL to perform a `GET` after unsuccessful execution. By default this is `CHECK_URL` with appended "/fail" at the end
* `HC_LOG` set variable to send log data to healthchecks.io. `OUTPUT_LOG` must also be set.
* `OUTPUT_LOG` set variable to output log file to /logs
* `ROTATE_LOG` set variable to delete logs older than specified days from /logs
* `TZ` set the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to use for the cron and log `America/Chicago`
* `UID` set variable to specify user to run rclone as. Must also use GID.
* `GID` set variable to specify group to run rclone as. Must also use UID.

**When using UID/GID the config and/or logs directory must be writeable by this UID**

```bash
$ docker run --rm -it -v $(pwd)/config:/config -v /path/to/source:/source -e SYNC_SRC="/source" -e SYNC_DEST="dest:path" -e TZ="America/Argentina/Buenos_Aires" -e CRON="0 0 * * *" -e CRON_ABORT="0 6 * * *" -e FORCE_SYNC=1 -e CHECK_URL=https://hchk.io/hchk_uuid bcardiff/rclone
$ docker run --rm -it -v $(pwd)/config:/config -v /path/to/source:/source -e SYNC_SRC="/source" -e SYNC_DEST="dest:path" -e TZ="America/Chicago" -e CRON="0 0 * * *" -e CRON_ABORT="0 6 * * *" -e FORCE_SYNC=1 -e CHECK_URL=https://hchk.io/hchk_uuid pfidr/rclone
```

See [rclone sync docs](https://rclone.org/commands/rclone_sync/) for source/dest syntax and additional options.

## Changelog

+ **07/06/2023:**
* Update to latest Rclone (v1.63.0)
+ **07/18/2022:**
* Update to latest Rclone (v1.59.0)
+ **04/25/2022:**
* Display exit code in console output
* Fix issue with healthcheck
* Update to latest Rclone (v1.58.0)
+ **11/18/2021:**
* Update to latest Rclone (v1.57.0)
+ **10/04/2021:**
* Update to latest Rclone (v1.56.2)
+ **09/27/2021:**
* Update to latest Rclone (v1.56.1)
+ **08/25/2021:**
* Update to latest Rclone (v1.56.0)
+ **06/25/2021:**
* Update to latest Rclone (v1.55.1)
+ **06/25/2021:**
* Update to latest Rclone (v1.55.0)
+ **03/10/2021:**
* Update to latest Rclone (v1.54.1)
+ **02/04/2021:**
* Update to latest Rclone (v1.54.0)
+ **01/22/2021:**
* Update to latest Rclone (v1.53.4)
+ **11/23/2020:**
* Update to latest Rclone (v1.53.3)
+ **10/28/2020:**
* Update to latest Rclone (v1.53.2)
+ **09/13/2020:**
* Update to latest Rclone (v1.53.1)
+ **09/05/2020:**
* Update to latest Rclone (v1.53.0)
+ **08/31/2020:**
* Add ability to send log data to healthchecks.io - See `HC_LOG` environment variable
+ **08/20/2020:**
* Update to latest Rclone (v1.52.3)
+ **06/25/2020:**
* Update to latest Rclone (v1.52.2)
+ **06/11/2020:**
* Update to latest Rclone (v1.52.1)
+ **05/28/2020:**
* Eval the entire rclone command
* Modify how rclone errors are interpreted when checking if source directory is empty
+ **05/27/2020:**
* Update to latest Rclone (v1.52.0)
* Add `RCLONE_DIR_CMD_DEPTH` option to declare recursion depth when checking if `SYNC_SRC` is empty
* Move call to signal start of healthchecks.io further up in the sync process
* Change when logs are deleted to make sure an active log is not deleted
+ **05/18/2020:**
* Modify how rclone errors are interpreted when passing results to healthchecks.io
+ **05/17/2020:**
* Handle spaces in `SYNC_SRC` and `SYNC_DEST`
+ **02/01/2020:**
* Update to latest Rclone (v1.51.0)
+ **11/20/2019:**
* Update to latest Rclone (v1.50.2)
+ **11/18/2019:**
* Add support for UID/GID
+ **11/06/2019:**
* Update to latest Rclone (v1.50.1)
+ **10/27/2019:**
* Update to latest Rclone (v1.50.0)
+ **10/07/2019:**
* Update to latest Rclone (v1.49.5)
+ **10/01/2019:**
* Update to latest Rclone (v1.49.4)
+ **09/23/2019:**
* Add environment variable SYNC_ONCE
+ **09/19/2019:**
* Add environment variable SYNC_OPTS_EVAL
+ **09/17/2019:**
* Update to latest Rclone (v1.49.3)
+ **09/10/2019:**
* Regression on log rotation
+ **09/09/2019:**
* Update to latest Rclone (v1.49.2)
+ **08/29/2019:**
* Update to latest Rclone (v1.49.1)
+ **08/20/2019:**
* Add start command for healthchecks.io calls
* Add debug messages for healthchecks.io calls
+ **08/19/2019:**
* Correct log rotation when there are no logs
+ **07/18/2019:**
* Optimizations to dockerfile
+ **06/22/2019:**
* Update to latest Rclone (v1.48.0)
+ **05/01/2019:**
* Initial release

<br />
<br />
<br />
<br />
Credit to Brian J. Cardiff for the orginal project @ https://github.com/bcardiff/docker-rclone
37 changes: 37 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

docker build --no-cache --build-arg RCLONE_VERSION=v1.47.0 -t pfidr/rclone:1.47 -t pfidr/rclone:1.47.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.48.0 -t pfidr/rclone:1.48 -t pfidr/rclone:1.48.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.0 -t pfidr/rclone:1.49.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.1 -t pfidr/rclone:1.49.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.2 -t pfidr/rclone:1.49.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.3 -t pfidr/rclone:1.49.3 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.4 -t pfidr/rclone:1.49.4 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.49.5 -t pfidr/rclone:1.49.5 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.50.0 -t pfidr/rclone:1.50.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.50.1 -t pfidr/rclone:1.50.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.50.2 -t pfidr/rclone:1.50.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.51.0 -t pfidr/rclone:1.51.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.0 -t pfidr/rclone:1.52.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.1 -t pfidr/rclone:1.52.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.2 -t pfidr/rclone:1.52.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.52.3 -t pfidr/rclone:1.52.3 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.0 -t pfidr/rclone:1.53.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.1 -t pfidr/rclone:1.53.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.2 -t pfidr/rclone:1.53.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.3 -t pfidr/rclone:1.53.3 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.53.4 -t pfidr/rclone:1.53.4 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.54.0 -t pfidr/rclone:1.54.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.54.1 -t pfidr/rclone:1.54.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.55.0 -t pfidr/rclone:1.55.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.55.1 -t pfidr/rclone:1.55.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.56.0 -t pfidr/rclone:1.56.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.56.1 -t pfidr/rclone:1.56.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.56.2 -t pfidr/rclone:1.56.2 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.57.0 -t pfidr/rclone:1.57.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.58.0 -t pfidr/rclone:1.58.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.59.0 -t pfidr/rclone:1.59.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.60.0 -t pfidr/rclone:1.60.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.61.0 -t pfidr/rclone:1.61.0 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.61.1 -t pfidr/rclone:1.61.1 .
docker build --no-cache --build-arg RCLONE_VERSION=v1.63.0 -t pfidr/rclone:1.63.0 -t pfidr/rclone:latest -t pfidr/rclone:test -t rclone_test .
92 changes: 84 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,73 @@

set -e

# Announce version
echo "INFO: Running $(rclone --version | head -n 1)"

# Make sure sync/copy command is ok
if [ "$(echo "$RCLONE_CMD" | tr '[:lower:]' '[:upper:]')" != "SYNC" ] && [ "$(echo "$RCLONE_CMD" | tr '[:lower:]' '[:upper:]')" != "COPY" ] && [ "$(echo "$RCLONE_CMD" | tr '[:lower:]' '[:upper:]')" != "MOVE" ]
then
echo "WARNING: rclone command '$RCLONE_CMD' is not supported by this container, please use sync/copy/move. Stopping."
exit 1
fi

# Make sure dir command is ok
if [ "$(echo "$RCLONE_DIR_CMD" | tr '[:lower:]' '[:upper:]')" != "LS" ] && [ "$(echo "$RCLONE_DIR_CMD" | tr '[:lower:]' '[:upper:]')" != "LSF" ]
then
echo "WARNING: rclone directory command '$RCLONE_DIR_CMD' is not supported by this container, please use ls or lsf. Stopping."
exit 1
fi

# Make sure UID and GID are both supplied
if [ -z "$GID" -a ! -z "$UID" ] || [ -z "$UID" -a ! -z "$GID" ]
then
echo "WARNING: Must supply both UID and GID or neither. Stopping."
exit 1
fi

# Process UID and GID
if [ ! -z "$GID" ]
then

#Get group name or add it
GROUP=$(getent group "$GID" | cut -d: -f1)
if [ -z "$GROUP" ]
then
GROUP=rclone
addgroup --gid "$GID" "$GROUP"
fi

#get user or add it
USER=$(getent passwd "$UID" | cut -d: -f1)
if [ -z "$USER" ]
then
USER=rclone
adduser \
--disabled-password \
--gecos "" \
--no-create-home \
--ingroup "$GROUP" \
--uid "$UID" \
"$USER" >/dev/null
fi
else
USER=$(whoami)
fi

# Re-write cron shortcut
case "$(echo "$CRON" | tr '[:lower:]' '[:upper:]')" in
*@YEARLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 1 *" && CRONS="0 0 1 1 *";;
*@ANNUALLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 1 *" && CRONS="0 0 1 1 *";;
*@MONTHLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 1 * *" && CRONS="0 0 1 * * ";;
*@WEEKLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 * * 0" && CRONS="0 0 * * 0";;
*@DAILY* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 * * *" && CRONS="0 0 * * *";;
*@MIDNIGHT* ) echo "INFO: Cron shortcut $CRON re-written to 0 0 * * *" && CRONS="0 0 * * *";;
*@HOURLY* ) echo "INFO: Cron shortcut $CRON re-written to 0 * * * *" && CRONS="0 * * * *";;
*@* ) echo "WARNING: Cron shortcut $CRON is not supported. Stopping." && exit 1;;
* ) CRONS=$CRON;;
esac

# Set time zone if passed in
if [ ! -z "$TZ" ]
then
cp /usr/share/zoneinfo/$TZ /etc/localtime
Expand All @@ -10,34 +77,44 @@ fi

rm -f /tmp/sync.pid

# Check for source and destination ; launch config if missing
if [ -z "$SYNC_SRC" ] || [ -z "$SYNC_DEST" ]
then
echo "INFO: No SYNC_SRC and SYNC_DEST found. Starting rclone config"
rclone config $RCLONE_OPTS
su "$USER" -c "rclone config $RCLONE_OPTS"
echo "INFO: Define SYNC_SRC and SYNC_DEST to start sync process."
else
# SYNC_SRC and SYNC_DEST setup
# run sync either once or in cron depending on CRON
if [ -z "$FAIL_URL" ]
then

#Create fail URL if CHECK_URL is populated but FAIL_URL is not
if [ ! -z "$CHECK_URL" ] && [ -z "$FAIL_URL" ]
then
FAIL_URL="${CHECK_URL}/fail"
fi
if [ -z "$CRON" ]

if [ -z "$CRONS" ]
then
echo "INFO: No CRON setting found. Running sync once."
echo "INFO: Add CRON=\"0 0 * * *\" to perform sync every midnight"
/sync.sh
su "$USER" -c /sync.sh
else
if [ -z "$FORCE_SYNC" ]
then
echo "INFO: Add FORCE_SYNC=1 to perform a sync upon boot"
else
/sync.sh
su "$USER" -c /sync.sh
fi

if [ ! -z "$SYNC_ONCE" ]
then
echo "INFO: SYNC_ONCE option activated. Stopping now."
exit 0
fi

# Setup cron schedule
crontab -d
echo "$CRON /sync.sh >>/tmp/sync.log 2>&1" > /tmp/crontab.tmp
echo "$CRONS su $USER -c /sync.sh >>/tmp/sync.log 2>&1" > /tmp/crontab.tmp
if [ -z "$CRON_ABORT" ]
then
echo "INFO: Add CRON_ABORT=\"0 6 * * *\" to cancel outstanding sync at 6am"
Expand All @@ -56,4 +133,3 @@ else
tail -F /tmp/crond.log /tmp/sync.log
fi
fi

Loading