#! /bin/sh # $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. # Copyright 2013 Mario Fetka. All Rights Reserved. # Released under the LGPL (GNU Lesser General Public License) # # Author: Mario Fetka # # treat unset variables as an error set -u die() { [ $# -gt 0 ] && echo "error: $@" | boxes -d shell >&2 exit 1 } BASE_DIR="`dirname $0`/.." LIB_DIR="${BASE_DIR}/lib" OPSI_WEB_ROOT="" # load libraries . ${LIB_DIR}/shflags || die 'unable to load shflags library' . ${LIB_DIR}/shlib || die 'unable to load shlib library' . ${LIB_DIR}/versions || die 'unable to load versions library' # Source local build configuration (must be done AFTER sourcing the builder-product.cfg.cfg) test -f $HOME/.opsi-administration.cfg && . $HOME/.opsi-administration.cfg # define flags DEFINE_string 'name' '' 'the name of the package' 'n' DEFINE_string 'version' '' 'the version of the package' 'v' DEFINE_string 'type' '' 'type of package' 'y' DEFINE_string 'from' '' 'source level of package' 'f' DEFINE_string 'to' '' 'output file to write to' 't' DEFINE_string 'root' '' 'output file to write to' 'r' DEFINE_string 'show' '' 'show a list of the' 's' DEFINE_string 'delete' '' 'delete specific versions of the package' 'd' DEFINE_boolean 'purge' false 'delete old versions of the package' 'p' FLAGS_HELP="USAGE: ${ARGV0} [flags]" #if [ `which 7z` ] || exit go_show() { local opsi_dir=$1 local show_name=$2 local show_type=$3 local show_from=$4 local show_to=$5 local show_version="" local show_dir="/${opsi_dir}/${show_type}/${show_from}/" # Find all revision files and sort them local file_list=`mktemp /tmp/opsi-administration.show.XXXXXXXXXXX` local file_list_version=`mktemp /tmp/opsi-administration.show.version.XXXXXXXXXXX` local file_list_release=`mktemp /tmp/opsi-administration.show.release.XXXXXXXXXXX` local file_list_final=`mktemp /tmp/opsi-administration.show.final.XXXXXXXXXXX` local show_list=`mktemp /tmp/opsi-administration.show.list.XXXXXXXXXXX` echo "" echo "Web Root: ${show_dir} Package Name: ${show_name}" >> $show_list echo "" >> $show_list for cfg_file in `find ${show_dir} -name "${show_name}-*.cfg" -print ` ; do . ${cfg_file} echo $REV_VERSION >> ${file_list} done sort -V ${file_list} | uniq > ${file_list_version} for pkg_version in `cat ${file_list_version}` ; do for cfg_file_ver in ${show_dir}/${show_name}-${pkg_version}-*.cfg ; do . ${cfg_file_ver} echo ${pkg_version}-$REV_CREATOR_TAG$REV_RELEASE >> ${file_list_release} done done sort -n ${file_list_release} | uniq > ${file_list_final} for release_file_list in `cat ${file_list_final}` ; do . ${show_dir}/${show_name}-${release_file_list}.cfg echo $REV_PN-$REV_VERSION-$REV_CREATOR_TAG$REV_RELEASE >> $show_list show_version=$REV_VERSION-$REV_CREATOR_TAG$REV_RELEASE done if [ -n "${show_version}" ];then echo "./${ARGV0} --root ${OPSI_ROOT} --name ${show_name} --type ${show_type} --from ${show_from} --to ${show_to} --version ${show_version} " >> $show_list else echo "no package named ${show_name}-* in this dir ${show_dir}" >> $show_list fi boxes -d shell $show_list echo "" rm -f ${show_list} rm -f ${file_list} rm -f ${file_list_final} rm -f ${file_list_version} rm -f ${file_list_release} } go_copy() { local opsi_dir=$1 local copy_name=$2 local copy_type=$3 local copy_from=$4 local copy_to=$5 local copy_version=$6 local copy_from_dir="/${opsi_dir}/${copy_type}/${copy_from}/" local copy_to_dir="/${opsi_dir}/${copy_type}/${copy_to}/" local copy_list=`mktemp /tmp/opsi-administration.copy.list.XXXXXXXXXXX` echo "" echo "Web Root Source: ${copy_from_dir} Web Root Destination: ${copy_to_dir}" >> $copy_list echo "Package Name: ${copy_name}" >> $copy_list echo "" >> $copy_list if [ ${FLAGS_purge} -eq ${FLAGS_TRUE} ]; then rm -f ${copy_to_dir}/${copy_name}-* &>> $copy_list fi ln -vf ${copy_from_dir}/${copy_name}{-,_}${copy_version}{.,-}* ${copy_to_dir}/ &>> $copy_list boxes -d shell $copy_list echo "" } main() { # checks # check if a config file is present or the --root flag has been added if [ -n "${OPSI_WEB_ROOT}" ];then OPSI_ROOT="${OPSI_WEB_ROOT}" else if [ -n "${FLAGS_root}" ];then OPSI_ROOT=${FLAGS_root} else die 'root flag or config file mising' fi fi # the name falg is always needed [ -n "${FLAGS_name:-}" ] || die 'name flag missing' # check if the type is correctly set if [ -n "${FLAGS_type}" ] ; then case "${FLAGS_type}" in public) ;; restricted) ;; *) die "type is only public or restricted" ;; esac fi # check if the show is correctly set if [ -n "${FLAGS_show}" ] ; then case "${FLAGS_show}" in integration) ;; testing) ;; release) ;; *) die "show is onyl integration testing or release" ;; esac fi # check if the from is correctly set if [ -n "${FLAGS_from}" ] ; then case "${FLAGS_from}" in integration) ;; testing) ;; release) ;; *) die "from is onyl integration testing or release" ;; esac fi # check if the to is correctly set if [ -n "${FLAGS_to}" ] ; then case "${FLAGS_to}" in integration) ;; testing) ;; release) ;; *) die "to is onyl integration testing or release" ;; esac fi # set some local vars local show_from="" local show_to="" if [ -z "${FLAGS_from}" ] && [ -z "${FLAGS_to}" ] && [ -z "${FLAGS_type}" ] ; then go_show ${OPSI_ROOT} ${FLAGS_name:-} "public" "integration" "testing" elif [ -n "${FLAGS_show}" ] && [ -n "${FLAGS_type}" ] ; then case "${FLAGS_show}" in integration) show_from="integration" show_to="testing" ;; testing) show_from="testing" show_to="release" ;; esac go_show ${OPSI_ROOT} ${FLAGS_name:-} ${FLAGS_type:-} ${show_from} ${show_to} elif [ -z "${FLAGS_show}" ] && [ -n "${FLAGS_type}" ] && [ -n "${FLAGS_from}" ] && [ -n "${FLAGS_to}" ] && [ -n "${FLAGS_version}" ]; then go_copy ${OPSI_ROOT} ${FLAGS_name:-} ${FLAGS_type:-} ${FLAGS_from:-} ${FLAGS_to:-} ${FLAGS_version:-} ${FLAGS_purge} fi # if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} -a -f "${output}" ]; then # if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then # rm -f "${output}" # else # echo "not overwriting '${output}'" >&2 # exit ${FLAGS_ERROR} # fi # fi # if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then # touch "${output}" 2>/dev/null || die "unable to write to '${output}'" # fi # run tests # ( # cd "${SRC_DIR}"; # if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then # ./${FLAGS_suite} |tee "${output}" # else # ./${FLAGS_suite} # fi # ) # if [ ! ${FLAGS_dry_run} ]; then # echo >&2 # echo "output written to '${output}'" >&2 # fi } FLAGS "$@" || exit $? [ ${FLAGS_help} -eq ${FALSE} ] || exit eval set -- "${FLAGS_ARGV}" main "$@"