-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeploy-timelines.sh
More file actions
executable file
·193 lines (162 loc) · 5.67 KB
/
deploy-timelines.sh
File metadata and controls
executable file
·193 lines (162 loc) · 5.67 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
# copy timelines to a target webserver directory
set -e
set -u
source $(dirname $0)/environ.sh
# timeline webserver directory
TIMELINEDIR=/u/group/clas/www/clas12mon/html/hipo
# input finding command
inputCmd="$TIMELINESRC/bin/set-input-dir.sh -s timeline_web"
inputCmdOpts=""
usage() {
echo """
USAGE: $0 [OPTIONS]...
========================================================================
| CAUTION: READ ALL OF THIS GUIDE BEFORE RUNNING!
|
| If you want a quick start, try the most typical command:
| $0 -d [DATASET] -t [TARGET_DIRECTORY] -D
| This will only print what will be done; remove -D to actually run
|
| WARNING: be careful not to overwrite anything you shouldn't
========================================================================
REQUIRED OPTIONS: copy timelines for dataset [DATASET] to [TARGET_DIRECTORY]
*** Specify at least one of the following:""" >&2
$inputCmd -h
echo """
*** Also, specify the target:
-t [TARGET_DIRECTORY] the top-level destination where the directory of
final timelines will be copied to
NOTES:
- [TARGET_DIRECTORY] is RELATIVE to \$TIMELINEDIR, where
TIMELINEDIR = $TIMELINEDIR
- use the -c option for a [TARGET_DIRECTORY] not relative to \$TIMELINEDIR
- you must have write permission to the destination directory
- recommendations for [TARGET_DIRECTORY]:
\$LOGNAME your personal directory for testing
[RUN_GROUP]/pass[PASS] the Run Group's directory; note the
file organization may vary between Run Groups
OPTIONAL OPTIONS:
-----------------
-D dry-run: prints what your command will do, but does not do it
-c interpret [TARGET_DIRECTORY] as a custom directory,
not relative to \$TIMELINEDIR
-s [SUB_DIRECTORY] customize the subdirectory of [TARGET_DIRECTORY] to
where timeline files will be copied
default = [DATASET]
-m [METADATA] include run-filter controls (for specific datasets)
available choices:
$(find $TIMELINESRC/data/metadata -name "*.json" -exec basename {} .json \; | sed 's;^; ;')
-n [NOTE] add a note that will be shown on the clas12mon webpage
(i.e., the README file); surround your note in quotes
-h print this usage guide
""" >&2
}
# parse arguments
[ $# -lt 2 ] && usage && exit 101
### optional arguments
dataset=""
targetDirArg=""
dryRun=false
customTarget=false
subDir=""
metadataFile=""
readmeNote=""
inputDir=""
helpMode=false
while getopts "d:i:Ut:Dcs:m:n:h-:" opt; do
case $opt in
d) inputCmdOpts+=" -d $OPTARG" ;;
i) inputCmdOpts+=" -i $OPTARG" ;;
U) inputCmdOpts+=" -U" ;;
t) targetDirArg=$OPTARG ;;
D) dryRun=true ;;
c) customTarget=true ;;
s) subDir=$OPTARG ;;
m) metadataFile=$OPTARG ;;
n) readmeNote=$OPTARG ;;
h) helpMode=true ;;
-)
[ "$OPTARG" != "help" ] && printError "unknown option --$OPTARG"
helpMode=true
;;
*) exit 100 ;;
esac
done
if $helpMode; then
usage
exit 101
fi
# set input directory and dataset name
dataset=$($inputCmd $inputCmdOpts -D)
inputDir=$($inputCmd $inputCmdOpts -I)
# check required options
[ -z "$dataset" -o -z "$inputDir" -o -z "$targetDirArg" ] && printError "missing one or more required options" && usage && exit 100
# check if the metadata file exists
if [ -n "$metadataFile" ]; then
metadataFile=$TIMELINESRC/data/metadata/$metadataFile.json
if [ -f "$metadataFile" ]; then
echo "using metadata file '$metadataFile'"
else
printError "metadata file '$metadataFile' does not exist (bad argument for option '-m')"
exit 100
fi
fi
# print the README note, if set
[ -n "$readmeNote" ] && echo "using the note: '$readmeNote'"
# specify target directory
[ -z "$subDir" ] && subDir=$dataset
if ${customTarget}; then
targetDir=$targetDirArg/$subDir
else
targetDir=$TIMELINEDIR/$targetDirArg/$subDir
fi
# print what we will do; exit prematurely if dry run
echo """
-----------------------------------------------------------
DEPLOYMENT PLAN: copy [SOURCE]/* [DESTINATION]/*
[SOURCE]: $inputDir
[DESTINATION]: $targetDir
[NOTE]: '$readmeNote'
WARNING: [DESTINATION] will be REMOVED before deploying!
-----------------------------------------------------------
"""
if ${dryRun}; then
echo """
This was a dry run, and nothing was done. Inspect the output above. Make sure
that you have write access to [DESTINATION]. If everything looks okay, re-run
your command without the -D option.
"""
exit 0
fi
# deploy
echo """-------------------------
DEPLOYING
-------------------------"""
mkdir -pv $targetDir
rm -rv $targetDir
mkdir -pv $targetDir
cp -rv $inputDir/* $targetDir/
[ -n "$metadataFile" ] && cp -v $metadataFile $targetDir/metadata.json
[ -n "$readmeNote" ] && echo "$readmeNote" > $targetDir/README
$TIMELINESRC/bin/run-groovy-timeline.sh $TIMELINESRC/bin/index-webpage.groovy $targetDir
echo "DONE."
# print URL
echo "-----------------------------------------------------------"
if ${customTarget}; then
domain="https://[YOUR_CUSTOM_DOMAIN]"
msg="""
Since you specified a custom [TARGET_DIRECTORY] with -c, you will need to
figure out the correct URL yourself; use the following URL as a template,
noting that you may need to remove some parent directories from the URL
"""
else
domain="https://clas12mon.jlab.org"
msg=""
fi
echo """
TIMELINE URL:
$msg
$domain/$targetDirArg/$subDir/tlsummary
"""
echo "-----------------------------------------------------------"