#!/bin/sh # forked from: https://github.com/rexim/dotfiles/blob/master/deploy.sh SCRIPT_DIR="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd )" MANIFEST_FILE="MANIFEST" symlink_file() { filename="$SCRIPT_DIR/$1" destination=$(echo "$HOME/$2/$1" | sed 's/\/\//\//g') mkdir -p $(dirname "$destination") if [ -L "$destination" ]; then echo "info: updating $filename symlink" rm -f "$destination" > /dev/null ln -s "$filename" "$destination" else if [ -e "$destination" ]; then echo "error: $destination exists but it's not a symlink. Please fix that manually" && return else ln -s "$filename" "$destination" echo "info: $filename -> $destination" fi fi } deploy_manifest() { echo "--- deploying ---" for row in $(cat "$SCRIPT_DIR/$MANIFEST_FILE"); do filename=$(echo $row | cut -d \| -f 1) destination=$(echo $row | cut -d \| -f 2) symlink_file $filename $destination done } clean() { echo "--- cleaning up ---" for row in $(cat "$SCRIPT_DIR/$MANIFEST_FILE"); do filename=$(echo $row | cut -d \| -f 1) destination=$(echo $row | cut -d \| -f 2) result=$(echo "$HOME/$destination/$filename" | sed 's/\/\//\//g') rm -f "$result" > /dev/null echo "info: removed $result symlink" done } [ "$1" = "clean" ] && clean && exit deploy_manifest