PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/install/codemgmt/sneeze

http://casacore.googlecode.com/
Shell | 514 lines | 327 code | 76 blank | 111 comment | 48 complexity | b0410bd00abc9895f97a7043be3ca4ad MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/bin/sh
  2. #-----------------------------------------------------------------------------
  3. # sneeze: Rebuild the AIPS++ system areas for 'inhale'
  4. #-----------------------------------------------------------------------------
  5. #
  6. # Copyright (C) 1993-1997,2001,2003
  7. # Associated Universities, Inc. Washington DC, USA.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #
  23. # Correspondence concerning AIPS++ should be addressed as follows:
  24. # Internet email: aips2-request@nrao.edu.
  25. # Postal address: AIPS++ Project Office
  26. # National Radio Astronomy Observatory
  27. # 520 Edgemont Road
  28. # Charlottesville, VA 22903-2475 USA
  29. #
  30. #-----------------------------------------------------------------------------
  31. # Usage: sneeze [-l] [-e <extlist>] [-m <mode>] [-s <seconds>] targets
  32. #-----------------------------------------------------------------------------
  33. # sneeze rebuilds the AIPS++ system areas performing certain accounting
  34. # functions. It is intended for the use of 'inhale' rather than for general
  35. # usage.
  36. #
  37. # Options:
  38. # -e Serially rebuild the systems corresponding to each "aips_ext" in
  39. # the blank- or colon-separated list. If no "-e" option is given
  40. # sneeze just rebuilds the host's default architecture (as specified
  41. # in "aipshosts"). An "_" in the extlist signals no extension.
  42. #
  43. # -l Log mode - if specified then the output of sneeze will be logged
  44. # to the file specified by the "sneeze.$HOST.$AIPSEXT.logfile"
  45. # resource and mailed to the addresses specified by the
  46. # "sneeze.$HOST.$AIPSEXT.logmail" resource. If these are not defined
  47. # the log is sent to $AIPSARCH/sneeze.log and the mail to
  48. # aips2-inhale@nrao.edu.
  49. #
  50. # -m Mode of the rebuild, "incremental" (default), "cumulative",
  51. # "hybrid", or "base".
  52. #
  53. # -s time to wait until starting. Helpful in avoid simultaneous glish build problems
  54. #
  55. # Status return values correspond to the various phases of the operation
  56. # 0: success
  57. # 1: initialization error
  58. # 2: error rebuilding the system
  59. #
  60. # Notes:
  61. # 1) It is assumed that the code areas have already been brought up-to-date
  62. # with respect to the slave repositories.
  63. #
  64. # Original: 1993/07/13 by Mark Calabretta, ATNF
  65. # $Id: sneeze 18684 2005-05-20 07:38:57Z gvandiep $
  66. #=============================================================================
  67. # Initialize
  68. #-----------------------------------------------------------------------------
  69. # Check that AIPSPATH is defined.
  70. if [ "$AIPSPATH" = "" ]
  71. then
  72. exec 1>&2
  73. echo ""
  74. echo "sneeze: AIPSPATH is undefined, abort!"
  75. exit 1
  76. fi
  77. # Parse AIPSPATH.
  78. AIPSROOT=`echo $AIPSPATH | awk '{print $1}'`
  79. ARCH=`echo $AIPSPATH | awk '{print $2}'`
  80. SITE=`echo $AIPSPATH | awk '{print $3}'`
  81. HOST=`echo $AIPSPATH | awk '{print $4}'`
  82. # Check the accessibility of the AIPSROOT area.
  83. if [ ! -d "$AIPSROOT" ]
  84. then
  85. exec 1>&2
  86. echo ""
  87. echo "sneeze: The AIPS++ root directory does not exist or is not"
  88. echo " accessible, $AIPSROOT"
  89. exit 1
  90. fi
  91. # Check the default architecture.
  92. if [ "$ARCH" = ARCH -o "$ARCH" = "" ]
  93. then
  94. exec 1>&2
  95. echo ""
  96. echo "sneeze: The host architecture could not be determined, abort!"
  97. exit 1
  98. fi
  99. # Guard against being overwritten.
  100. case $0 in
  101. *-)
  102. ;;
  103. *)
  104. ARGS=
  105. DOLOG=
  106. EXTLIST=
  107. while [ "$#" -gt 0 ]
  108. do
  109. case $1 in
  110. -e*)
  111. case $1 in
  112. -e)
  113. shift
  114. EXTLIST=`echo $1 | sed -e 's/ */:/g'`
  115. ;;
  116. *)
  117. EXTLIST=`echo $1 | sed -e '{s/^-e//;s/ */:/g}'`
  118. ;;
  119. esac
  120. ;;
  121. -l)
  122. DOLOG=1
  123. ARGS="$ARGS $1"
  124. ;;
  125. -s)
  126. shift
  127. echo "Sleeping $1 seconds before continuing..."
  128. sleep $1
  129. echo "continuing"
  130. shift
  131. ;;
  132. *)
  133. ARGS="$ARGS $1"
  134. ;;
  135. esac
  136. [ "x$2" = "x" ] && break
  137. shift
  138. done
  139. if [ "$EXTLIST" = "" ]
  140. then
  141. case $ARCH in
  142. *_*)
  143. EXTLIST=`echo $ARCH | sed -e 's/.*_//'`
  144. ;;
  145. *)
  146. EXTLIST="_"
  147. ;;
  148. esac
  149. fi
  150. # Resolve logging issues.
  151. LOGFILE=""
  152. LOGMAIL=""
  153. LOGMAILER=""
  154. if [ "$DOLOG" ]
  155. then
  156. EXTLIST=`echo :$EXTLIST: | sed -e 's/::*/::/g'`
  157. AIPSEXT=`echo $EXTLIST | sed -e '{s/^:://;s/::.*//;}'`
  158. EXTLIST=`echo $EXTLIST | sed -e "{s/::/:/g;s/^://;s/:$//;}"`
  159. aips_ext=$AIPSEXT . $AIPSROOT/aipsinit.sh
  160. LOGFILE=`getrc -i sneeze.$HOST.$AIPSEXT.logfile 2> /dev/null`
  161. LOGMAIL=`getrc -i sneeze.$HOST.$AIPSEXT.logmail 2> /dev/null`
  162. LOGMAILER=`getrc -i sneeze.$HOST.$AIPSEXT.mailer 2> /dev/null`
  163. [ "$LOGFILE" = "" ] && LOGFILE=$AIPSROOT/$ARCH/sneeze.log
  164. [ "$LOGMAIL" = "" ] && LOGMAIL=aips2-inhale@nrao.edu
  165. [ "$LOGMAILER" = "" ] && LOGMAILER=mail
  166. fi
  167. cp $0 $0-
  168. if [ "$LOGMAIL" != "" ]
  169. then
  170. $0- -e $EXTLIST $ARGS 2>&1 | tee $LOGFILE | $LOGMAILER $LOGMAIL
  171. exit 0
  172. else
  173. exec $0- -e $EXTLIST $ARGS 2>&1 > $LOGFILE
  174. fi
  175. ;;
  176. esac
  177. # Set default file creation mode.
  178. umask 002
  179. # Identify ourselves.
  180. LOGNAME=${LOGNAME-$USER}
  181. echo ""
  182. echo "sneeze: $AIPSPATH"
  183. echo ""
  184. echo "sneeze: Execution on $HOST by $LOGNAME commenced at"
  185. echo "sneeze: `adate`"
  186. echo "sneeze: `adate -l`"
  187. echo ""
  188. echo "sneeze: Command line arguments \"$*\""
  189. # Parse command input.
  190. DOLOG=""
  191. EXTLIST="_"
  192. MODE=incremental
  193. TARGETS=""
  194. while [ "$#" -gt 0 ]
  195. do
  196. case $1 in
  197. -e*)
  198. case $1 in
  199. -e)
  200. shift
  201. EXTLIST=`echo $1 | sed -e 's/ */:/g'`
  202. ;;
  203. *)
  204. EXTLIST=`echo $1 | sed -e '{s/^-e//;s/ */:/g}'`
  205. ;;
  206. esac
  207. ;;
  208. -l)
  209. DOLOG=1
  210. ;;
  211. -m*)
  212. case $1 in
  213. -m)
  214. shift
  215. MODE="$1"
  216. ;;
  217. *)
  218. MODE=`echo $1 | sed -e 's/^-m//'`
  219. ;;
  220. esac
  221. ;;
  222. *)
  223. TARGETS="$TARGETS $1"
  224. ;;
  225. esac
  226. [ "" = "$2" ] && break
  227. shift
  228. done
  229. [ "$EXTLIST" = "" ] && EXTLIST="_"
  230. EXTLIST=`echo :$EXTLIST: | sed -e 's/::*/::/g'`
  231. # Redefine AIPSPATH.
  232. AIPSEXT=`echo $EXTLIST | sed -e '{s/^:://;s/::.*//;}'`
  233. aips_ext=$AIPSEXT . $AIPSROOT/aipsinit.sh
  234. # Revise ARCH.
  235. ARCH=`echo $AIPSPATH | awk '{ print $2 }'`
  236. # Update EXTLIST.
  237. EXTLIST=`echo $EXTLIST | \
  238. sed -e "{s/:$AIPSEXT://g;s/::/:/g;s/^://;s/:$//;}"`
  239. TARGETS=`echo $TARGETS`
  240. [ "$TARGETS" = "" ] && TARGETS=allsys
  241. # Define major AIPS++ directories.
  242. AIPSCODE="$AIPSROOT/code"
  243. AIPSARCH="$AIPSROOT/$ARCH"
  244. ARCHTMPD="$AIPSARCH/tmp"
  245. # What is the very latest version?
  246. NEWVERSN=`cat $AIPSCODE/VERSION | awk '{ print $1 }'`
  247. NEWMAJOR=`echo $NEWVERSN | awk -F. '{ print $1 }'`
  248. NEWMINOR=`echo $NEWVERSN | awk -F. '{ print $2 }'`
  249. DASH=`echo $ARCH | sed -e 's/./-/g'`
  250. echo ""
  251. echo "sneeze: Rebuild AIPS++ version $NEWVERSN for $ARCH."
  252. echo "----------------------------------------------$DASH"
  253. # Ensure that the system areas exist.
  254. if [ ! -d "$AIPSARCH" ]
  255. then
  256. exec 1>&2
  257. echo ""
  258. echo "sneeze: $AIPSARCH does not exist, you must run 'configure'"
  259. echo "to create it, abort!"
  260. exit 1
  261. fi
  262. # Get account information.
  263. AIPS2MGR=`getrc -i account.manager 2> /dev/null`
  264. AIPS2PRG=`getrc -i account.programmer 2> /dev/null`
  265. MGRACCNT=`echo $AIPS2MGR | sed -e 's/\..*//'`
  266. MGRGROUP=`echo $AIPS2MGR | sed -e 's/.*\.//'`
  267. PRGGROUP=`echo $AIPS2PRG | sed -e 's/.*\.//'`
  268. # Check that we're being run from the right account.
  269. if [ "$MGRACCNT" != "$LOGNAME" -a "$MGRACCNT" != "" ]
  270. then
  271. exec 1>&2
  272. echo ""
  273. echo "sneeze: This utility can only be run by $MGRACCNT, not" \
  274. "$LOGNAME, abort!"
  275. exit 1
  276. fi
  277. # Report the amount of free space available for the rebuild.
  278. echo ""
  279. echo "sneeze: Available space in the /tmp and $AIPSARCH partitions"
  280. df /tmp $AIPSARCH
  281. #-----------------------------------------------------------------------------
  282. # Rebuild the system
  283. #-----------------------------------------------------------------------------
  284. echo ""
  285. echo "sneeze: Applying system deletions..."
  286. trap 'echo "" ; \
  287. echo "sneeze: Cleaning up..." ; \
  288. cd $AIPSROOT ; \
  289. rm -f $ARCHTMPD/ax_master ; \
  290. exit' 1 2 3 15
  291. cp $AIPSCODE/install/codemgmt/ax_master $ARCHTMPD/ax_master
  292. chmod u+rwx $ARCHTMPD/ax_master
  293. if [ "$MODE" = incremental ]
  294. then
  295. # Apply deletions for the current version onwards.
  296. $ARCHTMPD/ax_master -system -s
  297. else
  298. # Apply all deletions.
  299. $ARCHTMPD/ax_master -system -s -c
  300. fi
  301. rm -f $ARCHTMPD/ax_master
  302. # Check or set directory ownerships and permissions.
  303. find $AIPSARCH -type d ! -user $MGRACCNT \
  304. -exec echo "Incorrect directory ownership:" {} \;
  305. find $AIPSARCH -type d ! -group $PRGGROUP -exec chgrp $PRGGROUP {} \;
  306. find $AIPSARCH -type d ! -perm 2775 -exec chmod ug=rwx,g+s,o=rx {} \;
  307. cd $AIPSCODE
  308. # Clean up the system areas on cumulative updates.
  309. if [ "$MODE" != incremental ]
  310. then
  311. echo ""
  312. echo "sneeze: Cleaning up the system areas..."
  313. gmake NODEP=1 cleansys
  314. fi
  315. # Rebuild the system.
  316. echo ""
  317. echo "sneeze: Rebuilding the system..."
  318. gmake $TARGETS
  319. # Mark it as done.
  320. cd $AIPSARCH
  321. [ -f LOGFILE ] || touch LOGFILE
  322. mv -f LOGFILE LOGFILE_
  323. echo "$NEWVERSN `adate` ($TARGETS)" | cat - LOGFILE_ > LOGFILE
  324. [ -f VERSION ] && mv -f VERSION VERSION_
  325. cp -p $AIPSCODE/VERSION .
  326. chmod 444 VERSION LOGFILE
  327. rm -f VERSION_ LOGFILE_
  328. #-----------------------------------------------------------------------------
  329. # Preserve the base system.
  330. #-----------------------------------------------------------------------------
  331. if [ "$MODE" = base ]
  332. then
  333. echo ""
  334. cd $AIPSROOT
  335. BASEROOT="$AIPSROOT/base-$NEWMAJOR"
  336. [ -d "$BASEROOT" ] || mkdir $BASEROOT
  337. chgrp $PRGGROUP $BASEROOT
  338. chmod ug=rwx,g+s,o=rx $BASEROOT
  339. BASESYS=`getrc -i sneeze.base.$ARCH.preserve 2> /dev/null`
  340. BASESYS=`affirm -a $BASESYS`
  341. if [ "$BASESYS" != false ]
  342. then
  343. echo "sneeze: Preserve the base system."
  344. echo "---------------------------------"
  345. echo ""
  346. echo "sneeze: Copying $AIPSARCH to $BASEROOT/$ARCH..."
  347. # Use the "h" option to force tar to follow symlinks.
  348. tar chf - $ARCH | (cd $BASEROOT && tar pvxf -)
  349. else
  350. echo "sneeze: Preserve the critical parts of the base system."
  351. echo "-------------------------------------------------------"
  352. mkdir $BASEROOT/$ARCH
  353. chgrp $PRGGROUP $BASEROOT/$ARCH
  354. chmod ug=rwx,g+s,o=rx $BASEROOT/$ARCH
  355. echo ""
  356. echo "sneeze: Copying $AIPSARCH/$SITE to $BASEROOT/$ARCH/$SITE..."
  357. # Use the "h" option to force tar to follow symlinks.
  358. tar chf - $ARCH/aipsrc $ARCH/makedefs $ARCH/$SITE | \
  359. (cd $BASEROOT && tar pvxf -)
  360. fi
  361. if [ -d "$BASEROOT/code/install" ]
  362. then
  363. # Remake the root directory.
  364. echo ""
  365. echo "sneeze: Remaking files in $BASEROOT..."
  366. cp $AIPSROOT/aipshosts $BASEROOT
  367. ( AIPSPATH="$BASEROOT $ARCH $SITE $HOST" ; \
  368. export AIPSPATH ; \
  369. gmake -C $BASEROOT/code/install aipsroot )
  370. fi
  371. # Preserve the base documentation but only if we build it.
  372. BASEDOCS=`getrc -i sneeze.base.docs.preserve 2> /dev/null`
  373. BASEDOCS=`affirm -a $BASEDOCS`
  374. if [ "$BASEDOCS" != false ]
  375. then
  376. # Check that we build the documentation.
  377. eval `gmake VARS=DOCSYS eval_vars`
  378. if [ "$DOCSYS" = doc ]
  379. then
  380. echo "sneeze: Preserve the base documentation."
  381. echo "----------------------------------------"
  382. echo ""
  383. echo "sneeze: Copying $AIPSROOT/docs to $BASEROOT/docs..."
  384. # Use the "h" option to force tar to follow symlinks.
  385. tar chf - docs | (cd $BASEROOT && tar pvxf -)
  386. fi
  387. fi
  388. fi
  389. #-----------------------------------------------------------------------------
  390. # Wind up.
  391. #-----------------------------------------------------------------------------
  392. cd $AIPSCODE
  393. # Produce diagnostics on cumulative updates.
  394. if [ "$MODE" != incremental ]
  395. then
  396. echo ""
  397. echo "sneeze: System diagnostics."
  398. echo "---------------------------"
  399. gmake -f $AIPSARCH/makedefs diagnostics
  400. fi
  401. # We're finished with this architecture.
  402. echo ""
  403. echo "sneeze: Execution terminated at"
  404. echo "sneeze: `adate`"
  405. echo "sneeze: `adate -l`"
  406. # Recurse if necessary.
  407. if [ "$EXTLIST" != "" ]
  408. then
  409. if [ "$DOLOG" != "" ]
  410. then
  411. # Find the next AIPSEXT.
  412. EXTLIST=`echo :$EXTLIST: | sed -e 's/::*/::/g'`
  413. AIPSEXT=`echo $EXTLIST | sed -e '{s/^:://;s/::.*//;}'`
  414. EXTLIST=`echo $EXTLIST | sed -e "{s/::/:/g;s/^://;s/:$//;}"`
  415. aips_ext=$AIPSEXT . $AIPSROOT/aipsinit.sh
  416. ARCH=`echo $AIPSPATH | awk '{ print $2 }'`
  417. LOGFILE=`getrc -i sneeze.$HOST.$AIPSEXT.logfile 2> /dev/null`
  418. LOGMAIL=`getrc -i sneeze.$HOST.$AIPSEXT.logmail 2> /dev/null`
  419. LOGMAILER=`getrc -i sneeze.$HOST.$AIPSEXT.mailer 2> /dev/null`
  420. [ "$LOGFILE" = "" ] && LOGFILE=$AIPSROOT/$ARCH/sneeze.log
  421. [ "$LOGMAIL" = "" ] && LOGMAIL=aips2-inhale@nrao.edu
  422. [ "$LOGMAILER" = "" ] && LOGMAILER=mail
  423. if [ "$LOGMAIL" != "" ]
  424. then
  425. (exec $0 -e $EXTLIST -l -m $MODE $TARGETS 2>&1 | \
  426. tee $LOGFILE | $LOGMAILER $LOGMAIL) &
  427. exit 0
  428. else
  429. exec $0 -e $EXTLIST -l -m $MODE $TARGETS 2>&1 > $LOGFILE
  430. fi
  431. else
  432. echo ""
  433. echo ""
  434. echo ""
  435. exec $0 -e $EXTLIST -m $MODE $TARGETS
  436. fi
  437. fi
  438. exit 0