]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - setup.sh
*: License under GPL v3+.
[config/dotfiles.git] / setup.sh
index 50df24d8ccc5223a5adb6f80b58f6641cc7abc86..d982e56e58d7e0cddafd60b481573b4e5eca24a1 100755 (executable)
--- a/setup.sh
+++ b/setup.sh
@@ -3,90 +3,30 @@
 # Runs setup.sh in all configuration directories. Must be run in the main
 # configuration directory.
 
-
-# Creates a new git repository in $1, adds a new remote named $2 and fetches
-# the master on $3. If the git repository already exists a new remote $2 for
-# $3 is added. If the remote already exists nothing happens.
-git_remote_init_update() {
-    # Make sure the requested directory exists.
-    mkdir -p "$1"
-    # Go to the target directory.
-    pwd=`pwd`
-    cd "$1"
-
-    # Create the git repository if it doesn't exist yet.
-    new=no
-    if [ ! -d .git ]; then
-        echo "Creating new git repository in '$1'."
-        git init > /dev/null
-        new=yes
-    fi
-
-    # If the remote doesn't exist add it and fetch from remote.
-    git remote | grep "$2" > /dev/null
-    if [ "$?" -ne "0" ]; then
-        echo "Adding remote '$2' to '$1'."
-        git remote add -t master "$2" "$3/$1"
-        git fetch "$2" > /dev/null
-        # Remove the remote and abort if the fetch was unsuccessful.
-        if [ "$?" -ne "0" ]; then
-            git remote rm "$2"
-            exit 1
-        fi
-
-        # Pushing to the remote pushes only the master branch in remotes named
-        # the hostname of this machine. This makes it easy to see where
-        # changes came from.
-        echo " push = +refs/heads/master:refs/remotes/`hostname`/master" \
-            >> .git/config
-    else
-        echo "Remote '$2' already exists in '$1'."
-    fi
-
-    # Merge with remote master if the repository was just created, otherwise
-    # the repository starts empty. Also run gc to compress the new repository.
-    if [ $new = yes ]; then
-        git merge "$2/master"
-        git gc > /dev/null
-    fi
-
-    # Go back to the starting directory.
-    cd "$pwd"
-    unset pwd
-}
-
-# Run setup.sh in each project.
-if [ "$#" -eq "0" ]; then
-    for project in `find . -name .git -type d`; do
-        # Skip this directory to prevent an infinite loop.
-        [ "$project" = "./.git" ] && continue
-
-        [ -d "$project" ] && (echo "running setup.sh in '$project'";
-                            cd "$project/.."; ./setup.sh > /dev/null)
-    done
-# Create git repository if necessary and/or additional remotes and fetch them.
-elif [ "$#" -ge "2" ]; then
-    # Get name of the remote and the remote location.
-    name="$1"
-    remote="$2"
-    # Remove $1 and $2 to get the possible subdirectories in $@.
-    shift
-    shift
-
-    # Create the git repository if necessary and add the remotes.
-    git_remote_init_update . "$name" "$remote"
-    for project in $@; do
-        git_remote_init_update "$project" "$name" "$remote"
-    done
-# Usage message.
-else
-    echo "Usage: ./setup.sh <remote-name> <git-repository> [subdirectories]*
-
-Example:
-./setup.sh nightwish ssh://user@nightwish/home/user/dotfiles shell vcs
-
-This will add the remote nightwish given by the ssh URL and fetch the master
-for dotfiles, dotfiles/shell and dotfiles/vcs if they don't exist already. If
-the remotes exist already nothing happens. This also sets up fetching/pushing
-settings so only the master is fetched and pushed."
-fi
+# Copyright (C) 2009-2013  Simon Ruderich
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+for path in `find . -name setup.sh -type f`; do
+    # Skip this directory to prevent an infinite loop.
+    [ "$path" = "./setup.sh" ] && continue
+    # Skip non executable setup.sh files as an easy way to deactivate one.
+    [ ! -x "$path" ] && continue
+
+    project=`echo "$path" | sed 's|/setup.sh$||'`
+
+    echo "running setup.sh in '$project'"
+    ( cd "$project"; ./setup.sh > /dev/null )
+done