#!/bin/sh
P="$(basename $(realpath $(pwd)))"

if ! [ -e $P.spec ]; then
	echo "Failed basic sanity check."
	echo "This tool must be run in a directory containing the files for"
	echo "the new package - at least including a $P.spec file."
	exit 1
fi

git init
ls *.tar* &>/dev/null && abb store *.tar*
ls *.tbz* &>/dev/null && abb store *.tbz*
ls *.tgz* &>/dev/null && abb store *.tgz*
ls *.txz* &>/dev/null && abb store *.txz*
ls *.zip &>/dev/null && abb store *.zip
ls *.7z &>/dev/null && abb store *.7z
ls *.crate &>/dev/null && abb store *.crate
ls *.jar &>/dev/null && abb store *.jar
git add $P.spec
git add .abf.yml &>/dev/null || :
git add *.patch &>/dev/null || :
git add *.diff &>/dev/null || :
git add *.txt &>/dev/null || :
git add *.sh &>/dev/null || :
git add *.md &>/dev/null || :
git add *.json &>/dev/null || :
git add *.rpmlintrc &>/dev/null || :
git commit -am "Initial package"

SUMMARY="$(grep ^Summary: $P.spec |head -n1 |cut -d: -f2- |xargs echo)"

gh repo create --description "$SUMMARY" --public --push --source . OpenMandrivaAssociation/$P
abf create_empty --description "$SUMMARY" --visibility public -v $P openmandriva
# FIXME set Github organization properly in abf create_empty
abf add -p openmandriva/$P cooker/main
abf add -p openmandriva/$P rolling/main
abf build -a aarch64 -a znver1 -a x86_64 -b master --auto-publish-status default --skip-personal --no-extra-tests --update-type enhancement -p openmandriva/$P
