commit 6a546e5036174dd86a3d63e2117a7b63a099c7e4
parent 58ec6dfe6a7d8a7a2e817e0bbbbde4cc2bb0a531
Author: lash <dev@holbrook.no>
Date:   Sun,  9 Jan 2022 16:51:02 +0000
Add draft for git bare repo adder with metadata capability
Diffstat:
| A | bdbg.sh |  |  | 35 | +++++++++++++++++++++++++++++++++++ | 
| A | common.sh |  |  | 7 | +++++++ | 
| A | gitadd.sh |  |  | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 
3 files changed, 112 insertions(+), 0 deletions(-)
diff --git a/bdbg.sh b/bdbg.sh
@@ -0,0 +1,35 @@
+if [ -z "$_level" ]; then
+	_level=3
+fi
+
+dbg() {
+	if [ "$1" -lt "$_level" ]; then
+		return 0
+	fi
+
+	case "$1" in
+		1)
+			lvl='debug'
+			clr='\e[0;96m'
+			;;
+		2)
+			lvl='info'
+			clr='\e[0;92m'
+			;;
+
+		3)
+			lvl='warn'
+			clr='\e[0;93m'
+			;;
+		4)
+			lvl='error'
+			clr='\e[0;91m'
+			;;
+
+	esac
+
+	if [ -z $_debug ]; then
+		return 0
+	fi
+	>&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m"
+}
diff --git a/common.sh b/common.sh
@@ -0,0 +1,7 @@
+chomp_git_path() {
+	basename_raw=$(basename $1)
+	basename_chomped=${basename_raw%.git}
+	>&2 echo "checkout repo $basename_chomped ($1)"
+	basename_git=${basename_chomped}.git
+	echo -n $basename_git > $2	
+}
diff --git a/gitadd.sh b/gitadd.sh
@@ -0,0 +1,70 @@
+while test $# != 0; do
+	case "$1" in
+		-v)
+			_debug=1
+			_level=1
+			shift
+			;;
+		-d)
+			shift
+			description=$1
+			shift
+			;;
+		-o)
+			shift
+			owner=$1
+			shift
+			;;
+		*)
+			break
+			;;
+	esac
+done
+
+. bdbg.sh
+
+p=$1
+if [ -z $1 ]; then
+	dbg 4 "missing remote repo"
+	exit 1
+fi
+
+. common.sh
+
+if [ ! -z $description ]; then
+	dbg 2 "using git repo description: $description"
+fi
+
+if [ ! -z $owner ]; then
+	dbg 2 "using git repo owner: $owner"
+fi
+
+b=${GIT_BASE:-.}
+set +e
+
+t=$(mktemp)
+chomp_git_path $p $t
+read -r pc < $t
+dbg 2 "using git repo path: $b/$pc for $p"
+
+pushd $b
+git clone --bare $p $pc
+popd
+
+if [ ! -z $description ]; then
+	echo -n $description > $pc/description
+fi
+
+if [ ! -z $owner ]; then
+	grep -e "^[owner]" $pc/config
+	if [ $? -eq "0" ]; then
+		>&2 echo "owner already set in config, skip, edit manually if you really want"
+	else
+		cat <<EOF >> $pc/config
+[gitweb]
+	owner = $owner
+EOF
+	fi
+fi
+
+set -e