From 8d46c1de766483c07e62dcd6e1f62855e34197f7 Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Tue, 10 Mar 2020 14:13:39 +0100 Subject: [PATCH] Prevent initializing/synchronizing if container is restarted and not deleted, see #14 --- seafile-client/seafile-entrypoint.sh | 45 ++++++++++++++++------------ tests/test_binaries.sh | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/seafile-client/seafile-entrypoint.sh b/seafile-client/seafile-entrypoint.sh index 5122e1d..ff217f2 100644 --- a/seafile-client/seafile-entrypoint.sh +++ b/seafile-client/seafile-entrypoint.sh @@ -16,30 +16,37 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Safely initialise the Seafile client. -seafile_ini=~/.ccnet/seafile.ini -/usr/bin/seaf-cli init -d ~/.seafile -while [ ! -f $seafile_ini ]; do sleep 1; done +# Initialise the Seafile client, if not already initialised. +seafile_ini="$HOME/.ccnet/seafile.ini" +if [ ! -f "$seafile_ini" ]; then + echo "Initializing Seafile client..." + seaf-cli init -d ~/.seafile + while [ ! -f "$seafile_ini" ]; do sleep 1; done +fi -# Safely start the Seafile daemon. -seafile_sock=~/.seafile/seafile-data/seafile.sock -/usr/bin/seaf-cli start -while [ ! -S $seafile_sock ]; do sleep 1; done +# Start the Seafile daemon. +echo "Starting Seafile client..." +seaf-cli start +while [ ! -S "$HOME/.seafile/seafile-data/seafile.sock" ]; do sleep 1; done -# Set the disable_verify_certificate key to true only if the environment variable exists. -[[ "$SEAF_SKIP_SSL_CERT" ]] && seaf-cli config -k disable_verify_certificate -v true +# Synchronize the library, if not already synchronized. +if [ -z "$(seaf-cli status | grep -v ^\#)" ]; then + echo "Synchronizing Seafile library..." + # Set the disable_verify_certificate key to true only if the environment variable exists. + [[ "$SEAF_SKIP_SSL_CERT" ]] && seaf-cli config -k disable_verify_certificate -v true -# Set the upload/download limits -[[ "$SEAF_UPLOAD_LIMIT" ]] && seaf-cli config -k upload_limit -v $SEAF_UPLOAD_LIMIT -[[ "$SEAF_DOWNLOAD_LIMIT" ]] && seaf-cli config -k download_limit -v $SEAF_DOWNLOAD_LIMIT + # Set the upload/download limits + [[ "$SEAF_UPLOAD_LIMIT" ]] && seaf-cli config -k upload_limit -v $SEAF_UPLOAD_LIMIT + [[ "$SEAF_DOWNLOAD_LIMIT" ]] && seaf-cli config -k download_limit -v $SEAF_DOWNLOAD_LIMIT -# Build the seaf-cli sync command. -cmd="seaf-cli sync -u $SEAF_USERNAME -p $SEAF_PASSWORD -s $SEAF_SERVER_URL -l $SEAF_LIBRARY_UUID -d /library" -[[ "$SEAF_2FA_SECRET" ]] && cmd+=" -a $(oathtool --base32 --totp $SEAF_2FA_SECRET)" -[[ "$SEAF_LIBRARY_PASSWORD" ]] && cmd+=" -e $SEAF_LIBRARY_PASSWORD" + # Build the seaf-cli sync command. + cmd="seaf-cli sync -u $SEAF_USERNAME -p $SEAF_PASSWORD -s $SEAF_SERVER_URL -l $SEAF_LIBRARY_UUID -d /library" + [[ "$SEAF_2FA_SECRET" ]] && cmd+=" -a $(oathtool --base32 --totp $SEAF_2FA_SECRET)" + [[ "$SEAF_LIBRARY_PASSWORD" ]] && cmd+=" -e $SEAF_LIBRARY_PASSWORD" -# Run it. -if ! eval $cmd; then echo "Failed to synchronize."; exit 1; fi + # Run it. + if ! eval $cmd; then echo "Failed to synchronize."; exit 1; fi +fi # Continously print the log, infinitely. while true; do diff --git a/tests/test_binaries.sh b/tests/test_binaries.sh index 09c79f6..4a2770a 100644 --- a/tests/test_binaries.sh +++ b/tests/test_binaries.sh @@ -17,7 +17,7 @@ # along with this program. If not, see . failures=() -binaries=(seaf-cli oathtool) +binaries=(seaf-cli oathtool grep) for binary in "${binaries[@]}"; do if ! [ -x "$(command -v $binary)" ]; then