# 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"
+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
- # 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
+ project=`echo "$path" | sed 's|/setup.sh$||'`
- # 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 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
-# 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
+ echo "running setup.sh in '$project'"
+ ( cd "$project"; ./setup.sh > /dev/null )
+done