summaryrefslogtreecommitdiffstats
path: root/old/NewCGitUnixPermGitProject.sh
diff options
context:
space:
mode:
Diffstat (limited to 'old/NewCGitUnixPermGitProject.sh')
-rwxr-xr-xold/NewCGitUnixPermGitProject.sh85
1 files changed, 85 insertions, 0 deletions
diff --git a/old/NewCGitUnixPermGitProject.sh b/old/NewCGitUnixPermGitProject.sh
new file mode 100755
index 0000000..856c884
--- /dev/null
+++ b/old/NewCGitUnixPermGitProject.sh
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+##### Configure These Vars: #####
+
+USER="git"
+HOST="labs.anyclip.com"
+REPOS="/home/$USER"
+POSTCMD="$REPOS/updatewebinterface.sh"
+
+#################################
+
+
+# Check environment
+if [ "$1" == "" ]; then
+ echo "The first argument of this script must be the description of the git repository."
+ exit 1
+fi
+if [ ! -d ".git" ]; then
+ echo "The current directory is not a git repository."
+ exit 1
+fi
+
+# Initialize constants
+repository="`pwd | xargs -0 basename | tr -d ' '`"
+connection="$USER@$HOST"
+hash="`echo $REPOS $repository $connection $(date +%s%N) | md5sum | cut -d ' ' -f 1`"
+options="-o ControlMaster=auto -o ControlPath=./.sshcontrolmaster-$hash"
+gitsshpath="./.gitssh-$hash"
+
+# Create git ssh stub to use our options
+echo -n "[*] Creating git ssh wrapper script..."
+(echo '#!/bin/sh' > $gitsshpath &&
+echo -n 'exec ssh ' >> $gitsshpath &&
+echo -n "$options " >> $gitsshpath &&
+echo '"$@"' >> $gitsshpath &&
+chmod +x $gitsshpath) || { echo "failure!"; exit 1; }
+echo "success."
+export GIT_SSH="$gitsshpath"
+
+# Setup control master
+echo -n "[*] Connecting to server..."
+ssh $options -fN $connection || { echo "failure!"; exit 1; }
+echo "success."
+
+# Create bare repo on server
+echo -n "[*] Creating bare remote repository..."
+ssh $options $connection "\
+ cd \"$REPOS\" && \
+ mkdir \"$repository\" &&\
+ cd \"$repository\" &&\
+ git init --bare &&\
+ echo \"$1\" > description &&\
+ mv hooks/post-update.sample hooks/post-update &&\
+ chmod +x hooks/post-update;" > /dev/null 2>&1 || { echo "failure!"; exit 1; }
+echo "success."
+
+# Add configuration for remote repo to local repo
+echo -n "[*] Setting up local configuration..."
+echo "[remote \"origin\"]
+ url = $connection:$REPOS/$repository
+ fetch = +refs/heads/*:refs/remotes/origin/*
+[branch \"master\"]
+ remote = origin
+ merge = refs/heads/master" >> .git/config || { echo "failure!"; exit 1; }
+echo "success."
+
+# Push local repo to remote repo
+echo -n "[*] Uploading repository..."
+git push --all > /dev/null 2>&1 || { echo "failure!"; exit 1; }
+echo "success."
+
+# Run the post command if there is one
+if [ "$POSTCMD" != "" ]; then
+ echo -n "[*] Running post-command..."
+ ssh $options $connection "$POSTCMD" || { echo "failure!"; exit 1; }
+ echo "success."
+fi
+
+# Kill the ssh control master, delete gitssh wrapper
+echo -n "[*] Cleaning up..."
+ssh $options -O exit $connection 2> /dev/null || echo "\n\tClean up failed: could not kill ssh control master."
+rm $gitsshpath > /dev/null || echo "\n\tClean up failed: could not delete git ssh wrapper."
+echo "success."
+
+echo "Complete!"