dotfiles

my active dotfiles
git clone git://git.jakekoroman.com/dotfiles
Log | Files | Refs | README

deploy.sh (1433B)


      1 #!/bin/sh
      2 
      3 # forked from: https://github.com/rexim/dotfiles/blob/master/deploy.sh
      4 
      5 SCRIPT_DIR="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd )"
      6 MANIFEST_FILE="MANIFEST"
      7 
      8 symlink_file() {
      9     filename="$SCRIPT_DIR/$1"
     10     destination=$(echo "$HOME/$2/$1" | sed 's/\/\//\//g')
     11 
     12     mkdir -p $(dirname "$destination")
     13 
     14     if [ -L "$destination" ]; then
     15         echo "info: updating $filename symlink"
     16         rm -f "$destination" > /dev/null
     17         ln -s "$filename" "$destination"
     18     else
     19         if [ -e "$destination" ]; then
     20             echo "error: $destination exists but it's not a symlink. Please fix that manually" && return
     21         else
     22             ln -s "$filename" "$destination"
     23             echo "info: $filename -> $destination"
     24         fi
     25     fi
     26 }
     27 
     28 deploy_manifest() {
     29     echo "--- deploying ---"
     30     for row in $(cat "$SCRIPT_DIR/$MANIFEST_FILE"); do
     31         filename=$(echo $row | cut -d \| -f 1)
     32         destination=$(echo $row | cut -d \| -f 2)
     33         symlink_file $filename $destination
     34     done
     35 }
     36 
     37 clean() {
     38     echo "--- cleaning up ---"
     39     for row in $(cat "$SCRIPT_DIR/$MANIFEST_FILE"); do
     40         filename=$(echo $row | cut -d \| -f 1)
     41         destination=$(echo $row | cut -d \| -f 2)
     42         result=$(echo "$HOME/$destination/$filename" | sed 's/\/\//\//g')
     43         rm -f "$result" > /dev/null
     44         echo "info: removed $result symlink"
     45     done
     46 }
     47 
     48 [ "$1" = "clean" ] && clean && exit
     49 deploy_manifest