From a045ccb81704c9533fb839be38344c424418c541 Mon Sep 17 00:00:00 2001 From: DT Netsolution GmbH Date: Mon, 6 Feb 2012 01:15:25 +0100 Subject: [PATCH] GOPSI-6: Filling up hd with old builds. Adding autopurge options --- conf/opsi-builder.cfg | 15 +++++++++++++ lib/builder-targets.sh | 51 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/conf/opsi-builder.cfg b/conf/opsi-builder.cfg index 8bd0573..be054a1 100644 --- a/conf/opsi-builder.cfg +++ b/conf/opsi-builder.cfg @@ -78,6 +78,21 @@ OPSI_REPOS_UPLOAD_SOURCE=true OPSI_REPOS_UPLOAD_BIN=false OPSI_REPOS_OPSIMANAGER_INSTALL=false +## +# Limiting instances of published version +# Valid values: true|false +OPSI_REPOS_PURGE=false + +# defines the max. instances of published versions per product +# Valid values: 0...n, 0: disable autocleanup +OPSI_REPOS_PURGE_LIMIT=3 + +# defines limits for special products +# Valid values: 0...n, 0: disable autocleanup +OPSI_REPOS_PURGE_LIMIT_productname1=2 +OPSI_REPOS_PURGE_LIMIT_productname2=6 + + ############################### # Distribution / Vendor settings ############################### diff --git a/lib/builder-targets.sh b/lib/builder-targets.sh index 87a5fdb..1f7ec31 100644 --- a/lib/builder-targets.sh +++ b/lib/builder-targets.sh @@ -17,6 +17,7 @@ builder_config() { CMD_unix2dos="`which unix2dos`" ; builder_check_error "Command 'unix2dos' not installed" CMD_identify="`which identify`" ; builder_check_error "Command 'identify' (ImageMagick) not installed" CMD_zsyncmake="`which zsyncmake`" ; builder_check_error "Command 'zsyncmake' not installed" + CMD_comm="`which comm`" ; builder_check_error "Command 'comm' not installed" # Check temp dir test -d ${TMP_DIR} @@ -62,6 +63,11 @@ builder_config() { fatal_error "unknown TYPE: $TYPE" fi + # Check, if variable is numeric + if [ ! `expr ${OPSI_REPOS_PURGE_LIMIT} + 1 2> /dev/null` ] ; then + fatal_error "OPSI_REPOS_PURGE_LIMIT must be numeric" + fi + } ##################### @@ -70,8 +76,8 @@ builder_config() { builder_prepare() { echo "builder_prepare: " # Check if the package is still build - if [ -z "$OPSI_REPOS_FORCE_UPLOAD" ] && [ -f "${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi" ] ; then - echo "Directory ${OPSI_REPOS_PRODUCT_DIR} already exists." + if [ "$OPSI_REPOS_FORCE_UPLOAD" != "true" ] && [ -f "${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi" ] ; then + echo "File ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi already exists." exit 1 fi @@ -289,8 +295,49 @@ builder_publish() { builder_check_error "Can't create zsync file" fi + # Create revision file for this + local rev_file=${OPSI_REPOS_PRODUCT_DIR}/${PN}-${VERSION}-${CREATOR_TAG}${RELEASE}.cfg + cat > $rev_file < 0 ] ; then + echo "Autopurging enabled" + local limit + eval "`echo limit=\\$\\{OPSI_REPOS_PURGE_LIMIT_${PN}\\}`" + if [ -z "$limit" ] || [ ! `expr $limit + 1 2> /dev/null` ] ; then + limit=${OPSI_REPOS_PURGE_LIMIT} + fi + echo " Purging, max. number of versions: $limit" + + # Find all revision files + local file_list=${OUTPUT_DIR}/product-file-list.txt + find ${OPSI_REPOS_BASE_DIR} -name "${PN}-${VERSION}-${CREATOR_TAG}*.cfg" -exec echo {} \; | sort > ${file_list} + for cfg_file in `tail -${limit} ${file_list} | ${CMD_comm} -13 - ${file_list}` ; do + dir_base=`dirname ${cfg_file}` + . ${cfg_file} + + product_file="${dir_base}/${REV_OPSI_REPOS_FILE_PATTERN}" + echo " Purging product version: $product_file.*" + + # Paranoid ... check the files to delete first + if [ ! -z "${dir_base}" ] && [ -d "${OPSI_REPOS_BASE_DIR}" ] ; then + rm -f ${product_file}.* ${cfg_file} + fi + + # remove directory - if it's empty + if [ $(ls -1A ${dir_base} | wc -l) -eq 0 ]; then + rmdir ${dir_base} + fi + done + fi } ###################