2013-03-04 08:18:13 +01:00
|
|
|
#! /bin/sh
|
|
|
|
# $Id$
|
|
|
|
# vim:et:ft=sh:sts=2:sw=2
|
|
|
|
#
|
|
|
|
# Copyright 2008 Kate Ward. All Rights Reserved.
|
2013-03-04 08:22:27 +01:00
|
|
|
# Copyright 2013 Mario Fetka. All Rights Reserved.
|
2013-03-04 08:18:13 +01:00
|
|
|
# Released under the LGPL (GNU Lesser General Public License)
|
|
|
|
#
|
2013-03-04 08:22:27 +01:00
|
|
|
# Author: Mario Fetka <mario.fetka@gmail.com>
|
2013-03-04 08:18:13 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
# 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"
|
2013-03-04 16:31:50 +01:00
|
|
|
OPSI_WEB_ROOT=""
|
2013-03-04 08:18:13 +01:00
|
|
|
|
|
|
|
# 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'
|
2013-03-04 16:31:50 +01:00
|
|
|
DEFINE_string 'version' '' 'the version of the package' 'v'
|
|
|
|
DEFINE_string 'type' '' 'type of package' 'y'
|
2013-03-04 08:18:13 +01:00
|
|
|
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'
|
2013-03-04 16:31:50 +01:00
|
|
|
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'
|
2013-03-04 08:18:13 +01:00
|
|
|
|
|
|
|
FLAGS_HELP="USAGE: ${ARGV0} [flags]"
|
|
|
|
|
2013-03-04 08:25:01 +01:00
|
|
|
#if [ `which 7z` ] || exit
|
2013-03-04 08:18:13 +01:00
|
|
|
|
2013-03-04 16:31:50 +01:00
|
|
|
go_show()
|
2013-03-04 08:18:13 +01:00
|
|
|
{
|
2013-03-04 16:31:50 +01:00
|
|
|
local opsi_dir=$1
|
2013-03-04 08:18:13 +01:00
|
|
|
local show_name=$2
|
2013-03-04 16:31:50 +01:00
|
|
|
local show_type=$3
|
|
|
|
local show_from=$4
|
|
|
|
local show_to=$5
|
|
|
|
local show_version=""
|
|
|
|
local show_dir="/${opsi_dir}/${show_type}/${show_from}/"
|
2013-03-04 08:18:13 +01:00
|
|
|
# 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`
|
2013-03-04 16:31:50 +01:00
|
|
|
echo ""
|
2013-03-04 08:18:13 +01:00
|
|
|
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
|
2013-03-04 16:31:50 +01:00
|
|
|
. ${cfg_file}
|
2013-03-04 08:18:13 +01:00
|
|
|
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
|
2013-03-04 16:31:50 +01:00
|
|
|
. ${cfg_file_ver}
|
|
|
|
echo ${pkg_version}-$REV_CREATOR_TAG$REV_RELEASE >> ${file_list_release}
|
2013-03-04 08:18:13 +01:00
|
|
|
done
|
|
|
|
done
|
2013-03-04 17:52:36 +01:00
|
|
|
sort -V ${file_list_release} | uniq > ${file_list_final}
|
2013-03-04 16:31:50 +01:00
|
|
|
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
|
2013-03-04 16:59:58 +01:00
|
|
|
echo "./${ARGV0} --root ${OPSI_ROOT} --name ${show_name} --type ${show_type} --from ${show_from} --to ${show_to} --version ${show_version} (--purge)" >> $show_list
|
|
|
|
echo "./${ARGV0} --root ${OPSI_ROOT} --name ${show_name} --type ${show_type} --delete ${show_from} --version ${show_version} " >> $show_list
|
2013-03-04 16:31:50 +01:00
|
|
|
else
|
|
|
|
echo "no package named ${show_name}-* in this dir ${show_dir}" >> $show_list
|
|
|
|
fi
|
|
|
|
boxes -d shell $show_list
|
|
|
|
echo ""
|
|
|
|
|
2013-03-04 08:22:27 +01:00
|
|
|
rm -f ${show_list}
|
|
|
|
rm -f ${file_list}
|
|
|
|
rm -f ${file_list_final}
|
|
|
|
rm -f ${file_list_version}
|
|
|
|
rm -f ${file_list_release}
|
2013-03-04 08:18:13 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 16:31:50 +01:00
|
|
|
go_copy()
|
2013-03-04 08:18:13 +01:00
|
|
|
{
|
2013-03-04 16:31:50 +01:00
|
|
|
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
|
2013-03-04 08:18:13 +01:00
|
|
|
fi
|
2013-03-04 16:31:50 +01:00
|
|
|
ln -vf ${copy_from_dir}/${copy_name}{-,_}${copy_version}{.,-}* ${copy_to_dir}/ &>> $copy_list
|
|
|
|
boxes -d shell $copy_list
|
|
|
|
echo ""
|
2013-03-04 16:59:58 +01:00
|
|
|
|
|
|
|
rm -f ${copy_list}
|
|
|
|
}
|
|
|
|
|
|
|
|
go_delete()
|
|
|
|
{
|
|
|
|
local opsi_dir=$1
|
|
|
|
local delete_name=$2
|
|
|
|
local delete_type=$3
|
|
|
|
local delete_delete=$4
|
|
|
|
local delete_version=$5
|
|
|
|
local delete_dir="/${opsi_dir}/${delete_type}/${delete_delete}/"
|
|
|
|
local delete_list=`mktemp /tmp/opsi-administration.delete.list.XXXXXXXXXXX`
|
|
|
|
echo ""
|
|
|
|
echo "Web Root : ${delete_dir} Package Name: ${delete_name}" >> $delete_list
|
|
|
|
echo "" >> $delete_list
|
|
|
|
rm -f ${delete_dir}/${delete_name}{-,_}${delete_version}{.,-}* &>> $delete_list
|
|
|
|
boxes -d shell $delete_list
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
rm -f ${delete_list}
|
|
|
|
|
2013-03-04 16:31:50 +01:00
|
|
|
}
|
2013-03-04 08:18:13 +01:00
|
|
|
|
2013-03-04 16:31:50 +01:00
|
|
|
main()
|
|
|
|
{
|
2013-03-04 08:18:13 +01:00
|
|
|
# checks
|
2013-03-04 16:31:50 +01:00
|
|
|
# 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
|
2013-03-04 08:18:13 +01:00
|
|
|
[ -n "${FLAGS_name:-}" ] || die 'name flag missing'
|
|
|
|
|
2013-03-04 16:31:50 +01:00
|
|
|
# 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
|
2013-03-04 08:18:13 +01:00
|
|
|
fi
|
2013-03-04 16:31:50 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2013-03-04 16:59:58 +01:00
|
|
|
# check if the delete is correctly set
|
|
|
|
if [ -n "${FLAGS_delete}" ] ; then
|
|
|
|
case "${FLAGS_delete}" in
|
|
|
|
|
|
|
|
integration)
|
|
|
|
;;
|
|
|
|
testing)
|
|
|
|
;;
|
|
|
|
release)
|
|
|
|
;;
|
|
|
|
*) die "to is onyl integration testing or release"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2013-03-04 16:31:50 +01:00
|
|
|
# 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}
|
2013-03-04 16:59:58 +01:00
|
|
|
elif [ -z "${FLAGS_show}" ] && [ -n "${FLAGS_type}" ] && [ -n "${FLAGS_delete}" ] && [ -n "${FLAGS_version}" ]; then
|
|
|
|
go_delete ${OPSI_ROOT} ${FLAGS_name:-} ${FLAGS_type:-} ${FLAGS_delete:-} ${FLAGS_version:-}
|
|
|
|
else
|
|
|
|
die "read documetation for how to use"
|
2013-03-04 16:31:50 +01:00
|
|
|
fi
|
|
|
|
|
2013-03-04 08:18:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FLAGS "$@" || exit $?
|
|
|
|
[ ${FLAGS_help} -eq ${FALSE} ] || exit
|
|
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
main "$@"
|
2013-03-04 08:25:01 +01:00
|
|
|
|