Mercurial > ec-dotfiles
comparison setup @ 127:a7484f2c9616
Long-overdue massive reorganization.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Thu, 27 Oct 2011 16:23:23 +0700 |
parents | 9a15f3d1b5b0 |
children | 66a1d79c4161 |
comparison
equal
deleted
inserted
replaced
126:9a15f3d1b5b0 | 127:a7484f2c9616 |
---|---|
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" "${*}" |
16 } | |
17 | |
18 _tcsh() { | |
19 case "$1" in | |
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 | |
25 } | |
26 | |
27 _bash() { | |
28 case "$1" in | |
29 uninstall|install) | |
30 _rc "${1}" "bash" ".ecos_bash" | |
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 | |
35 } | |
36 | |
37 _zsh() { | |
38 case "$1" in | |
39 uninstall|install) | |
40 _rc "${1}" "zsh" ".ecos_zsh" | |
41 _init "${1}" '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' ".zshrc" | |
42 ;; | |
43 esac | |
44 } | |
45 | |
46 _rc() { | |
47 _srcfile="${rcdir}/${2}" | |
48 _dstfile="${HOME}/${3}" | |
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" | |
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 | |
67 } | |
68 | |
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 | |
24 } | 86 } |
25 | 87 |
26 linker() { | 88 linker() { |
27 echo "Creating symlink: ${1} => ~/${2}" | 89 echo "Creating symlink: ${1} => ~/${2}" |
90 [ -f "${1}" ] && rm "${PWD}/$" | |
28 ln -fs "${PWD}/${1}" "${HOME}/${2}" | 91 ln -fs "${PWD}/${1}" "${HOME}/${2}" |
29 } | 92 } |
30 | 93 |
31 uninstall_init() { | 94 _uninstall_init() { |
32 script="${1}" | 95 script="${1}" |
33 scripttmp="${1}.new.tmp" | 96 scripttmp="${1}.new.tmp" |
34 hashdata="${2}" | 97 hashdata="${2}" |
35 if [ -f "${script}" ]; then | 98 if [ -f "${script}" ]; then |
36 grep -v "${hashdata}" "${script}" > "${scripttmp}" | 99 grep -v "${hashdata}" "${script}" > "${scripttmp}" |
37 mv "${scripttmp}" "${script}" | 100 mv "${scripttmp}" "${script}" |
38 fi | 101 fi |
39 } | 102 } |
40 | 103 |
41 uninstall() { | 104 _help() { |
42 for i in .ecos_tcsh .tmux.conf .hgrc .vimrc .inputrc bin-ec .ecos.bin .ecos_bin .ecos_bash .ecos_zsh; do | |
43 if [ -e "${HOME}/${i}" ]; then | |
44 echo "Removing file: ~/${i}" | |
45 rm -f "${HOME}/${i}" | |
46 fi | |
47 done | |
48 uninstall_init "${HOME}/.cshrc" "#ECCORE_TCSH" | |
49 uninstall_init "${HOME}/.bashrc" "#ECCORE_BASH" | |
50 uninstall_init "${HOME}/.bash_profile" "#ECCORE_BASH" | |
51 uninstall_init "${HOME}/.zshrc" "#ECCORE_ZSH" | |
52 } | |
53 | |
54 update() { | |
55 if [ -f "${HOME}/.tcsh_exec" ]; then | |
56 mv -f "${HOME}/.tcsh_exec" "${HOME}/.ecos_tcsh.after" | |
57 echo "Moved: ${HOME}/.tcsh_exec => ${HOME}/.ecos_tcsh.after" | |
58 fi | |
59 } | |
60 | |
61 help() { | |
62 cat <<EOF | 105 cat <<EOF |
63 Usage: ${0} [install|uninstall] | 106 Usage: ${0} [install|uninstall] |
64 EOF | 107 EOF |
65 } | 108 } |
66 | 109 |
67 case "$1" in | 110 case "${1}" in |
68 install) | 111 install|uninstall) |
69 install | 112 for i in tcsh bash zsh; do |
70 ;; | 113 _"${i}" "${1}" |
71 uninstall) | 114 done |
72 uninstall | 115 _rc "${1}" "tmux" ".tmux.conf" |
73 ;; | 116 _rc "${1}" "hg" ".hgrc" |
74 update) | 117 _rc "${1}" "vim" ".vimrc" |
75 update | 118 _rc "${1}" "inputrc" ".inputrc" |
119 _rc "${1}" "bin" ".ecos_bin" | |
76 ;; | 120 ;; |
77 *) | 121 *) |
78 help | 122 _help |
79 ;; | 123 ;; |
80 esac | 124 esac |