Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 10 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ export DIR_NAME=.docker-blueprint
export ROOT_DIR=~/.docker-blueprint
export LOCAL_DIR="$PROJECT_DIR/$DIR_NAME"
export TEMP_DIR="$LOCAL_DIR/tmp"
export CACHE_DIR="$ROOT_DIR/cache"
export ENTRYPOINT="$ROOT_DIR/entrypoint.sh"
export PROJECT_BLUEPRINT_FILE=docker-blueprint.yml

mkdir -p "$CACHE_DIR"

# Delete temporary files older than 5 minutes
mkdir -p "$TEMP_DIR"
find "$TEMP_DIR" -mindepth 1 -type f -mmin +5 -delete
Expand Down Expand Up @@ -99,32 +102,34 @@ if [[ -f "$ROOT_DIR/commands/$1.sh" ]]; then
fi

source "$ROOT_DIR/commands/$1.sh"
source "$ROOT_DIR/includes/check-upstream.sh"
exit
fi

MODE_NO_TTY=false

if [[ $# -eq 0 ]]; then
source "$ROOT_DIR/commands/help.sh"
source "$ROOT_DIR/includes/check-upstream.sh"
exit
fi

while [[ "$#" -gt 0 ]]; do
case $1 in
start | stop | restart | down)
$DOCKER_COMPOSE "$1" ${@:2}
exit
break
;;

-h | --help)
source "$ROOT_DIR/commands/help.sh"
exit
break
;;

-v | --version)
AS_FUNCTION=false
source "$ROOT_DIR/commands/version.sh"
exit
break
;;

-T)
Expand Down Expand Up @@ -197,3 +202,5 @@ while [[ "$#" -gt 0 ]]; do

shift
done

source "$ROOT_DIR/includes/check-upstream.sh"
45 changes: 45 additions & 0 deletions includes/check-upstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

if [[ -z "$CHECK_UPSTREAM_WAS_CALLED" ]]; then

export CHECK_UPSTREAM_WAS_CALLED=1

new_version_available_flag_file="$CACHE_DIR/.new-version-available"
update_check_timestamp_file="$CACHE_DIR/.update-check-timestamp"
update_check_interval=86400 # One day in seconds

current_timestamp="$(date +%s)"
previous_timestamp=0

if [[ -f "$update_check_timestamp_file" ]]; then
previous_timestamp="$(cat "$update_check_timestamp_file")"
fi

timestamp_delta=$(($current_timestamp - $previous_timestamp))

if [[ "$timestamp_delta" -gt "$update_check_interval" ]]; then
echo "$current_timestamp" >"$update_check_timestamp_file"

PREVIOUS_DIR=$PWD

cd $ROOT_DIR
git remote update >/dev/null
git status -uno | grep 'branch is behind' >/dev/null
cd $PREVIOUS_DIR

if [[ $? > 0 ]]; then
rm -f "$new_version_available_flag_file"
exit # No new commits
else
touch "$new_version_available_flag_file"
fi
fi

if [[ -f "$new_version_available_flag_file" ]]; then
printf "\n"
printf "New version is available!\n"
printf "Install with ${EXE_COL}docker-blueprint${RESET} ${CMD_COL}update${RESET}\n"
printf "\n"
fi

fi