#!/bin/sh

if [ "$1" = "-h" ]; then
	echo "./mkpkg -h: Print this help."
	echo "./mkpkg -b: Build only, no repo action."
	echo "./mkpkg -p: Upload to archive after build."
	echo "./mkpkg -u: Upload to archive only, without local repo action and build."
fi

ver="$(grep -m1 ^linuxmuster-mail debian/changelog | awk -F\( '{ print $2 }' | awk -F\) '{ print $1 }')"

if [ "$1" != "-u" ]; then
	buildpackage.sh || exit 1
fi

[ "$1" = "-b" ] && exit 0

if [ "$1" != "-u" ]; then
	rm -f ~/www/lmn7/linuxmuster-mail*
	cp ../debs/linuxmuster-mail_${ver}* ~/www/lmn7 || exit 1
	repo-update.sh lmn7 || exit 1
fi

if [ "$1" = "-p" -o "$1" = "-u" ]; then
	ssh lmnarc rm -f lmn7/linuxmuster-mail*
	scp ../debs/linuxmuster-mail_${ver}* lmnarc:lmn7
	ssh -t lmnarc mini-dinstall -b
fi
