-
Notifications
You must be signed in to change notification settings - Fork 11
/
hazen-app
executable file
·72 lines (61 loc) · 1.68 KB
/
hazen-app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# DOCKER REGISTRY INFO
BASE_IMAGE="hazen"
ORGANISATION="gsttmriphysics"
REGISTRY="docker.io"
IMAGE="$REGISTRY/$ORGANISATION/$BASE_IMAGE"
# FUNCTIONS
check_bash(){
if ! [ -n "$BASH_VERSION" ];then
echo "Called script with non-bash shell, calling self with bash....";
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
/bin/bash ${SCRIPTPATH}/hazen-app
exit;
fi
}
check_cmd_in_path(){
cmd=$1
which $cmd > /dev/null 2>&1 || error 1 "$cmd not found! please install $cmd to continue"
}
check_internet_connections(){
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
if [ $? -eq 0 ]; then
internet_status=true
else
echo "WARNING: No internet connection, unable to verify Hazen version"
internet_status=false
fi
}
#
while getopts :b: flag
do
case "${flag}" in
b) BUILD_TAG=${OPTARG}
shift "$(( OPTIND - 1 ))";;
esac
done
# MAIN
check_bash
check_cmd_in_path docker
check_internet_connections
# define requested version with cmd line argument
if [ -z "$BUILD_TAG" ]; then # no command line argument supplied
APP_IMAGE=$IMAGE:latest
else
APP_IMAGE=$IMAGE:$BUILD_TAG
fi
# pull requested version
if [ "$internet_status" = true ]; then
echo $APP_IMAGE
docker pull $APP_IMAGE
else
echo "No internet connection, unable to check for latest version"
fi
command="docker run \
--rm \
--mount type=bind,source=$(pwd),target=/home/hazen_user/data \
-w /home/hazen_user/data \
${APP_IMAGE} $@"
echo running: ${command}
# Set up mounted volumes, environment, and run our containerized command
exec ${command}