source: trunk/confexport.in @ 591

Revision 591, 4.9 KB checked in by blee, 6 weeks ago (diff)

In confexport always use conf_revision_svn since the fdb may be stale.

Fixes #139

  • 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# This script prepares an "export" of the confman repository for system
30# processes to be able to pull. It is intended to be prepared regularly
31# by an automated process like cron.
32
33if [ -r @pkgdatadir@/confmancommon.sh ] ; then
34    . @pkgdatadir@/confmancommon.sh
35else
36    echo "Can't find confmancommon.sh. Exiting." >&2
37    exit 17
38fi
39
40# This changes the behavior of some library functions (e.g. URIs, locks)
41CONF_EXPORT=true
42
43function print_help {
44    echo "usage: $0 [-f] [-d]" >&4
45    echo "Type '$0 -h' to display this help and exit." >&4
46    conf_cleanExit ${1:-0}
47}
48
49FORCE=false
50DEBUG=false
51
52while getopts "fdh" OPT 2>&4 ; do
53    case "$OPT" in
54        f)  FORCE=true ;;
55        d)  DEBUG=true ;;
56        h)  print_help 0;;
57        *)  print_help 1;;
58    esac
59done
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.
63if $DEBUG ; then
64    exec 1>&2
65else
66    exec 1>/dev/null
67fi
68
69echo "Export operation started" | conf_logger
70
71confexport_lock_system
72
73umask 077
74
75case ${CONF_EXPORT_STYLE} in
76    repository)
77        temp_conf_export=$(conf_tmp_file)
78        ;;
79    module|recipe)
80        temp_conf_export=$(conf_tmp_dir)
81        ;;
82    *)
83        echo "Unsupported export style: ${CONF_EXPORT_STYLE}" >&2
84        exit 1
85        ;;
86esac
87
88if [ -z "${temp_conf_export}" ] ; then
89    echo "Could not create tempfile. Exiting." >&2
90    exit 1
91fi
92
93if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then
94    WORK_PATH=$(conf_tmp_dir)
95    conf_debug "Using temporary export working copy at ${WORK_PATH}"
96else
97    WORK_PATH="${CONF_EXPORT_WORK_PATH}"
98    conf_debug "Using persistent export working copy at ${WORK_PATH}"
99fi
100
101conf_checkout_tree
102
103repo_export="${CONF_EXPORT_STYLE}:$(conf_revision_svn)"
104sys_export="$(conf_export_sysrev)"
105
106conf_debug "repo_export: ${repo_export}"
107conf_debug "sys_export: ${sys_export}"
108
109if [ "${sys_export}" = "${repo_export}" ]; then
110    if ! ${FORCE}; then
111        echo "System is up to date." | conf_logger
112        conf_cleanExit 0
113    fi
114fi
115
116repo_method=$(echo ${repo_export} | cut -d ':' -f 1)
117sys_method=$(echo ${sys_export} | cut -d ':' -f 1)
118repo_revision=$(echo ${repo_export} | cut -d ':' -f 2)
119sys_revision=$(echo ${sys_export} | cut -d ':' -f 2)
120
121if [ "${sys_method}" != "${repo_method}" ]; then
122    echo "Export style change detected: ${sys_method} -> ${repo_method}"
123    if ${CONF_EXPORT_INCREMENTAL}; then
124        echo "Ignoring CONF_EXPORT_INCREMENTAL during export style change"
125        CONF_EXPORT_INCREMENTAL="false"
126    fi
127fi
128
129if [ "${sys_revision}" -gt "${repo_revision}" ]; then
130    echo "Error: The last export was newer than the current repository.  Exiting without making changes." >&2
131    conf_cleanExit 1
132fi
133
134if ! conf_export "${temp_conf_export}" "${sys_revision}" "${repo_revision}"; then
135    echo "Error: The export failed. Exiting." >&2
136    rm -rf "${temp_conf_export}"
137    conf_cleanExit 1
138fi
139
140# Prepare the new export
141chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} "${temp_conf_export}" || exit 1
142chmod -R ${CONF_EXPORT_MODE} "${temp_conf_export}" || exit 1
143
144# Switch to the new export
145old_conf_export=$(conf_tmp_dir)
146if [ -e "${CONF_EXPORT_FILE}" ]; then
147    mv "${CONF_EXPORT_FILE}" "${old_conf_export}" || exit 1
148fi
149mv "${temp_conf_export}" "${CONF_EXPORT_FILE}"
150
151conf_record_export
152
153echo "Export operation finished successfully" | conf_logger
154
155confexport_unlock_system
156
157# Remove the old export
158rm -rf "${old_conf_export}"
159
160# If CONF_EXPORT_WORK_PATH is not set, we were using a temporary
161# directory, so clean it up
162if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then
163    rm -rf "${WORK_PATH}"
164fi
165
166conf_cleanExit 0
Note: See TracBrowser for help on using the repository browser.