Added update.sh and some small adjustments in _bashrc.
authorW. Trevor King <wking@drexel.edu>
Wed, 26 Nov 2008 18:08:39 +0000 (13:08 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 26 Nov 2008 18:12:47 +0000 (13:12 -0500)
_bashrc
update.sh [new file with mode: 0755]

diff --git a/_bashrc b/_bashrc
index d993c947180379ead1bdfd7daf46adc5c93c5219..200b2010f991b8cda0990e0342dadedec146d7cc 100644 (file)
--- a/_bashrc
+++ b/_bashrc
@@ -168,12 +168,17 @@ fi
 
 # If we don't have checked out copies of our dotfiles, get them
 if [ ! -d ~/.dotfiles/ ]; then
+    http="http://einstein.physics.drexel.edu/~wking/code/git/dotfiles.git"
+    ssh="http://einstein.physics.drexel.edu/~wking/code/git/dotfiles.git"
+    tgz="http://einstein.physics.drexel.edu/~wking/code/tar/dotfiles.tgz"
     if [ $GIT_INSTALLED == "true" ]; then
-        git clone http://einstein.physics.drexel.edu/~wking/code/git/dotfiles.git ~/.dotfiles
+        git clone $http ~/.dotfiles
+        # setup to use ssh by default.
+        sed -i "s/$http/$ssh/" ~/.dotfiles/.git/config
     else
         # fallback on wgetting the tarball
         pushd ~
-       wget http://einstein.physics.drexel.edu/~wking/code/tar/dotfiles.tgz
+       wget --output-document dotfiles.tgz $tgz
        tar -xzvf dotfiles.tgz
        rm -rf dotfiles.tgz
        popd
diff --git a/update.sh b/update.sh
new file mode 100755 (executable)
index 0000000..6bf4855
--- /dev/null
+++ b/update.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Get the current dotfiles from the server using a variety of methods.
+#
+# In order of decreasing preference:
+#   if we have git installed
+#     git over ssh, if there is an ssh agent running
+#     git over http
+#   otherwise
+#     wget a tarball
+
+# The default ssh url is stored in .git/config, so we don't need it here
+http="http://einstein.physics.drexel.edu/~wking/code/git/dotfiles.git"
+tgz="http://einstein.physics.drexel.edu/~wking/code/tar/dotfiles.tgz"
+
+
+# Check for Git (versioning system) so we know how to get our .dotfiles
+if [ -d .git ];then
+   GIT_INSTALLED="true"
+else
+   GIT_INSTALLED="false"
+fi
+
+# Check for a SSH agent
+if [ -n "$SS_AUTH_SOCK" ] && [ -n "$SSH_AGENT_PID" ]; then
+   SSH_AGENT="true"
+else
+   SSH_AGENT="false"
+fi
+
+if [ $GIT_INSTALLED == "true" ]; then
+    if [ $SSH_AGENT == "true" ]; then
+       git pull || exit 1
+    else
+       git pull $http master || exit 1
+    fi
+else
+    # fallback on wgetting the tarball
+    pushd ~
+    wget --output-document dotfiles.tgz $tgz || exit 1
+    tar -xzvf dotfiles.tgz || exit 1
+    rm -rf dotfiles.tgz || exit 1
+    popd
+fi