Last active
May 31, 2017 22:50
-
-
Save codycraven/5faf08a194d28059d6bdd16d64baae00 to your computer and use it in GitHub Desktop.
docker-sync osx_native unison repair
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SYNC_CONTAINER="$1" | |
getLogfile () { | |
echo "/tmp/$( docker exec "$SYNC_CONTAINER" ls /tmp/ | grep ^unison-stdout-- )" | |
} | |
if [ $# -lt 1 ]; then | |
>&2 echo "Error: an argument with the docker-sync container name must be passed" | |
exit 1 | |
elif [ $# -gt 1 ]; then | |
>&2 echo "Error: only one argument with the docker-sync container name must be passed" | |
exit 1 | |
fi | |
if ! $( docker container ps | tail -n +2 | awk '{print $NF}' | grep -q "$SYNC_CONTAINER" ); then | |
>&2 echo "Error: docker-sync container '$SYNC_CONTAINER' is not running" | |
exit 1 | |
fi | |
echo "Killing Unison for docker-sync: $SYNC_CONTAINER" | |
# Clear Unison log file so we can detect when sync is complete | |
if $( docker exec "$SYNC_CONTAINER" ls /tmp/ | grep -q "^unison-stdout--" ); then | |
LOGFILE=$( getLogfile ) | |
docker exec "$SYNC_CONTAINER" truncate -s 0 "$LOGFILE" | |
fi | |
PID=$( docker exec $SYNC_CONTAINER ps | grep ' unison ' | awk '{print $1}' ) | |
docker exec "$SYNC_CONTAINER" kill -9 "$PID" | |
echo '' | |
# Just in-case the log file wasn't previously present... highly-unlikely | |
echo 'Waiting for Unison to start' | |
until $( docker exec "$SYNC_CONTAINER" ls /tmp/ | grep -q "^unison-stdout--" ); do | |
echo -en '.' | |
sleep 1 | |
done | |
LOGFILE=$( getLogfile ) | |
echo '' | |
echo 'Waiting for files to sync' | |
until $( docker exec "$SYNC_CONTAINER" cat "$LOGFILE" | grep -q "^Nothing to do" ); do | |
echo -en '.' | |
sleep 1 | |
done | |
echo '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment