#!/bin/bash # # The infection. # # Parameters BASENAME="`basename $0`" EXCLUDES="--exclude=local --exclude=stowpkg/tree" DATE="`date +%Y%m%d%I%M%S`" BACKUPS="$HOME/.backups/$DATE" ACTION="$1" # Make sure we're running git directly and not any existing wrapper GIT="/usr/bin/git" # Usage function infection_usage { echo "usage: $BASENAME [options]" exit 1 } # Initialize function infection_init { # Set dir and base names depending on the way the program was called (symlink or direct) if [ "$(cd `dirname $0` &> /dev/null && basename `pwd`)" == "inception" ]; then DIRNAME="$(cd `dirname $0`/.. &> /dev/null && pwd)" else DIRNAME="$(cd `dirname $0` &> /dev/null && pwd)" fi SHORTNAME="$(echo $DIRNAME | sed -e "s|$HOME/||")" ( # Check if we were called correctly. Program should be called # from the toplevel repository symlink and not from it's own # repository #if [ ! -d "$DIRNAME/inception" ]; then # echo "Please call me using $DIRNAME/infection" # exit 1 #fi # Check if repo is inside $HOME if [ "$DIRNAME" != "$HOME/$SHORTNAME" ]; then echo "Please make sure $DIRNAME is moved to $HOME" exit 1 fi cd $DIRNAME &> /dev/null if [ "$ACTION" == "fetch" ] && [ "$ACTION" == "merge" ]; then echo "Initializing submodules..." $GIT submodule sync --recursive $GIT submodule update --init --recursive #--recommend-shallow fi # Convert to new dotfiles layout # # This way we can easily check the integrity of our dotfiles # once the integrity of the repo is checked if [ -e "$DIRNAME/dotfiles" ]; then if [ -e "$HOME/.dotfiles" ]; then if [ ! -h "$HOME/.dotfiles" ] || [ "`readlink $HOME/.dotfiles`" != "$SHORTNAME/dotfiles" ]; then mkdir -p $BACKUPS mv $HOME/.dotfiles $BACKUPS/ ( cd $HOME &> /dev/null && ln -s $SHORTNAME/dotfiles .dotfiles ) fi else ( cd $HOME &> /dev/null && ln -s $SHORTNAME/dotfiles .dotfiles ) fi fi #if [ ! -e "$HOME/.dotfiles" ]; then # echo "Cloning default dotfiles..." # ./metadot/metadot clone default #else # echo "Updating dotfiles..." # ./metadot/metadot fetch #fi #echo "Checking latest tag..." #cd $HOME/.dotfiles #$DIRNAME/utils-git/git-check-tag #echo "Checking out the latest tag..." #$DIRNAME/utils-git/git-checkout-tag #echo "Checking dotfiles..." #$DIRNAME/metadot/metadot version ) #echo "" #echo "Please manually verify dotfiles version and tag from the above output." #echo "If everything is fine, proceed running this command again with the 'load' parameter." #cd - } # Load function infection_load { ( cd $DIRNAME &> /dev/null BUNDLE="$3" DEPENDENCIES="$4" if [ "$BUNDLE" == "--all" ]; then echo "Loading all dotfiles..." ./metadot/metadot load --all if [ "$DEPENDENCIES" == "--deps" ]; then ./metadot/metadot deps --all fi elif [ ! -z "$BUNDLE" ]; then echo "Loading $BUNDLE dotfiles..." ./metadot/metadot load-bundle $BUNDLE if [ "$DEPENDENCIES" == "--deps" ]; then ./metadot/metadot deps-bundle $BUNDLE fi fi ) echo "Done. Logout and login again to apply all changes." } # Install function infection_install { #$0 init $0 load $* } # Deploy function infection_deploy { if [ ! -z "$2" ]; then REMOTES="$*" for REMOTE in $REMOTES; do REMOTE="$2" MODULES="`$DIRNAME/metadot/metadot installed | xargs`" # Sync repo if [ -e "$HOME/$SHORTNAME" ]; then rsync -avz --delete $EXCLUDES $HOME/$SHORTNAME/ $REMOTE:$SHORTNAMR/ fi # Sync dotfiles if [ -e "$HOME/.dotfiles" ]; then rsync -avz --delete $HOME/.dotfiles/ $REMOTE:.dotfiles/ fi # Sync loaded modules ssh -T $REMOTE <