Mercurial > ec-dotfiles
comparison setup @ 138:f963d52c031a
Merge.
| author | Edho Arief <edho@myconan.net> |
|---|---|
| date | Wed, 02 Nov 2011 22:12:16 +0700 |
| parents | 70928bbbd6cb |
| children | 6a110770a756 |
comparison
equal
deleted
inserted
replaced
| 137:983beb13c736 | 138:f963d52c031a |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 install() { | 3 basedir="`dirname "${0}"`" |
| 4 uninstall | 4 cd "${basedir}" |
| 5 #create symlinks | 5 basedir="`pwd`" |
| 6 linker "tcsh" ".ecos_tcsh" | 6 rcdir="${basedir}/rc" |
| 7 linker "bash" ".ecos_bash" | 7 bindir="${basedir}/bin" |
| 8 linker "zsh" ".ecos_zsh" | |
| 9 linker "tmux" ".tmux.conf" | |
| 10 linker "hg" ".hgrc" | |
| 11 linker "vim" ".vimrc" | |
| 12 linker "inputrc" ".inputrc" | |
| 13 #originally bin-ec. Renamed to .ecos.bin for sanity when listing home | |
| 14 #and replaced . with _ for more sanity | |
| 15 linker "bin" ".ecos_bin" | |
| 16 | 8 |
| 17 #modify cshrc | 9 test -n "${HOME}" || exit 1 |
| 18 echo '[ -r "${HOME}/.ecos_tcsh" ] && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' >> "${HOME}/.cshrc" | 10 |
| 19 #modify bash_profile and bashrc | 11 _echo() { |
| 20 echo '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' >> "${HOME}/.bash_profile" | 12 _echon "${*}"; printf "\n" |
| 21 echo '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' >> "${HOME}/.bashrc" | 13 } |
| 22 #modify zshrc | 14 _echon() { |
| 23 echo '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' >> "${HOME}/.zshrc" | 15 printf "%s" "${*}" |
| 24 } | 16 } |
| 25 | 17 |
| 26 linker() { | 18 _tcsh() { |
| 27 echo "Creating symlink: ${1} => ~/${2}" | 19 case "$1" in |
| 28 ln -fs "${PWD}/${1}" "${HOME}/${2}" | 20 uninstall|install) |
| 21 _rc "${1}" "tcsh" ".ecos_tcsh" | |
| 22 _init "${1}" '[ -r "${HOME}/.ecos_tcsh" ] && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' ".cshrc" | |
| 23 ;; | |
| 24 esac | |
| 29 } | 25 } |
| 30 | 26 |
| 31 uninstall_tcsh() { | 27 _bash() { |
| 32 if [ -f "${HOME}/.cshrc" ]; then | 28 case "$1" in |
| 33 grep -v '#ECCORE_TCSH' "${HOME}/.cshrc" > .cleancshrc | 29 uninstall|install) |
| 34 mv .cleancshrc "${HOME}/.cshrc" | 30 _rc "${1}" "bash" ".ecos_bash" |
| 35 fi | 31 _init "${1}" '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' ".bash_profile" |
| 32 _init "${1}" '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' ".bashrc" | |
| 33 ;; | |
| 34 esac | |
| 36 } | 35 } |
| 37 | 36 |
| 38 uninstall() { | 37 _zsh() { |
| 39 for i in .ecos_tcsh .tmux.conf .hgrc .vimrc .inputrc bin-ec .ecos.bin .ecos_bin .ecos_bash .ecos_zsh; do | 38 case "$1" in |
| 40 if [ -f "${HOME}/${i}" ]; then | 39 uninstall|install) |
| 41 echo "Removing file: ~/${i}" | 40 _rc "${1}" "zsh" ".ecos_zsh" |
| 42 rm -f "${HOME}/${i}" | 41 _init "${1}" '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' ".zshrc" |
| 43 fi | 42 ;; |
| 44 done | 43 esac |
| 45 uninstall_tcsh | |
| 46 } | 44 } |
| 47 | 45 |
| 48 update() { | 46 _rc() { |
| 49 if [ -f "${HOME}/.tcsh_exec" ]; then | 47 _srcfile="${rcdir}/${2}" |
| 50 mv -f "${HOME}/.tcsh_exec" "${HOME}/.ecos_tcsh.after" | 48 _dstfile="${HOME}/${3}" |
| 51 echo "Moved: ${HOME}/.tcsh_exec => ${HOME}/.ecos_tcsh.after" | 49 if test ! -h "${_dstfile}"; then |
| 50 if test -f "${_dstfile}"; then | |
| 51 cp "${_dstfile}" "${_dstfile}.bak" | |
| 52 elif test -d "${_dstfile}"; then | |
| 53 cp -r "${_dstfile}" "${_dstfile}.bak" | |
| 54 fi | |
| 55 _echo "${_dstfile} backed up to ${_dstfile}.bak" | |
| 52 fi | 56 fi |
| 57 rm -f "${_dstfile}" | |
| 58 case "${1}" in | |
| 59 install) | |
| 60 ln -fs "${_srcfile}" "${_dstfile}" | |
| 61 _echo "Installed ${_dstfile}" | |
| 62 ;; | |
| 63 uninstall) | |
| 64 _echo "Removed ${_dstfile}" | |
| 65 ;; | |
| 66 esac | |
| 53 } | 67 } |
| 54 | 68 |
| 55 help() { | 69 _init() { |
| 70 _script="${HOME}/${3}" | |
| 71 _scripttmp="${HOME}/.tmp.${3}" | |
| 72 _data="${2}" | |
| 73 if [ -f "${_script}" ]; then | |
| 74 grep -v "${_data}" "${_script}" > "${_scripttmp}" | |
| 75 mv -f "${_scripttmp}" "${_script}" | |
| 76 fi | |
| 77 case "${1}" in | |
| 78 install) | |
| 79 _echo "${_data}" >> "${_script}" | |
| 80 _echo "Added autostart to ${_script}" | |
| 81 ;; | |
| 82 uninstall) | |
| 83 _echo "Removed autostart from ${_script}" | |
| 84 ;; | |
| 85 esac | |
| 86 } | |
| 87 | |
| 88 _help() { | |
| 56 cat <<EOF | 89 cat <<EOF |
| 57 Usage: ${0} [install|uninstall] | 90 Usage: ${0} [install|uninstall] |
| 58 EOF | 91 EOF |
| 59 } | 92 } |
| 60 | 93 |
| 61 case "$1" in | 94 case "${1}" in |
| 62 install) | 95 install|uninstall) |
| 63 install | 96 for i in tcsh bash zsh; do |
| 64 ;; | 97 _"${i}" "${1}" |
| 65 uninstall) | 98 done |
| 66 uninstall | 99 _rc "${1}" "tmux" ".tmux.conf" |
| 67 ;; | 100 _rc "${1}" "hg" ".hgrc" |
| 68 update) | 101 _rc "${1}" "vim" ".vimrc" |
| 69 update | 102 _rc "${1}" "inputrc" ".inputrc" |
| 103 _rc "${1}" "../bin" ".ecos_bin" | |
| 70 ;; | 104 ;; |
| 71 *) | 105 *) |
| 72 help | 106 _help |
| 73 ;; | 107 ;; |
| 74 esac | 108 esac |
