git » repo-mgmt.git » main » tree

[main] / git-set-upstream.sh

#!/bin/sh
if [ "$1" = "--help" ]; then
	echo "usage $0 [upstream-base] [remote-name]"
	exit 1
fi
SRV=${1:-"/mnt/nfs/git"}
RMT=${2:-"publish"}
echo Setting remote $RMT of every git repo to $SRV/folder/repo.git
echo Enter to continue
read dummy


asowner() {
	if [[ -O . ]]; then
		$1
	else
		su builder -c "$1"
	fi
}

doagit() {
	local g=$(basename ${2::-5})
	echo /$3/$g
	cd /$3/$g
	if grep -q "remote \"$RMT\"" .git/config; then
		local CMD="git remote set-url $RMT $SRV/$1/$g.git"
		asowner "$CMD"
		return 0
	fi
	local CMD="git remote add $RMT $SRV/$1/$g.git"
	asowner "$CMD"
}

doatree() {
	cd /$1
	local GITS=$(find -mindepth 2 -maxdepth 2 -name '.git' -type d)

	for g in $GITS; do
		doagit $2 $g $1 "$3"
	done
}

doatree sources sources
for repo in core base kde5; do
	doatree sources/$repo-pkgbuilds $repo-pkgbuilds
done

#./git-arr-all.sh