-
Notifications
You must be signed in to change notification settings - Fork 0
/
djamload
executable file
·127 lines (104 loc) · 3.03 KB
/
djamload
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# djam load file --target=prog --app=app_name
# We load the given file into the containers that are used by the target program
# and application.
die() {
printf '%s\n' "$1" >&2
exit 1
}
show_usage() {
cat << EOF
djamload file.jxe --target=program --app=appl_name
This command will load the file.jxe in the docker containers that are already
running the target program under the given application name (appl_name).
If no running instance is found, an error message will be printed.
EOF
}
if [ -z $1 ]; then
show_usage
exit 0
fi
checkdocker() {
if [ -e $1/dockerId ]; then
local didp=`cat $1/dockerId`
local present=`docker ps --filter id=$didp | grep $didp | wc -l | tr -d '[:space:]'`
if [ $present == "1" ]; then
running="docker"
else
running="none"
fi
fi
}
app=
target=
file=$1
shift
while :; do
case $1 in
-h|-\?|--help)
show_usage # Display a usage synopsis.
exit
;;
-a|--app) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
app=$2
shift
else
die 'ERROR: "--app" requires a non-empty option argument.'
fi
;;
--app=?*)
app=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--app=) # Handle the case of an empty
die 'ERROR: "--app" requires a non-empty option argument.'
;;
-t|--target) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
target=$2
shift
else
die 'ERROR: "--target" requires a non-empty option argument.'
fi
;;
--target=?*)
target=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--target=) # Handle the case of an empty
die 'ERROR: "--target" requires a non-empty option argument.'
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
# Check folder
jamfolder=$HOME"/__jamruns"
if [ ! -d $jamfolder ]; then
die "ERROR! No running instance found. "
fi
if [ -z $target ]; then
die "Target not specified.. cannot locate the running application."
fi
tname="${target%.*}"
tname=$tname"_"$app
if [ "$(ls -A $jamfolder)" ]; then
cd $jamfolder
for jruns in `ls $jamfolder/$tname`; do
dir=$jamfolder/$tname/$jruns
if [ -d $dir ]; then
checkdocker $dir
if [ $running == "docker" ]; then
runon=`cat $dir/dockerId`
docker cp $file $dbuildc:$file
fi
fi
done
fi