source: trunk/confaudit.in @ 548

Revision 548, 3.8 KB checked in by blee, 8 weeks ago (diff)

Also reverse the recipe in confaudit for consistency.

See #120

  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
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
30if [ -r @pkgdatadir@/confmancommon.sh ] ; then
31    . @pkgdatadir@/confmancommon.sh
32else
33    echo "Can't find confmancommon.sh. Exiting." >&2
34    exit 17
35fi
36
37function 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
43quiet=false
44sleep_mode=false
45while 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
53done
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.
57if $DEBUG ; then
58    exec 1>&2
59else
60    exec 1>/dev/null
61fi
62
63system_lock=$(conf_lock_system)
64
65conf_require_recipe
66
67if $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
75fi
76
77# Set up our "Working Copy"
78tmpdir=$(conf_tmp_dir)
79WORK_PATH="$tmpdir"
80
81tarpath=$(conf_fetch)
82if ! [ -s $tarpath ] ; then
83    echo "Could not fetch the export." >&2
84    exit 1
85fi
86
87case ${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        ;;
105esac
106
107rm -rf $tarpath
108
109tmproot=$(conf_tmp_dir)
110live_root="${LIVE_ROOT}"
111statefile=$(conf_tmp_file)
112
113# Override LIVE_ROOT to commit into our temporary directory.
114LIVE_ROOT="$tmproot"
115
116echo "Audit operation started" | conf_logger
117for layer in $(conf_get_reverse_recipe) ; do
118    echo "Rolling on $layer..."
119    conf_rollout $layer $statefile || conf_cleanExit
120done
121for file in $SINGULARITIES ; do
122    conf_assemble_sing $file || conf_cleanExit
123done
124rm -rf $tmpdir
125
126if $quiet; then
127    diff -ruq ${live_root}/ $tmproot | grep -v "^Only in" >&2
128else
129    diff -ru ${live_root}/ $tmproot | grep -v "^Only in" >&2
130fi
131echo "Audit operation finished successfully" | conf_logger
132
133conf_unlock_system $system_lock
134
135rm -rf $tmproot
136
137conf_cleanExit 0
138
Note: See TracBrowser for help on using the repository browser.