]> git.phdru.name Git - git-scripts.git/commitdiff
Add `copy-scripts/`: Copy this repo to a remote host
authorOleg Broytman <phd@phdru.name>
Sat, 15 Aug 2020 13:32:04 +0000 (16:32 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 15 Aug 2020 13:34:03 +0000 (16:34 +0300)
Copy git-scripts to an ssh-accessible remote host.

copy-scripts/copy-scripts [new file with mode: 0755]
copy-scripts/post-update [moved from hooks/post-update with 73% similarity]

diff --git a/copy-scripts/copy-scripts b/copy-scripts/copy-scripts
new file mode 100755 (executable)
index 0000000..2201c0f
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# Copy git-scripts to an ssh-accessible remote host;
+# setup bare and non-bare repositories and the post-update hook.
+
+if [ $# -ne 3 ]; then
+   echo "Usage: $0 [user@]host directory remote_name" >&2
+   exit 1
+fi
+
+remote_host="$1"
+remote_dir="$2"
+remote_name="$3"
+
+ssh "$remote_host" "cd $remote_dir && exec git init --bare git-scripts.git" &&
+git remote add "$remote_name" "$remote_host:$remote_dir/git-scripts.git" &&
+git push "$remote_name" master &&
+exec ssh "$remote_host" "cd $remote_dir && git clone git-scripts.git &&
+   cd git-scripts.git/hooks &&
+   exec ln -s ../../git-scripts/copy-scripts/post-update"
similarity index 73%
rename from hooks/post-update
rename to copy-scripts/post-update
index 3350fa84c5a8511d56587b321b31daa3fed8a3fe..78fc50d4cebb3fd185eae7008fb025e74cfd92ae 100755 (executable)
@@ -6,9 +6,7 @@ for ref in "$@"; do
    if [ "$ref" = refs/heads/master ]; then
       unset GIT_DIR
       cd ../git-scripts &&
-      if ! git remote show -n origin 2>/dev/null; then
-         git remote add origin ../git-scripts.git
-      fi &&
+      git checkout master &&
       git pull origin master &&
       git push origin master
       exit