Mercurial > ec-dotfiles
annotate setup @ 133:fcef92b3f37f
Forgot to check whether the file actually exists.
author | Edho Prima Arief <edho@myconan.net> |
---|---|
date | Thu, 27 Oct 2011 16:31:43 +0700 |
parents | 66a1d79c4161 |
children | 719b0687d974 |
rev | line source |
---|---|
1
ddd721f10cb8
Unified installer/uninstaller.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
1 #!/bin/sh |
ddd721f10cb8
Unified installer/uninstaller.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
2 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
3 basedir="`dirname "${0}"`" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
4 cd "${basedir}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
5 basedir="`pwd`" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
6 rcdir="${basedir}/rc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
7 bindir="${basedir}/bin" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
8 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
9 test -n "${HOME}" || exit 1 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
10 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
11 _echo() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
12 _echon "${*}"; printf "\n" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
13 } |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
14 _echon() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
15 printf "%s" "${*}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
16 } |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
17 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
18 _tcsh() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
19 case "$1" in |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
20 uninstall|install) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
21 _rc "${1}" "tcsh" ".ecos_tcsh" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
22 _init "${1}" '[ -r "${HOME}/.ecos_tcsh" ] && source "${HOME}/.ecos_tcsh" #ECCORE_TCSH' ".cshrc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
23 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
24 esac |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
25 } |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
26 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
27 _bash() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
28 case "$1" in |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
29 uninstall|install) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
30 _rc "${1}" "bash" ".ecos_bash" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
31 _init "${1}" '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' ".bash_profile" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
32 _init "${1}" '[ -r "${HOME}/.ecos_bash" ] && . "${HOME}/.ecos_bash" #ECCORE_BASH' ".bashrc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
33 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
34 esac |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
35 } |
1
ddd721f10cb8
Unified installer/uninstaller.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
36 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
37 _zsh() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
38 case "$1" in |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
39 uninstall|install) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
40 _rc "${1}" "zsh" ".ecos_zsh" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
41 _init "${1}" '[ -r "${HOME}/.ecos_zsh" ] && . "${HOME}/.ecos_zsh" #ECCORE_ZSH' ".zshrc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
42 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
43 esac |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
44 } |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
45 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
46 _rc() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
47 _srcfile="${rcdir}/${2}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
48 _dstfile="${HOME}/${3}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
49 if test ! -h "${_dstfile}"; then |
133
fcef92b3f37f
Forgot to check whether the file actually exists.
Edho Prima Arief <edho@myconan.net>
parents:
128
diff
changeset
|
50 _fexist=0 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
51 if test -f "${_dstfile}"; then |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
52 cp "${_dstfile}" "${_dstfile}.bak" |
133
fcef92b3f37f
Forgot to check whether the file actually exists.
Edho Prima Arief <edho@myconan.net>
parents:
128
diff
changeset
|
53 _fexist=1 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
54 elif test -d "${_dstfile}"; then |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
55 cp -r "${_dstfile}" "${_dstfile}.bak" |
133
fcef92b3f37f
Forgot to check whether the file actually exists.
Edho Prima Arief <edho@myconan.net>
parents:
128
diff
changeset
|
56 _fexist=1 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
57 fi |
133
fcef92b3f37f
Forgot to check whether the file actually exists.
Edho Prima Arief <edho@myconan.net>
parents:
128
diff
changeset
|
58 test "${_fexist}" = 1 &&_echo "${_dstfile} backed up to ${_dstfile}.bak" |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
59 fi |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
60 rm -f "${_dstfile}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
61 case "${1}" in |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
62 install) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
63 ln -fs "${_srcfile}" "${_dstfile}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
64 _echo "Installed ${_dstfile}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
65 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
66 uninstall) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
67 _echo "Removed ${_dstfile}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
68 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
69 esac |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
70 } |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
71 |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
72 _init() { |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
73 _script="${HOME}/${3}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
74 _scripttmp="${HOME}/.tmp.${3}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
75 _data="${2}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
76 if [ -f "${_script}" ]; then |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
77 grep -v "${_data}" "${_script}" > "${_scripttmp}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
78 mv -f "${_scripttmp}" "${_script}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
79 fi |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
80 case "${1}" in |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
81 install) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
82 _echo "${_data}" >> "${_script}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
83 _echo "Added autostart to ${_script}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
84 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
85 uninstall) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
86 _echo "Removed autostart from ${_script}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
87 ;; |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
88 esac |
1
ddd721f10cb8
Unified installer/uninstaller.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
89 } |
ddd721f10cb8
Unified installer/uninstaller.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
90 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
91 _help() { |
23
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
92 cat <<EOF |
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
93 Usage: ${0} [install|uninstall] |
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
94 EOF |
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
95 } |
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
96 |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
97 case "${1}" in |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
98 install|uninstall) |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
99 for i in tcsh bash zsh; do |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
100 _"${i}" "${1}" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
101 done |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
102 _rc "${1}" "tmux" ".tmux.conf" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
103 _rc "${1}" "hg" ".hgrc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
104 _rc "${1}" "vim" ".vimrc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
105 _rc "${1}" "inputrc" ".inputrc" |
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
106 _rc "${1}" "bin" ".ecos_bin" |
26
175848778e77
Added initial upgrade support.
Edho Prima Arief <me@myconan.net>
parents:
23
diff
changeset
|
107 ;; |
23
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
108 *) |
127
a7484f2c9616
Long-overdue massive reorganization.
Edho Prima Arief <edho@myconan.net>
parents:
126
diff
changeset
|
109 _help |
23
738a2da8b79c
Added usage information for setup script.
Edho Prima Arief <me@myconan.net>
parents:
17
diff
changeset
|
110 ;; |
1
ddd721f10cb8
Unified installer/uninstaller.
Edho Prima Arief <me@myconan.net>
parents:
diff
changeset
|
111 esac |