| 1 | #!@BASH@ |
|---|
| 2 | # |
|---|
| 3 | # Copyright (c) 2008, Christopher Cowart and contributors |
|---|
| 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # Redistribution and use in source and binary forms, with or without |
|---|
| 7 | # modification, are permitted provided that the following conditions |
|---|
| 8 | # are met: |
|---|
| 9 | # * Redistributions of source code must retain the above copyright |
|---|
| 10 | # notice, this list of conditions and the following disclaimer. |
|---|
| 11 | # * Redistributions in binary form must reproduce the above copyright |
|---|
| 12 | # notice, this list of conditions and the following disclaimer in the |
|---|
| 13 | # documentation and/or other materials provided with the distribution. |
|---|
| 14 | # |
|---|
| 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 16 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 17 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 18 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 19 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 20 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
|---|
| 21 | # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|---|
| 22 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|---|
| 23 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 24 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 25 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | # |
|---|
| 27 | # $Id$ |
|---|
| 28 | # |
|---|
| 29 | # This script obtains the latest "export" from confman and installs |
|---|
| 30 | # it onto the system. It is intended to be used in crons as the |
|---|
| 31 | # configuration pulling mechanism. |
|---|
| 32 | |
|---|
| 33 | if [ -r @pkgdatadir@/confmancommon.sh ] ; then |
|---|
| 34 | . @pkgdatadir@/confmancommon.sh |
|---|
| 35 | else |
|---|
| 36 | echo "Can't find confmancommon.sh. Exiting." >&2 |
|---|
| 37 | exit 17 |
|---|
| 38 | fi |
|---|
| 39 | |
|---|
| 40 | function print_help { |
|---|
| 41 | echo "usage: $0 [-f] [-s] [-d]" >&4 |
|---|
| 42 | echo "Type '$0 -h' to display this help and exit." >&4 |
|---|
| 43 | conf_cleanExit ${1:-0} |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | FORCE=false |
|---|
| 47 | QUIET=false |
|---|
| 48 | sleep_mode=false |
|---|
| 49 | |
|---|
| 50 | while getopts "fqsdh" OPT 2>&4 ; do |
|---|
| 51 | case $OPT in |
|---|
| 52 | f) FORCE=true ;; |
|---|
| 53 | s) sleep_mode=true ;; |
|---|
| 54 | d) DEBUG=true ;; |
|---|
| 55 | q) QUIET=true ;; |
|---|
| 56 | h) print_help 0;; |
|---|
| 57 | *) print_help 1;; |
|---|
| 58 | esac |
|---|
| 59 | done |
|---|
| 60 | |
|---|
| 61 | # If we're in debug mode, we should log stderr messages to the logger |
|---|
| 62 | # as well. Otherwise, we send them to the bit bucket. |
|---|
| 63 | if $DEBUG ; then |
|---|
| 64 | exec 1>&2 |
|---|
| 65 | else |
|---|
| 66 | exec 1>/dev/null |
|---|
| 67 | fi |
|---|
| 68 | |
|---|
| 69 | system_lock=$(conf_lock_system) |
|---|
| 70 | |
|---|
| 71 | conf_require_recipe |
|---|
| 72 | |
|---|
| 73 | if $sleep_mode; then |
|---|
| 74 | if [ -n "${CONF_SYNC_SLEEP}" ] && [ ${CONF_SYNC_SLEEP} -ge 0 ]; then |
|---|
| 75 | echo "Sleeping ${CONF_SYNC_SLEEP} seconds..." |
|---|
| 76 | sleep ${CONF_SYNC_SLEEP} |
|---|
| 77 | else |
|---|
| 78 | echo "Invalid sleep value: ${CONF_SYNC_SLEEP}" >&2 |
|---|
| 79 | exit 1 |
|---|
| 80 | fi |
|---|
| 81 | fi |
|---|
| 82 | |
|---|
| 83 | # Set up our "Working Copy" |
|---|
| 84 | tmpdir=$(conf_tmp_dir) |
|---|
| 85 | WORK_PATH="$tmpdir" |
|---|
| 86 | |
|---|
| 87 | tarpath=$(conf_fetch) |
|---|
| 88 | if ! [ -s $tarpath ] ; then |
|---|
| 89 | echo "Could not fetch the export." >&2 |
|---|
| 90 | exit 1 |
|---|
| 91 | fi |
|---|
| 92 | |
|---|
| 93 | case ${CONF_EXPORT_STYLE} in |
|---|
| 94 | repository|recipe) |
|---|
| 95 | tar -xzf $tarpath -C $tmpdir |
|---|
| 96 | ;; |
|---|
| 97 | module) |
|---|
| 98 | for layer in $(conf_get_recipe); do |
|---|
| 99 | tarfile="$tarpath/$layer.tgz" |
|---|
| 100 | if ! [ -s $tarfile ]; then |
|---|
| 101 | echo "Could not fetch the export." >&2 |
|---|
| 102 | exit 1 |
|---|
| 103 | fi |
|---|
| 104 | tar -xzf $tarfile -C $tmpdir |
|---|
| 105 | done |
|---|
| 106 | ;; |
|---|
| 107 | *) |
|---|
| 108 | echo "Unsupported export style." >&2 |
|---|
| 109 | exit 1 |
|---|
| 110 | ;; |
|---|
| 111 | esac |
|---|
| 112 | |
|---|
| 113 | rm -rf $tarpath |
|---|
| 114 | |
|---|
| 115 | tar_revision=`conf_revision` |
|---|
| 116 | sys_revision=`conf_sysrev` |
|---|
| 117 | last_action=$(conf_lastact) |
|---|
| 118 | statefile=$(conf_tmp_file) |
|---|
| 119 | |
|---|
| 120 | if [ -n "${sys_revision}" ] ; then |
|---|
| 121 | if [ "${tar_revision}" -lt "${sys_revision}" ]; then |
|---|
| 122 | echo "Error: ${tarpath} is out of date. Exiting without making changes." >&2 |
|---|
| 123 | conf_markdirty |
|---|
| 124 | conf_cleanExit 1 |
|---|
| 125 | elif ! ${FORCE} && [ "${tar_revision}" -eq "${sys_revision}" ]; then |
|---|
| 126 | if [ "${last_action}" = "commit" -o "${last_action}" = "sync" ]; then |
|---|
| 127 | ${QUIET} || echo "System is up to date." | conf_logger |
|---|
| 128 | conf_cleanExit 0 |
|---|
| 129 | fi |
|---|
| 130 | fi |
|---|
| 131 | fi |
|---|
| 132 | |
|---|
| 133 | echo "Sync operation started" | conf_logger |
|---|
| 134 | for layer in $(conf_get_reverse_recipe) ; do |
|---|
| 135 | echo "Rolling on $layer..." |
|---|
| 136 | |
|---|
| 137 | # XXX: Until ticket #151 is resolved, prefer to use the fdb metadata |
|---|
| 138 | # when it is available |
|---|
| 139 | if [ -r "$(conf_meta_dir)/${layer}.fdb" ]; then |
|---|
| 140 | declare -A metadata |
|---|
| 141 | filedb_load "$(conf_meta_dir)/${layer}.fdb" "metadata" |
|---|
| 142 | CONF_GET_PROP_USE_FDB="true" |
|---|
| 143 | fi |
|---|
| 144 | |
|---|
| 145 | conf_rollout $layer $statefile || conf_cleanExit |
|---|
| 146 | |
|---|
| 147 | if ${CONF_GET_PROP_USE_FDB}; then |
|---|
| 148 | unset metadata |
|---|
| 149 | fi |
|---|
| 150 | done |
|---|
| 151 | for file in $SINGULARITIES ; do |
|---|
| 152 | conf_assemble_sing $file || conf_cleanExit |
|---|
| 153 | done |
|---|
| 154 | conf_markclean |
|---|
| 155 | conf_recordAction sync |
|---|
| 156 | echo "Sync operation finished successfully" | conf_logger |
|---|
| 157 | |
|---|
| 158 | conf_unlock_system $system_lock |
|---|
| 159 | |
|---|
| 160 | rm -rf $tmpdir |
|---|
| 161 | |
|---|
| 162 | conf_cleanExit 0 |
|---|
| 163 | |
|---|