2017-07-15 09:40:25 -04:00
|
|
|
#!/bin/bash
|
2017-07-15 13:52:23 -04:00
|
|
|
|
|
|
|
# prints colored text
|
|
|
|
print_style () {
|
2017-07-15 14:36:15 -04:00
|
|
|
|
2017-07-15 13:52:23 -04:00
|
|
|
if [ "$2" == "info" ] ; then
|
2017-07-15 14:24:01 -04:00
|
|
|
COLOR="96m";
|
2017-07-15 13:52:23 -04:00
|
|
|
elif [ "$2" == "success" ] ; then
|
2017-07-15 14:24:01 -04:00
|
|
|
COLOR="92m";
|
2017-07-15 13:52:23 -04:00
|
|
|
elif [ "$2" == "warning" ] ; then
|
2017-07-15 14:24:01 -04:00
|
|
|
COLOR="93m";
|
2017-07-15 13:52:23 -04:00
|
|
|
elif [ "$2" == "danger" ] ; then
|
2017-07-15 15:46:00 -04:00
|
|
|
COLOR="91m";
|
|
|
|
else #default color
|
|
|
|
COLOR="0m";
|
2017-07-15 13:52:23 -04:00
|
|
|
fi
|
|
|
|
|
2017-07-15 15:46:00 -04:00
|
|
|
STARTCOLOR="\e[$COLOR";
|
|
|
|
ENDCOLOR="\e[0m";
|
2017-07-15 14:24:01 -04:00
|
|
|
|
|
|
|
printf "$STARTCOLOR%b$ENDCOLOR" "$1";
|
2017-07-15 13:52:23 -04:00
|
|
|
}
|
|
|
|
|
2017-07-15 15:46:00 -04:00
|
|
|
display_options () {
|
|
|
|
printf "Available options:\n";
|
2017-07-15 13:52:23 -04:00
|
|
|
print_style " install" "success"; printf "\t\t Installs docker-sync gem on the host machine.\n";
|
2017-07-15 15:46:00 -04:00
|
|
|
print_style " up [services]" "success"; printf "\t Starts docker-sync and runs docker compose.\n";
|
2017-07-15 13:52:23 -04:00
|
|
|
print_style " down" "success"; printf "\t\t\t Stops containers and docker-sync.\n";
|
|
|
|
print_style " trigger" "success"; printf "\t\t Manually triggers the synchronization of files.\n";
|
2017-07-15 15:46:00 -04:00
|
|
|
print_style " clean" "warning"; printf "\t\t Removes all files from the docker-sync container.\n";
|
|
|
|
}
|
2017-07-15 13:52:23 -04:00
|
|
|
|
2017-07-15 15:46:00 -04:00
|
|
|
if [[ $# -eq 0 ]] ; then
|
|
|
|
print_style "Missing arguments.\n" "danger";
|
|
|
|
display_options;
|
2017-07-15 09:40:25 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-15 09:46:52 -04:00
|
|
|
if [ "$1" == "up" ] ; then
|
2017-07-15 14:24:01 -04:00
|
|
|
print_style "Initializing Docker Sync\n" "info";
|
2017-07-15 15:46:00 -04:00
|
|
|
print_style "May take a long time (15min+) the first run\n" "info";
|
2017-07-15 14:41:35 -04:00
|
|
|
docker-sync start;
|
2017-07-15 15:46:00 -04:00
|
|
|
|
2017-07-15 14:41:35 -04:00
|
|
|
print_style "Initializing Docker Compose\n" "info";
|
|
|
|
shift; # removing first argument
|
2017-07-15 11:13:50 -04:00
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.sync.yml up -d ${@};
|
2017-07-15 12:00:44 -04:00
|
|
|
|
2017-07-15 09:46:52 -04:00
|
|
|
elif [ "$1" == "down" ]; then
|
2017-07-15 14:36:15 -04:00
|
|
|
print_style "Stopping Docker Compose\n" "info";
|
2017-07-15 14:41:35 -04:00
|
|
|
docker-compose down;
|
2017-07-15 15:46:00 -04:00
|
|
|
|
2017-07-15 14:41:35 -04:00
|
|
|
print_style "Stopping Docker Sync\n" "info";
|
2017-07-15 09:44:09 -04:00
|
|
|
docker-sync stop;
|
2017-07-15 12:00:44 -04:00
|
|
|
|
2017-07-15 11:01:52 -04:00
|
|
|
elif [ "$1" == "install" ]; then
|
2017-07-15 14:36:15 -04:00
|
|
|
print_style "Installing docker-sync\n" "info";
|
2017-07-15 11:01:52 -04:00
|
|
|
gem install docker-sync;
|
2017-07-15 12:00:44 -04:00
|
|
|
|
|
|
|
elif [ "$1" == "trigger" ]; then
|
2017-07-15 14:36:15 -04:00
|
|
|
print_style "Manually triggering sync between host and docker-sync container.\n" "info";
|
2017-07-15 11:01:52 -04:00
|
|
|
docker-sync sync;
|
2017-07-15 12:00:44 -04:00
|
|
|
|
2017-07-15 11:01:52 -04:00
|
|
|
elif [ "$1" == "clean" ]; then
|
2017-07-15 14:36:15 -04:00
|
|
|
print_style "Removing and cleaning up files from the docker-sync container.\n" "warning";
|
2017-07-15 11:01:52 -04:00
|
|
|
docker-sync clean;
|
2017-07-15 12:00:44 -04:00
|
|
|
|
2017-07-15 09:46:52 -04:00
|
|
|
else
|
2017-07-15 15:46:00 -04:00
|
|
|
print_style "Invalid arguments.\n" "danger";
|
|
|
|
display_options;
|
|
|
|
exit 1
|
2017-07-15 09:40:25 -04:00
|
|
|
fi
|