| 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 | |
|---|
| 30 | if [ -r @pkgdatadir@/confmancommon.sh ] ; then |
|---|
| 31 | . @pkgdatadir@/confmancommon.sh |
|---|
| 32 | else |
|---|
| 33 | echo "Can't find confmancommon.sh. Exiting." >&2 |
|---|
| 34 | exit 17 |
|---|
| 35 | fi |
|---|
| 36 | |
|---|
| 37 | function print_help { |
|---|
| 38 | echo "usage: $0 [-s] [-q] [-d]" >&4 |
|---|
| 39 | echo "Type '$0 -h' to display this help and exit." >&4 |
|---|
| 40 | conf_cleanExit ${1:-0} |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | quiet=false |
|---|
| 44 | sleep_mode=false |
|---|
| 45 | while getopts "sqdh" opt 2>&4 ; do |
|---|
| 46 | case $opt in |
|---|
| 47 | s) sleep_mode=true ;; |
|---|
| 48 | q) quiet=true ;; |
|---|
| 49 | d) DEBUG=true ;; |
|---|
| 50 | h) print_help 0 ;; |
|---|
| 51 | *) print_help 1 ;; |
|---|
| 52 | esac |
|---|
| 53 | done |
|---|
| 54 | |
|---|
| 55 | # If we're in debug mode, we should log stderr messages to the logger |
|---|
| 56 | # as well. Otherwise, we send them to the bit bucket. |
|---|
| 57 | if $DEBUG ; then |
|---|
| 58 | exec 1>&2 |
|---|
| 59 | else |
|---|
| 60 | exec 1>/dev/null |
|---|
| 61 | fi |
|---|
| 62 | |
|---|
| 63 | system_lock=$(conf_lock_system) |
|---|
| 64 | |
|---|
| 65 | conf_require_recipe |
|---|
| 66 | |
|---|
| 67 | if $sleep_mode; then |
|---|
| 68 | if [ -n "${CONF_AUDIT_SLEEP}" ] && [ ${CONF_AUDIT_SLEEP} -ge 0 ]; then |
|---|
| 69 | echo "Sleeping ${CONF_AUDIT_SLEEP} seconds..." |
|---|
| 70 | sleep ${CONF_AUDIT_SLEEP} |
|---|
| 71 | else |
|---|
| 72 | echo "Invalid sleep value: ${CONF_AUDIT_SLEEP}" >&2 |
|---|
| 73 | exit 1 |
|---|
| 74 | fi |
|---|
| 75 | fi |
|---|
| 76 | |
|---|
| 77 | # Set up our "Working Copy" |
|---|
| 78 | tmpdir=$(conf_tmp_dir) |
|---|
| 79 | WORK_PATH="$tmpdir" |
|---|
| 80 | |
|---|
| 81 | tarpath=$(conf_fetch) |
|---|
| 82 | if ! [ -s $tarpath ] ; then |
|---|
| 83 | echo "Could not fetch the export." >&2 |
|---|
| 84 | exit 1 |
|---|
| 85 | fi |
|---|
| 86 | |
|---|
| 87 | case ${CONF_EXPORT_STYLE} in |
|---|
| 88 | repository|recipe) |
|---|
| 89 | tar -xzf $tarpath -C $tmpdir |
|---|
| 90 | ;; |
|---|
| 91 | module) |
|---|
| 92 | for layer in $(conf_get_recipe); do |
|---|
| 93 | tarfile="$tarpath/$layer.tgz" |
|---|
| 94 | if ! [ -s $tarfile ]; then |
|---|
| 95 | echo "Could not fetch the export." >&2 |
|---|
| 96 | exit 1 |
|---|
| 97 | fi |
|---|
| 98 | tar -xzf $tarfile -C $tmpdir |
|---|
| 99 | done |
|---|
| 100 | ;; |
|---|
| 101 | *) |
|---|
| 102 | echo "Unsupported export style." >&2 |
|---|
| 103 | exit 1 |
|---|
| 104 | ;; |
|---|
| 105 | esac |
|---|
| 106 | |
|---|
| 107 | rm -rf $tarpath |
|---|
| 108 | |
|---|
| 109 | tmproot=$(conf_tmp_dir) |
|---|
| 110 | live_root="${LIVE_ROOT}" |
|---|
| 111 | statefile=$(conf_tmp_file) |
|---|
| 112 | |
|---|
| 113 | # Override LIVE_ROOT to commit into our temporary directory. |
|---|
| 114 | LIVE_ROOT="$tmproot" |
|---|
| 115 | |
|---|
| 116 | echo "Audit operation started" | conf_logger |
|---|
| 117 | for layer in $(conf_get_reverse_recipe) ; do |
|---|
| 118 | echo "Rolling on $layer..." |
|---|
| 119 | conf_rollout $layer $statefile || conf_cleanExit |
|---|
| 120 | done |
|---|
| 121 | for file in $SINGULARITIES ; do |
|---|
| 122 | conf_assemble_sing $file || conf_cleanExit |
|---|
| 123 | done |
|---|
| 124 | rm -rf $tmpdir |
|---|
| 125 | |
|---|
| 126 | if $quiet; then |
|---|
| 127 | diff -ruq ${live_root}/ $tmproot | grep -v "^Only in" >&2 |
|---|
| 128 | else |
|---|
| 129 | diff -ru ${live_root}/ $tmproot | grep -v "^Only in" >&2 |
|---|
| 130 | fi |
|---|
| 131 | echo "Audit operation finished successfully" | conf_logger |
|---|
| 132 | |
|---|
| 133 | conf_unlock_system $system_lock |
|---|
| 134 | |
|---|
| 135 | rm -rf $tmproot |
|---|
| 136 | |
|---|
| 137 | conf_cleanExit 0 |
|---|
| 138 | |
|---|