quick-mrb-start.sh
Go to the documentation of this file.
1 #! /bin/bash
2 # Downloads and installs dune-raw-data as an MRB-controlled repository
3 
4 # THIS WILL INSTALL THE OFFLINE, I.E., nu-QUALIFIED VERSION OF dune-raw-data
5 
6 bad_network=false
7 
8 
9 git_status=`git status 2>/dev/null`
10 git_sts=$?
11 if [ $git_sts -eq 0 ];then
12  echo "This script is designed to be run in a fresh install directory!"
13  exit 1
14 fi
15 
16 starttime=`date`
17 Base=$PWD
18 test -d products || mkdir products
19 test -d download || mkdir download
20 test -d log || mkdir log
21 
22 if $bad_network ; then
23  echo "\"bad_network\" parameter is set; therefore quick-mrb-start.sh makes the following assumptions: "
24  echo "-All needed products are on the host, and the setup for those products has been sourced"
25  echo "-The git repos for artdaq, etc., are already in this directory"
26  echo "-There's a file already existing called $Base/download/product_deps which will tell this script what version of artdaq, etc., to expect"
27  echo "-Your host has the SLF7 operating system"
28  echo "-You've deleted the directories which look like localProducts_dune_raw_data_* and build_slf7.x86_64 (though the versions may have changed since this instruction was written)"
29  sleep 5
30 fi
31 
32 
33 
34 env_opts_var=`basename $0 | sed 's/\.sh$//' | tr 'a-z-' 'A-Z_'`_OPTS
35 USAGE="\
36  usage: `basename $0` [options]
37 examples: `basename $0`
38  `basename $0` --debug --dune-raw-data-developer --dune-raw-data-develop-branch
39 --debug perform a debug build
40 --dune-raw-data-develop-branch Install the current \"develop\" version of dune-raw-data (may be unstable!)
41 --dune-raw-data-developer use if you have (and want to use) write access to the dune-raw-data repository
42 "
43 
44 # Process script arguments and options
45 eval env_opts=\${$env_opts_var-} # can be args too
46 eval "set -- $env_opts \"\$@\""
47 op1chr='rest=`expr "$op" : "[^-]\(.*\)"` && set -- "-$rest" "$@"'
48 op1arg='rest=`expr "$op" : "[^-]\(.*\)"` && set -- "$rest" "$@"'
49 reqarg="$op1arg;"'test -z "${1+1}" &&echo opt -$op requires arg. &&echo "$USAGE" &&exit'
50 args= do_help= opt_v=0; opt_lrd_w=0; opt_lrd_develop=0; opt_la_nw=0;
51 while [ -n "${1-}" ];do
52  if expr "x${1-}" : 'x-' >/dev/null;then
53  op=`expr "x$1" : 'x-\(.*\)'`; shift # done with $1
54  leq=`expr "x$op" : 'x-[^=]*\(=\)'` lev=`expr "x$op" : 'x-[^=]*=\(.*\)'`
55  test -n "$leq"&&eval "set -- \"\$lev\" \"\$@\""&&op=`expr "x$op" : 'x\([^=]*\)'`
56  case "$op" in
57  \?*|h*) eval $op1chr; do_help=1;;
58  -debug) opt_debug=--debug;;
59  -dune-raw-data-develop-branch) opt_lrd_develop=1;;
60  -dune-raw-data-developer) opt_lrd_w=1;;
61  *) echo "Unknown option -$op"; do_help=1;;
62  esac
63  else
64  aa=`echo "$1" | sed -e"s/'/'\"'\"'/g"` args="$args '$aa'"; shift
65  fi
66 done
67 eval "set -- $args \"\$@\""; unset args aa
68 
69 set -u # complain about uninitialed shell variables - helps development
70 
71 if [[ $opt_lrd_develop -eq 0 ]]; then
72  echo "JCF, May-12-2017: currently there isn't an official cut release of dune-raw-data; therefore you need to supply the --dune-raw-data-develop-branch argument to this script" >&2
73  exit 1
74 fi
75 
76 dune_repo=/cvmfs/dune.opensciencegrid.org/products/dune
77 
78 if [[ ! -e $dune_repo ]]; then
79  echo "This installation needs access to the CVMFS mount point for the dune repo, ${dune_repo}, in order to obtain the dunepdsprce packages. Aborting..." >&2
80  exit 1
81 fi
82 
83 source $dune_repo/setup
84 
85 larsoft_repo=/cvmfs/fermilab.opensciencegrid.org/products/larsoft
86 
87 if [[ -e $larsoft_repo ]]; then
88  source $larsoft_repo/setup
89 fi
90 
91 test -n "${do_help-}" -o $# -ge 2 && echo "$USAGE" && exit
92 
93 # JCF, 1/16/15
94 # Save all output from this script (stdout + stderr) in a file with a
95 # name that looks like "quick-start.sh_Fri_Jan_16_13:58:27.script" as
96 # well as all stderr in a file with a name that looks like
97 # "quick-start.sh_Fri_Jan_16_13:58:27_stderr.script"
98 alloutput_file=$( date | awk -v "SCRIPTNAME=$(basename $0)" '{print SCRIPTNAME"_"$1"_"$2"_"$3"_"$4".script"}' )
99 stderr_file=$( date | awk -v "SCRIPTNAME=$(basename $0)" '{print SCRIPTNAME"_"$1"_"$2"_"$3"_"$4"_stderr.script"}' )
100 exec > >(tee "$Base/log/$alloutput_file")
101 exec 2> >(tee "$Base/log/$stderr_file")
102 
103 function detectAndPull() {
104  local startDir=$PWD
105  cd $Base/download
106  local packageName=$1
107  local packageOs=$2
108 
109  if [ $# -gt 2 ];then
110  local qualifiers=$3
111  fi
112  if [ $# -gt 3 ];then
113  local packageVersion=$4
114  else
115  local packageVersion=`curl http://scisoft.fnal.gov/scisoft/packages/${packageName}/ 2>/dev/null|grep ${packageName}|grep "id=\"v"|tail -1|sed 's/.* id="\(v.*\)".*/\1/'`
116  fi
117  local packageDotVersion=`echo $packageVersion|sed 's/_/\./g'|sed 's/v//'`
118 
119  if [[ "$packageOs" != "noarch" ]]; then
120  local upsflavor=`ups flavor`
121  local packageQualifiers="-`echo $qualifiers|sed 's/:/-/g'`"
122  local packageUPSString="-f $upsflavor -q$qualifiers"
123  fi
124  local packageInstalled=`ups list -aK+ $packageName $packageVersion ${packageUPSString-}|grep -c "$packageName"`
125  if [ $packageInstalled -eq 0 ]; then
126  local packagePath="$packageName/$packageVersion/$packageName-$packageDotVersion-${packageOs}${packageQualifiers-}.tar.bz2"
127  echo wget http://scisoft.fnal.gov/scisoft/packages/$packagePath
128  wget http://scisoft.fnal.gov/scisoft/packages/$packagePath >/dev/null 2>&1
129  local packageFile=$( echo $packagePath | awk 'BEGIN { FS="/" } { print $NF }' )
130 
131  if [[ ! -e $packageFile ]]; then
132  echo "Unable to download $packageName"
133  exit 1
134  fi
135 
136  local returndir=$PWD
137  cd $Base/products
138  tar -xjf $Base/download/$packageFile
139  cd $returndir
140  fi
141  cd $startDir
142 }
143 
144 if $bad_network ; then
145  os="slf7"
146 else
147  os=
148 fi
149 
150 cd $Base/download
151 
152 if [[ -z $os ]]; then
153  echo "Cloning cetpkgsupport to determine current OS"
154  git clone http://cdcvs.fnal.gov/projects/cetpkgsupport
155  os=`./cetpkgsupport/bin/get-directory-name os`
156 fi
157 
158 if [[ "$os" == "u14" ]]; then
159  echo "-H Linux64bit+3.19-2.19" >../products/ups_OVERRIDE.`hostname`
160 fi
161 
162 # Get all the information we'll need to decide which exact flavor of the software to install
163 if [ -z "${tag:-}" ]; then
164  tag=develop;
165 fi
166 
167 if ! $bad_network; then
168  wget https://cdcvs.fnal.gov/redmine/projects/dune-raw-data/repository/revisions/$tag/raw/ups/product_deps
169 fi
170 
171 if [[ ! -e $Base/download/product_deps ]]; then
172  echo "You need to have a product_deps file in $Base/download" >&2
173  exit 1
174 fi
175 
176 coredemo_version=`grep "parent dune_raw_data" $Base/download/product_deps|awk '{print $3}'`
177 
178 default_quals=$( awk '/^defaultqual/ {print $2} ' $Base/download/product_deps )
179 default_quals=$( echo $default_quals | sed -r 's/online/nu/' )
180 
181 quals=$default_quals
182 
183 defaultE=$( echo $quals | sed -r 's/.*(e[0-9]+).*/\1/' )
184 defaultS=$( echo $quals | sed -r 's/.*(s[0-9]+).*/\1/' )
185 
186 if [ -n "${equalifier-}" ]; then
187  equalifier="e${equalifier}";
188 else
189  equalifier=$defaultE
190 fi
191 if [ -n "${squalifier-}" ]; then
192  squalifier="s${squalifier}"
193 else
194  squalifier=$defaultS
195 fi
196 if [[ -n "${opt_debug:-}" ]] ; then
197  build_type="debug"
198 else
199  build_type="prof"
200 fi
201 
202 artdaq_core_version=$( sed -r -n 's/artdaq_core\s+(.*)\s+nu.*/\1/p' $Base/download/product_deps )
203 art_version=$( sed -r -n 's/art\s+(.*)\s+nu.*/\1/p' $Base/download/product_deps)
204 TRACE_version=$( sed -r -n 's/TRACE\s+(.*)\s+nu.*/\1/p' $Base/download/product_deps)
205 cetbuildtools_version=$( sed -r -n 's/cetbuildtools\s+(.*)\s+nu.*/\1/p' $Base/download/product_deps)
206 
207 
208 artdaq_core_version_dot=$( echo $artdaq_core_version | sed -r 's/v//;s/_/./g' )
209 art_version_dot=$( echo $art_version | sed -r 's/v//;s/_/./g' )
210 TRACE_version_dot=$( echo $TRACE_version | sed -r 's/v//;s/_/./g' )
211 cetbuildtools_version_dot=$( echo $cetbuildtools_version | sed -r 's/v//;s/_/./g' )
212 
213 # If we aren't connected to the outside world, you'll need to have
214 # previously scp'd or rsync'd the products to the host you're trying
215 # to install dune-artdaq on
216 
217 if ! $bad_network; then
218  wget http://scisoft.fnal.gov/scisoft/bundles/tools/pullProducts
219  chmod +x pullProducts
220 
221  ./pullProducts $Base/products ${os} art-${art_version} ${equalifier} ${build_type}
222 
223  if [ $? -ne 0 ]; then
224  echo "Error in pullProducts. Please go to http://scisoft.fnal.gov/scisoft/bundles/art/${art_version}/manifest and make sure that a manifest for the specified qualifier (${equalifier}) exists."
225  exit 1
226  fi
227 
228  detectAndPull mrb noarch
229 
230  curl -O http://scisoft.fnal.gov/scisoft/packages/artdaq_core/$artdaq_core_version/artdaq_core-${artdaq_core_version_dot}-${os}-x86_64-${equalifier}-${squalifier}-${build_type}.tar.bz2
231  curl -O http://scisoft.fnal.gov/scisoft/packages/cetbuildtools/$cetbuildtools_version/cetbuildtools-${cetbuildtools_version_dot}-noarch.tar.bz2
232  curl -O http://scisoft.fnal.gov/scisoft/packages/TRACE/$TRACE_version/TRACE-${TRACE_version_dot}-${os}-x86_64.tar.bz2
233 fi
234 
235 cd $Base/products
236 
237 echo "Unzipping downloaded archive files; this may take a while..."
238 
239 for archivefile in $Base/download/*.bz2; do
240  echo tar xjf $archivefile
241  tar xjf $archivefile
242 done
243 
244 source $Base/products/setup
245 setup mrb
246 setup git
247 setup gitflow
248 
249 export MRB_PROJECT=dune_raw_data
250 cd $Base
251 mrb newDev -f -v $coredemo_version -q ${quals}:${build_type}
252 set +u
253 localproducts_setup=$Base/localProducts_dune_raw_data_${coredemo_version}_$( echo $quals | tr ':' '_' )_${build_type}/setup
254 source $localproducts_setup
255 set -u
256 
257 cd $MRB_SOURCE
258 
259 if [[ $opt_lrd_develop -eq 1 ]]; then
260  dune_raw_data_checkout_arg="-d dune_raw_data"
261 else
262  dune_raw_data_checkout_arg="-t ${coredemo_version} -d dune_raw_data"
263 fi
264 
265 
266 if [[ $opt_lrd_w -eq 1 ]]; then
267  dune_raw_data_repo="ssh://p-dune-raw-data@cdcvs.fnal.gov/cvs/projects/dune-raw-data"
268 else
269  dune_raw_data_repo="http://cdcvs.fnal.gov/projects/dune-raw-data"
270 fi
271 
272 if ! $bad_network; then
273 
274 
275  mrb gitCheckout $dune_raw_data_checkout_arg $dune_raw_data_repo
276 
277  if [[ "$?" != "0" ]]; then
278  echo "Unable to perform checkout of $dune_raw_data_repo"
279  exit 1
280  fi
281 
282 fi
283 
284 sed -i -r '/^defaultqual/s/online/nu/' $Base/srcs/dune_raw_data/ups/product_deps
285 
286 ARTDAQ_DEMO_DIR=$Base/srcs/dune_raw_data
287 cd $Base
288  cat >setupDUNERAWDATA <<-EOF
289  echo # This script is intended to be sourced.
290 
291  sh -c "[ \`ps \$\$ | grep bash | wc -l\` -gt 0 ] || { echo 'Please switch to the bash shell before running dune-raw-data.'; exit; }" || exit
292  source $Base/products/setup
293  source $dune_repo/setup
294 
295  if [[ -e $larsoft_repo ]]; then
296  source $larsoft_repo/setup
297  fi
298 
299  setup mrb
300  source $localproducts_setup
301  source mrbSetEnv
302 
303  export DAQ_INDATA_PATH=$ARTDAQ_DEMO_DIR/test/Generators:$ARTDAQ_DEMO_DIR/inputData
304 
305  export DUNERAWDATA_BUILD=$MRB_BUILDDIR/dune_raw_data
306  export DUNERAWDATA_REPO="$ARTDAQ_DEMO_DIR"
307  setup TRACE $TRACE_version
308  setup art $art_version -q ${equalifier}:${build_type}
309  setup artdaq_core $artdaq_core_version -q ${equalifier}:${build_type}:${squalifier}
310 
311 
312  EOF
313  #
314 
315 source $dune_repo/setup
316 source $Base/products/setup
317 
318 cd $MRB_BUILDDIR
319 set +u
320 source mrbSetEnv
321 set -u
322 setup TRACE $TRACE_version
323 setup art $art_version -q ${equalifier}:${build_type}
324 setup artdaq_core $artdaq_core_version -q ${equalifier}:${build_type}:${squalifier}
325 
326 
327 export CETPKG_J=$((`cat /proc/cpuinfo|grep processor|tail -1|awk '{print $3}'` + 1))
328 mrb build # VERBOSE=1
329 installStatus=$?
330 
331 if [ $installStatus -eq 0 ]; then
332  echo "dune-raw-data has been installed correctly."
333  echo
334 else
335  echo "Build error. If all else fails, try (A) logging into a new terminal and (B) creating a new directory out of which to run this script."
336  echo
337 fi
338 
339 endtime=`date`
340 
341 echo "Build start time: $starttime"
342 echo "Build end time: $endtime"
343