aboutsummaryrefslogtreecommitdiffstats
path: root/git2redcrew.sh
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-03-15 19:29:07 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-03-15 22:12:49 +0100
commitf6a4ab6cf64b5a77686f5b4dbbdda11f1f771b17 (patch)
tree9e4f88df7606a4399876b1d9f121136d9536a314 /git2redcrew.sh
parentb18ff3cb50569f25c334f412030972b4bf159b46 (diff)
downloadhlupak-f6a4ab6cf64b5a77686f5b4dbbdda11f1f771b17.tar.gz
Unify git2redcrew and git2private.
Also, add an option -d to store repo in a subdirectory.
Diffstat (limited to 'git2redcrew.sh')
-rwxr-xr-xgit2redcrew.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/git2redcrew.sh b/git2redcrew.sh
new file mode 100755
index 0000000..964e6e1
--- /dev/null
+++ b/git2redcrew.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+set -ue
+
+SUBDIR=""
+PRIVATE=0
+
+REMHOST="redcrew"
+
+while getopts ":d:p" opt; do
+ case $opt in
+ d)
+ SUBDIR="/${OPTARG}"
+ ;;
+ p)
+ PRIVATE=1
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG"
+ exit 1
+ ;;
+ :)
+ echo "Option -$OPTARG requires an argument."
+ exit 1
+ ;;
+ esac
+done
+
+# Shift past the last option parsed by getopts
+shift $((OPTIND-1))
+
+if [ -d .git ] ; then
+ git gc --aggressive --prune=now
+ REPO="$(basename "$(git rev-parse --show-toplevel)")"
+ cd ..
+else
+ [ -n "$1" ] || exit 1
+ REPO="$1"
+ (cd "$REPO"
+ git gc --aggressive --prune=now
+ )
+fi
+
+GITDIR="$(readlink -f "${REPO}").git"
+git clone --bare "$REPO" "${GITDIR}"
+(cd "${GITDIR}"
+ # shellcheck disable=SC3045
+ read -r -e -p "Describe the repository:" DESC
+ echo "$DESC" >description
+ touch git-daemon-export-ok
+ git config --add gitweb.owner 'Matěj Cepl <mcepl@cepl.eu>'
+ git remote rm origin || /bin/true
+)
+
+if [ $PRIVATE -eq 1 ] ; then
+ TARGET="private_git${SUBDIR}"
+ URL_BASE="${REMHOST}:${TARGET}"
+else
+ TARGET="/srv/git${SUBDIR}"
+ URL_BASE="https://git.cepl.eu/cgit${SUBDIR}"
+fi
+
+rsync -avz "${GITDIR}" "${REMHOST}:${TARGET}/"
+rm -rf "${GITDIR}"
+cd "$REPO"
+git remote add myrepo "${URL_BASE}/${REPO}"
+if [ $PRIVATE -ne 1 ] ; then
+ git remote set-url --push myrepo "${REMHOST}:${TARGET}/${REPO}.git"
+fi
+# if git remote show gitlab >/dev/null 2>&1 ; then
+# git remote remove gitlab
+# fi
+git remote update
+git push --all -u myrepo