summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2010-05-21 12:32:49 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2010-05-21 12:32:49 +0200
commit074a5d3bf45dc1c692295b992cf0711cfbed02bb (patch)
tree3bf1636881dd840b52b850aef64f1503f8b09df2
parentGeneric webserver upload script to be run from directory that needs to be uploaded. (diff)
downloadGitTools-074a5d3bf45dc1c692295b992cf0711cfbed02bb.tar.xz
GitTools-074a5d3bf45dc1c692295b992cf0711cfbed02bb.zip
Cleanup new project script -- use control master signaling to exit, better output.
-rwxr-xr-xNewProject.sh100
1 files changed, 74 insertions, 26 deletions
diff --git a/NewProject.sh b/NewProject.sh
index 7d6dd9d..9a09158 100755
--- a/NewProject.sh
+++ b/NewProject.sh
@@ -1,32 +1,80 @@
#!/bin/sh
-currentDir=`pwd`
-targetDir="`basename \"$currentDir\"`"
-OPTIONS="-o ControlMaster=auto -o ControlPath=./.uploadcontrolpath"
-echo '#!/bin/sh' > ./.gitsshupload
-echo -n 'exec ssh ' >> ./.gitsshupload
-echo -n "$OPTIONS " >> ./.gitsshupload
-echo '"$@"' >> ./.gitsshupload
-chmod +x ./.gitsshupload
-export GIT_SSH="./.gitsshupload"
-ssh $OPTIONS -fN git@labs.anyclip.com
-
-ssh $OPTIONS git@labs.anyclip.com "\
-cd ~;\
-mkdir \"$targetDir\";\
-cd \"$targetDir\";
-git init --bare;\
-echo \"$1\" > description;\
-mv hooks/post-update.sample hooks/post-update;\
-chmod +x hooks/post-update;"
+
+##### Configure These Vars: #####
+
+USER="git"
+HOST="labs.anyclip.com"
+
+#################################
+
+
+# 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 $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 "\
+ 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 = git@labs.anyclip.com:$targetDir
+ url = $connection:$repository
fetch = +refs/heads/*:refs/remotes/origin/*
[branch \"master\"]
remote = origin
- merge = refs/heads/master" >> .git/config
-git push --all
-ssh $OPTIONS git@labs.anyclip.com "~/updatewebinterface.sh"
+ 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."
+
+# Update cgit by calling script
+echo -n "[*] Updating cgit web interface..."
+ssh $options $connection "~/updatewebinterface.sh" || (echo "failure!"; exit 1)
+echo "success."
+
+# 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."
-fuser -ks ./.uploadcontrolpath
-rm ./.uploadcontrolpath
-rm ./.gitsshupload
+echo "Complete!"