view setup @ 126:9a15f3d1b5b0

Incorrect test - should test for any existence instead of file.
author Edho Prima Arief <edho@myconan.net>
date Wed, 26 Oct 2011 16:54:25 +0700
parents 7c01fc6f7460
children a7484f2c9616
line wrap: on
line source

#!/bin/sh

install() {
  uninstall
  #create symlinks
  linker "tcsh" ".ecos_tcsh"
  linker "bash" ".ecos_bash"
  linker "zsh" ".ecos_zsh"
  linker "tmux" ".tmux.conf"
  linker "hg" ".hgrc"
  linker "vim" ".vimrc"
  linker "inputrc" ".inputrc"
  #originally bin-ec. Renamed to .ecos.bin for sanity when listing home
  #and replaced . with _ for more sanity
  linker "bin" ".ecos_bin"

  #modify cshrc
  echo '[ -r "${HOME}/.ecos_tcsh" ] && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' >> "${HOME}/.cshrc"
  #modify bash_profile and bashrc
  echo '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' >> "${HOME}/.bash_profile"
  echo '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' >> "${HOME}/.bashrc"
  #modify zshrc
  echo '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' >> "${HOME}/.zshrc"
}

linker() {
  echo "Creating symlink: ${1} => ~/${2}"
  ln -fs "${PWD}/${1}" "${HOME}/${2}"
}

uninstall_init() {
  script="${1}"
  scripttmp="${1}.new.tmp"
  hashdata="${2}"
  if [ -f "${script}" ]; then
    grep -v "${hashdata}" "${script}" > "${scripttmp}"
    mv "${scripttmp}" "${script}"
  fi
}

uninstall() {
  for i in .ecos_tcsh .tmux.conf .hgrc .vimrc .inputrc bin-ec .ecos.bin .ecos_bin .ecos_bash .ecos_zsh; do
    if [ -e "${HOME}/${i}" ]; then
      echo "Removing file: ~/${i}"
      rm -f "${HOME}/${i}"
    fi
  done
  uninstall_init "${HOME}/.cshrc" "#ECCORE_TCSH"
  uninstall_init "${HOME}/.bashrc" "#ECCORE_BASH"
  uninstall_init "${HOME}/.bash_profile" "#ECCORE_BASH"
  uninstall_init "${HOME}/.zshrc" "#ECCORE_ZSH"
}

update() {
  if [ -f "${HOME}/.tcsh_exec" ]; then
    mv -f "${HOME}/.tcsh_exec" "${HOME}/.ecos_tcsh.after"
    echo "Moved: ${HOME}/.tcsh_exec => ${HOME}/.ecos_tcsh.after"
  fi
}

help() {
  cat <<EOF
Usage: ${0} [install|uninstall]
EOF
}

case "$1" in
  install)
    install
  ;;
  uninstall)
    uninstall
  ;;
  update)
    update
  ;;
  *)
    help
  ;;
esac