aboutsummaryrefslogtreecommitdiffstats
path: root/roles/jails/22_forge/files/git-shell-commands
diff options
context:
space:
mode:
Diffstat (limited to 'roles/jails/22_forge/files/git-shell-commands')
-rw-r--r--roles/jails/22_forge/files/git-shell-commands/help1
-rw-r--r--roles/jails/22_forge/files/git-shell-commands/mirror-from44
-rw-r--r--roles/jails/22_forge/files/git-shell-commands/mirror-to5
3 files changed, 50 insertions, 0 deletions
diff --git a/roles/jails/22_forge/files/git-shell-commands/help b/roles/jails/22_forge/files/git-shell-commands/help
index e8f2631..acd24a9 100644
--- a/roles/jails/22_forge/files/git-shell-commands/help
+++ b/roles/jails/22_forge/files/git-shell-commands/help
@@ -8,5 +8,6 @@ Available commands:
rename [OLD_NAME] [NEW_NAME] rename a repository
delete [REPO_NAME] delete a repository
mirror-to [REPO_NAME] [GIT_URL] set up hourly mirror to a remote git URL
+ mirror-from [REPO_NAME] [GIT_URL] set up hourly fetch from a remote git URL
EOF
diff --git a/roles/jails/22_forge/files/git-shell-commands/mirror-from b/roles/jails/22_forge/files/git-shell-commands/mirror-from
new file mode 100644
index 0000000..2666cac
--- /dev/null
+++ b/roles/jails/22_forge/files/git-shell-commands/mirror-from
@@ -0,0 +1,44 @@
+#!/bin/sh
+# mirror-from [REPO_NAME] [GIT_URL]
+# Configures a repo to pull updates from a remote git URL hourly.
+# Pass empty URL to remove the mirror source.
+# Example: mirror-from myrepo https://github.com/user/myrepo.git
+if [ -z "$1" ]; then
+ echo "Usage: mirror-from [REPO_NAME] [GIT_URL]"
+ echo " mirror-from [REPO_NAME] - remove mirror source"
+ exit 1
+fi
+if [ ! -d "$1.git" ]; then
+ echo "Repository $1 does not exist"
+ exit 1
+fi
+
+REPO="$1"
+REMOTE="$2"
+REPO_PATH="$HOME/$REPO.git"
+
+cd "$REPO_PATH" || exit 1
+
+if [ -z "$REMOTE" ]; then
+ if git remote get-url mirror-from >/dev/null 2>&1; then
+ git remote remove mirror-from
+ echo "Removed mirror source for $REPO"
+ else
+ echo "No mirror source configured for $REPO"
+ fi
+ exit 0
+fi
+
+if git remote get-url mirror-to >/dev/null 2>&1; then
+ echo "Error: $REPO already has a mirror-to configured. Remove it first with: mirror-to $REPO"
+ exit 1
+fi
+
+if git remote get-url mirror-from >/dev/null 2>&1; then
+ git remote set-url mirror-from "$REMOTE"
+else
+ git remote add mirror-from "$REMOTE"
+fi
+
+echo "Configured $REPO to mirror from $REMOTE"
+echo "Mirrors run hourly. Logs: /var/log/git-mirrors.log"
diff --git a/roles/jails/22_forge/files/git-shell-commands/mirror-to b/roles/jails/22_forge/files/git-shell-commands/mirror-to
index d161283..6a0c20e 100644
--- a/roles/jails/22_forge/files/git-shell-commands/mirror-to
+++ b/roles/jails/22_forge/files/git-shell-commands/mirror-to
@@ -29,6 +29,11 @@ if [ -z "$REMOTE" ]; then
exit 0
fi
+if git remote get-url mirror-from >/dev/null 2>&1; then
+ echo "Error: $REPO already has a mirror-from configured. Remove it first with: mirror-from $REPO"
+ exit 1
+fi
+
if git remote get-url mirror-to >/dev/null 2>&1; then
git remote set-url mirror-to "$REMOTE"
else