- Timestamp:
- 08/12/2011 19:39:18 (9 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
confexport.in (modified) (4 diffs)
-
confmanlib.sh.in (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/confexport.in
r515 r522 29 29 # This script prepares an "export" of the confman repository for system 30 30 # processes to be able to pull. It is intended to be prepared regularly 31 # by a cron. It may be useful to modify this script to only prepare 32 # the export if the repository's most recent commit post-dates the 33 # tarball. 31 # by an automated process like cron. 34 32 35 33 if [ -r @pkgdatadir@/confmancommon.sh ] ; then … … 41 39 42 40 # This changes the behavior of some library functions (e.g. URIs, locks) 43 CONF_EXPORT= "true"41 CONF_EXPORT=true 44 42 45 43 function print_help { 46 echo "usage: $0 [- d]" >&444 echo "usage: $0 [-f] [-d]" >&4 47 45 echo "Type '$0 -h' to display this help and exit." >&4 48 46 conf_cleanExit ${1:-0} 49 47 } 50 48 51 while getopts "dh" OPT 2>&4 ; do 49 FORCE=false 50 DEBUG=false 51 52 while getopts "fdh" OPT 2>&4 ; do 52 53 case "$OPT" in 54 f) FORCE=true ;; 53 55 d) DEBUG=true ;; 54 56 h) print_help 0;; … … 64 66 exec 1>/dev/null 65 67 fi 68 69 echo "Export operation started" | conf_logger 66 70 67 71 confexport_lock_system … … 82 86 esac 83 87 84 if [ -z "$ temp_conf_export" ] ; then88 if [ -z "${temp_conf_export}" ] ; then 85 89 echo "Could not create tempfile. Exiting." >&2 86 90 exit 1 87 91 fi 88 92 89 echo "Beginning export operation." | conf_logger 90 if ! conf_export $temp_conf_export ; then 91 echo "The export failed. Exiting." >&2 92 rm -rf $temp_conf_export 93 exit 1 93 if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 94 WORK_PATH=$(conf_tmp_dir) 95 conf_debug "Using temporary export working copy at ${WORK_PATH}" 94 96 else 95 # Prepare the new export 96 chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} $temp_conf_export 97 chmod -R ${CONF_EXPORT_MODE} $temp_conf_export 98 # Switch to the new export 99 old_conf_export=$(conf_tmp_dir) 100 mv ${CONF_EXPORT_FILE} $old_conf_export 101 mv $temp_conf_export ${CONF_EXPORT_FILE} 102 # Remove the old export 103 rm -rf $old_conf_export 97 WORK_PATH="${CONF_EXPORT_WORK_PATH}" 98 conf_debug "Using persistent export working copy at ${WORK_PATH}" 104 99 fi 100 101 conf_checkout_tree 102 103 export_revision=$(conf_revision) 104 sys_revision=$(conf_export_sysrev) 105 106 conf_debug "export_revision is ${export_revision}" 107 conf_debug "sys_revision is ${sys_revision}" 108 109 if [ "${sys_revision}" -gt "${export_revision}" ]; then 110 echo "Error: The last export was newer than the current repository. Exiting without making changes." >&2 111 conf_cleanExit 1 112 elif [ "${sys_revision}" -eq "${export_revision}" ]; then 113 if ! ${FORCE}; then 114 echo "System is up to date." | conf_logger 115 conf_cleanExit 0 116 fi 117 fi 118 119 if ! conf_export "${temp_conf_export}"; then 120 echo "Error: The export failed. Exiting." >&2 121 rm -rf "${temp_conf_export}" 122 conf_cleanExit 1 123 fi 124 125 # Prepare the new export 126 chown -R ${CONF_EXPORT_USER}:${CONF_EXPORT_GROUP} "${temp_conf_export}" || exit 1 127 chmod -R ${CONF_EXPORT_MODE} "${temp_conf_export}" || exit 1 128 129 # Switch to the new export 130 old_conf_export=$(conf_tmp_dir) 131 mv "${CONF_EXPORT_FILE}" "${old_conf_export}" || exit 1 132 mv "${temp_conf_export}" "${CONF_EXPORT_FILE}" 133 134 conf_record_export 135 136 echo "Export operation finished successfully" | conf_logger 105 137 106 138 confexport_unlock_system "${system_lock}" 107 139 108 echo "Export complete." | conf_logger 140 # Remove the old export 141 rm -rf "${old_conf_export}" 142 143 # If CONF_EXPORT_WORK_PATH is not set, we were using a temporary 144 # directory, so clean it up 145 if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 146 rm -rf "${WORK_PATH}" 147 fi 109 148 110 149 conf_cleanExit 0 -
trunk/confmanlib.sh.in
r519 r522 28 28 29 29 REPO_ACTION="${REPO_DB}/last_action" 30 EXPORT_REV_FILE="${REPO_DB}/last_export" 30 31 REPO_SYNC_STATE="${REPO_DB}/state" 31 32 RECIPE_NAME="$(cat "$RECIPE_FILE" 2>/dev/null)" … … 402 403 local exportpath="$1" 403 404 local modules 404 405 if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then 406 WORK_PATH=$(conf_tmp_dir) 407 else 408 WORK_PATH="${CONF_EXPORT_WORK_PATH}" 409 fi 410 411 conf_checkout_tree 405 local module 406 local recipefile 407 local recipe 412 408 413 409 case ${CONF_EXPORT_STYLE} in … … 423 419 recipe) 424 420 for recipefile in $(conf_recipe_dir)/*; do 425 modules="meta $(conf_get_recipe $recipefile)" 426 tar -hczf "$exportpath/${recipefile#$(conf_recipe_dir)/}.tgz" -C "${WORK_PATH}" $modules 421 recipe=${recipefile#$(conf_recipe_dir)/} 422 modules=$(conf_get_recipe ${recipefile}) 423 tar -hczf "${exportpath}/${recipe}.tgz" -C "${WORK_PATH}" "${recipefile}" ${modules} 427 424 done 428 425 ;; … … 433 430 esac 434 431 435 if [ -z "${CONF_EXPORT_WORK_PATH}" ]; then436 rm -rf ${WORK_PATH}437 fi438 439 432 return 0 440 433 } … … 1023 1016 } 1024 1017 1018 # Returns the revision of the last export operation on stdout 1019 function conf_export_sysrev { 1020 local export_sysrev 1021 local rv 1022 1023 export_sysrev=0 1024 rv=0 1025 1026 if [ -f "${EXPORT_REV_FILE}" ]; then 1027 if ! export_sysrev=$(cat "${EXPORT_REV_FILE}"); then 1028 echo "Could not read file: ${EXPORT_REV_FILE}" >&2 1029 export_sysrev=0 1030 rv=1 1031 fi 1032 fi 1033 1034 echo ${export_sysrev} 1035 return ${rv} 1036 } 1037 1025 1038 # Returns the last action of the repository on stdout 1026 1039 function conf_lastact { … … 1037 1050 local revision=`conf_revision` 1038 1051 $SUDO sh -c "echo '${action}:${revision}' > $REPO_ACTION" 1052 } 1053 1054 # Records the export operation 1055 function conf_record_export { 1056 local revision=$(conf_revision) 1057 1058 if ! echo "${revision}" > "${EXPORT_REV_FILE}"; then 1059 echo "Could not record export to file: ${EXPORT_REV_FILE}" >&2 1060 return 1 1061 fi 1039 1062 } 1040 1063
Note: See TracChangeset
for help on using the changeset viewer.
