File modified: bin/setup.sh
Change308 at Sun May 23 18:26:01 2010 +0200 by Ivan Kanis <ivan@mac.foo>
diff -r 02353f89da79 -r e68e61a7f137 bin/setup.sh --- a/bin/setup.sh Sun May 23 17:45:23 2010 +0200 +++ b/bin/setup.sh Sun May 23 18:26:01 2010 +0200 @@ -1,3 +1,55 @@ +PORTABLE_DIR=/media/Iomega_HDD/keep/ + +check () { + error=${?} + msg=${1} + if test "X${error}" != "X0" + then + printf "${msg}.\n" + exit 1 + fi +} + +make_dir () { + dir=${1} + if test ! -d ${dir} + then + mkdir -p ${dir} + check "Failed creating directory ${dir}" + fi +} + +make_link () { + source=${1} + target=${2} + if test -e ${source} -a -d `dirname ${source}` + then + if test -d ${target} + then + rm -r ${target} + check "Failed to remove directory ${target}" + fi + if test -e ${target} + then + rm ${target} + check "Failed to remove file ${target}" + fi + ln -s ${source} ${target} + check "Failed to create link from ${source} to ${target}" + fi +} + +function user_setup () { + make_dir ${HOME}/tmp + make_dir ${HOME}/local + make_link ${HOME}/hg/conf/bashrc ${HOME}/.bash_profile + make_link ${HOME}/hg/lisp/emacs.d ${HOME}/.emacs.d + make_link ${HOME}/hg/conf/Xresources ${HOME}/.Xresources + make_link ${HOME}/hg/conf/vimrc ${HOME}/.vimrc + make_link ${PORTABLE_DIR}/.aspell.en.pws ${HOME}/.aspell.en.pws + make_link ${PORTABLE_DIR}/.aspell.fr.pws ${HOME}/.aspell.fr.pws +} + function yum_install () { yum install \ apr-devel \ @@ -116,20 +168,7 @@ xterm } -function create_symlink () -{ - ln -sf ${HOME}/hg/conf/bashrc ${HOME}/.bashrc - rm -f ${HOME}/.emacs.d - ln -sf ${HOME}/hg/lisp/emacs.d ${HOME}/.emacs.d - ln -sf ${HOME}/hg/conf/Xresources ${HOME}/.Xresources - ln -sf ${HOME}/hg/conf/vimrc ${HOME}/.vimrc - rm -f ${HOME}/.*pws - ln -s ${PORTABLE_DIR}/.aspell.en.pws ${HOME}/.aspell.en.pws - ln -s ${PORTABLE_DIR}/.aspell.fr.pws ${HOME}/.aspell.fr.pws -} - -PORTABLE_DIR=/media/Iomega_HDD/keep/ -if test X$(id -u) == X0 +if test "X`id -u`" == "X0" then which yum > /dev/null 2>&1 if test X$? == X0 @@ -142,5 +181,5 @@ apt_install fi else - create_symlink + user_setup fi