-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpfish-wrapper
executable file
·55 lines (48 loc) · 1.56 KB
/
pfish-wrapper
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
#!/bin/sh
# pfish
# A wrapper script for invoking pfish with docker
# Put this script in $PATH as `pfish`
#
# Inspired by https://spin.atomicobject.com/2015/11/30/command-line-tools-docker/
PROGNAME="$(basename $0)"
VERSION="1.2.1"
# Helper functions for guards
error(){
error_code=$1
echo "ERROR: $2" >&2
echo "($PROGNAME wrapper version: $VERSION, error code: $error_code )" &>2
exit $1
}
check_cmd_in_path(){
cmd=$1
which $cmd > /dev/null 2>&1 || error 1 "$cmd not found!"
}
# Guards (checks for dependencies)
check_cmd_in_path docker
#check_cmd_in_path docker-machine
#docker-machine active > /dev/null 2>&1 || error 2 "No active docker-machine VM found."
# ensure a configuration directory
CONFIG_DIR=$HOME/.pfish
mkdir -p $CONFIG_DIR
if [ "$#" -eq 0 ]; then
echo "Expected one or more arguments\nFor more details, run\n pfish --help" >&2
elif [ $1 = "update" ]; then
echo "Updating pfish v.$VERSION (see: https://github.com/aquariumbio/pfish#updating)"
exec docker pull "aquariumbio/pfish:$VERSION"
elif [ $1 = "version" ]; then
echo "Pfish version " $VERSION
else
# Set up mounted volumes, environment, and run containerized pfish script:
# - use host network
# - run interactively
# - mount current working directory as working directory in container
# - mount user .pfish directory as config directory in container
# - set container working directory
exec docker run \
--net=host \
--interactive --tty --rm \
--volume "$PWD":/wd \
--volume "$CONFIG_DIR:/script/config" \
--workdir /wd \
"aquariumbio/pfish:$VERSION" "$@"
fi