summaryrefslogblamecommitdiff
path: root/install
blob: 7205287033e072f4cf1e6810b9fe2303ef612c91 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                 


                                         


                            



                                              
              


                                                                                    
           



















                                 



                                               
              



                                                                                     
           





                                


                                          





                               




                                             
              



                                                                                    
                                                          



                                                                                    
           














                                                             
                           



                                                     
                                                               
                                    
                                                                    





















                                                
                                                                     



                                                            
                                                                                    








                                                                         




                                                






































                                                        
#!/bin/bash
# dotfiles -- install
# author: johannst

gInstallConfigFile=install.config

#"<config_tag>:<dep_binary>:<installer_fct_name>"
gToolsConfig=(
"bashrc:bash:bashrcInstaller"
"cgdb:cgdb:cgdbrcInstaller"
"conkyrc:conky:conkyrcInstaller"
"gitconfig:git:gitConfigInstaller"
"tmux.conf:tmux:tmuxConfigInstaller"
"vimrc:vim:vimConfigInstaller"
"Xresources:xterm:xtermConfigInstaller"
)

gMagicNumber=e2718281
ABS_BASE_DIR=$(readlink -f $(dirname $0))

#{{{ bashrcInstaller

function bashrcInstaller() {
   local bashrc=~/.bashrc
   touch $bashrc
   grep $gMagicNumber $bashrc > /dev/null 2>&1
   if [[ $? = 0 ]]; then
      return 1
   fi
   echo -e "\n# $gMagicNumber - Auto generated, do not delete or modify!" >> $bashrc
   echo -e "source $ABS_BASE_DIR/bashrc" >> $bashrc
   return 0
}

#}}}
#{{{ cgdbrcInstaller

function cgdbrcInstaller() {
   echo "cgdbrcInstaller called"
}

#}}}
#{{{ conkyrcInstaller

function conkyrcInstaller() {
   echo "conkyrcInstaller called"
}

#}}}
#{{{ gitConfigInstaller

function gitConfigInstaller() {
   local gitconf=~/.gitconfig
   touch $gitconf
   grep $gMagicNumber $gitconf > /dev/null 2>&1
   if [[ $? = 0 ]]; then
      return 1
   fi
   echo -e "\n# $gMagicNumber - Auto generated, do not delete or modify!" >> $gitconf
   echo -e "[include]" >> $gitconf
   echo -e "   path = $ABS_BASE_DIR/gitconfig" >> $gitconf
   return 0
}

#}}}
#{{{ tmuxConfigInstaller 

function tmuxConfigInstaller() {
   local tmuxconf=~/.tmux.conf
   ln -s $ABS_BASE_DIR/tmux.conf $tmuxconf
   return 0
}

#}}}
#{{{ vimConfigInstaller

function vimConfigInstaller() {
   local vimrc=~/.vimrc
   local vim_home=~/.vim
   touch $vimrc
   grep $gMagicNumber $vimrc > /dev/null 2>&1
   if [[ $? = 0 ]]; then
      return 1
   fi
   mkdir $vim_home > /dev/null 2>&1
   ln -s $ABS_BASE_DIR/vim/* $vim_home
   echo -e "\n\" $gMagicNumber - Auto generated, do not delete or modify!" >> $vimrc
   echo -e "let \$MYVIMRC='$ABS_BASE_DIR/vimrc'" >> $vimrc
   echo -e "let \$VIMHOME='$vim_home'" >> $vimrc
   echo -e "source $ABS_BASE_DIR/vimrc" >> $vimrc
   git clone https://github.com/VundleVim/Vundle.vim.git $vim_home/bundle/Vundle.vim
   vim +PluginInstall +qall
   return 0
}

#}}}
#{{{ xtermConfigInstaller

function xtermConfigInstaller() {
   echo "xtermConfigInstaller called"
}

#}}}

#{{{ Installer Main Loop

function main() {
   # parse gInstallConfigFile to see what should be installed
   local configToInstall=()
   while read line; do
      if [[ ! $line =~ ^[yYnN][[:blank:]]?- ]]; then 
         continue
      fi
      local flag=$(echo $line | cut -d '-' -f 1 | sed 's/ //g')
      if [[ $flag =~ ^[yY]$ ]]; then
         local config=$(echo $line | cut -d '-' -f 2 | sed 's/ //g')
         configToInstall+=("$config")
      fi
   done < $gInstallConfigFile

   echo "[Info]: List of tags found to install:"
   for conf in ${configToInstall[@]}; do 
      echo -e "\t$conf"
   done

   for conf in ${configToInstall[@]}; do 
      installConfig $conf
   done
}

#}}}
#{{{ Installer Core

installConfig() {
   local config=$1
   local binary=$(getDepenentBinaryName $config)
   isBinaryInstalled $binary
   if [[ $? -eq 1 ]]; then 
      echo "[Warning]: Skipping $config... $binary is not installed!"
      return 
   fi
   local installerFctPtr=$(getConfigInstallerFctPtr $config)
   if [[ -z $installerFctPtr ]]; then 
      echo "[Warning]: Skipping $config... installer function pointer lookup error!"
      return
   fi
   isInstallerDefined $installerFctPtr
   if [[ $? -eq 1 ]]; then 
      echo "[Warning]: Skipping $config... $installerFctPtr not defined!"
      return
   fi
   echo "[Info]: Intalling config for $binary using $installerFctPtr!"
   $installerFctPtr
   if [[ $? -eq 1 ]]; then 
      echo "[Info]: $config already installed!"
      return
   fi
   echo "[Info]: $config sucessfully installed!"
}

getValue() {
   local search_key=$1
   for k in ${gToolsConfig[@]}; do 
      local key=$(echo $k | cut -d ':' -f 1)
      if [[ "$key" == "$search_key" ]]; then 
         local entry=$(echo $k | cut -d ':' -f 2,3)
         echo ${entry}
         break
      fi
   done
}

getDepenentBinaryName() {
   local result=$(echo $(getValue $1) | cut -d ':' -f 1)
   echo $result
}

getConfigInstallerFctPtr() {
   local result=$(echo $(getValue $1) | cut -d ':' -f 2)
   echo $result
}

isBinaryInstalled() {
   local binary=$1
   type $binary >/dev/null 2>&1 || { return 1; }
   return 0
}

isInstallerDefined () {
   local func=$1
   declare -F $func >/dev/null 2>&1 || { return 1; }
   return 0
}

#}}}

main