| 1 | #! /bin/bash |
|---|
| 2 | |
|---|
| 3 | ## |
|---|
| 4 | # This script obtains the latest "export" from confman and installs |
|---|
| 5 | # it onto the system. It is intended to be used in crons as the |
|---|
| 6 | # configuration pulling mechanism. |
|---|
| 7 | # |
|---|
| 8 | # Author: Chris Cowart <ccowart@rescomp.berkeley.edu> |
|---|
| 9 | # 4 December 2006 |
|---|
| 10 | # |
|---|
| 11 | # $Id$ |
|---|
| 12 | ## |
|---|
| 13 | |
|---|
| 14 | # Try loading a development library first |
|---|
| 15 | if [ -r ./confmancommon.sh ] ; then |
|---|
| 16 | echo "Loading development library from current working directory." >&2 |
|---|
| 17 | . ./confmancommon.sh |
|---|
| 18 | elif [ -r /usr/local/rescomp/lib/confmancommon.sh ] ; then |
|---|
| 19 | . /usr/local/rescomp/lib/confmancommon.sh |
|---|
| 20 | else |
|---|
| 21 | echo "Can't find confmancommon.sh. Exiting." >&2 |
|---|
| 22 | fi |
|---|
| 23 | |
|---|
| 24 | # If we're in debug mode, we should log stderr messages to the logger |
|---|
| 25 | # as well. Otherwise, we send them to the bit bucket. |
|---|
| 26 | if $DEBUG ; then |
|---|
| 27 | exec 1>&2 |
|---|
| 28 | else |
|---|
| 29 | exec 1>/dev/null |
|---|
| 30 | fi |
|---|
| 31 | |
|---|
| 32 | # Set up our "Working Copy" |
|---|
| 33 | tarball=$(conf_fetch) |
|---|
| 34 | if ! [ -s $tarball ] ; then |
|---|
| 35 | echo "Could not fetch the tarball." >&2 |
|---|
| 36 | exit 1 |
|---|
| 37 | fi |
|---|
| 38 | |
|---|
| 39 | tmpdir=$(mktemp -d -t confman) |
|---|
| 40 | |
|---|
| 41 | tar -xzf $tarball -C $tmpdir |
|---|
| 42 | rm -rf $tarball |
|---|
| 43 | WORK_PATH="$tmpdir" |
|---|
| 44 | |
|---|
| 45 | tar_revision=`conf_revision` |
|---|
| 46 | sys_revision=`conf_sysrev` |
|---|
| 47 | last_action=$(conf_lastact) |
|---|
| 48 | |
|---|
| 49 | if [ "x$last_action" = "xinstall" ] && [ $tar_revision -lt $sys_revision ] |
|---|
| 50 | then |
|---|
| 51 | echo "Error: File system may be dirty." \ |
|---|
| 52 | "A commit operation is recommended." >&2 |
|---|
| 53 | echo "Error: $tarball is out of date. Exiting without making changes." >&2 |
|---|
| 54 | conf_markdirty |
|---|
| 55 | rm -rf $tmpdir |
|---|
| 56 | exit 1 |
|---|
| 57 | fi |
|---|
| 58 | |
|---|
| 59 | if [ $tar_revision -lt $sys_revision ] ; then |
|---|
| 60 | echo "System is up to date." | conf_logger |
|---|
| 61 | rm -rf $tmpdir |
|---|
| 62 | exit 0 |
|---|
| 63 | fi |
|---|
| 64 | |
|---|
| 65 | echo "Sync operation started" | conf_logger |
|---|
| 66 | for layer in $LAYERS ; do |
|---|
| 67 | echo "Rolling on $layer..." |
|---|
| 68 | conf_rollout $layer || conf_cleanExit |
|---|
| 69 | done |
|---|
| 70 | for file in $SINGULARITIES ; do |
|---|
| 71 | echo "Assembing singularity $file..." |
|---|
| 72 | conf_assemble_sing $file || conf_cleanExit |
|---|
| 73 | done |
|---|
| 74 | conf_markclean |
|---|
| 75 | conf_recordAction sync |
|---|
| 76 | echo "Sync operation finished successfully" | conf_logger |
|---|
| 77 | |
|---|
| 78 | rm -rf $tmpdir |
|---|
| 79 | |
|---|