#!/bin/sh -e

if [ $# -ne 2 ]; then
	printf 'Usage: %s <path to gear repo> <package name>\n' "$0"
	exit 1
fi

GEAR_REPO_PATH="$1"
PACKAGE_NAME="$2"

printf 'Processing %s\n' "$PACKAGE_NAME"

cd "$GEAR_REPO_PATH"

if [ -f '.gear-rules' ]; then
	echo "File .gear-rules found, try to rename it"
	if [ ! -f '.gear/rules' ]; then
		mkdir .gear
		git mv .gear-rules .gear/rules
		git commit -a -m 'Renamed .gear-rules to .gear/rules'
	else
		echo 'File .gear/rules already exists! Skipped.'
	fi
fi
