about summary refs log blame commit diff
path: root/configs/setup_configs.sh
blob: d74500f86e6f3eef6c99570c8424d55bca3381cd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11

                   
                                      

                                         
 




                                              
 
 

                             
 


                                                         
 
                                                                               
                                                     


                                                                   
 





                                                                                    
            
                                                        

                                                
          









                                    
#!/usr/bin/env bash

pc_settings_path="${HOME}/pc_settings"
configs_dir="${pc_settings_path}/configs"
shared_configs="${configs_dir}/shared"

if [[  $(uname) == 'Darwin' ]]; then
    os_specific_configs="${configs_dir}/os_x"
elif [[ $(uname) == 'Linux' ]]; then
    os_specific_configs="${configs_dir}/linux"
fi


function symlink_configs () {
    configs_dir=$1

    for cf in $(find $configs_dir -type f -name ".*"); do
        filename=$(grep -o "[^\/]+$" <<<$cf)
        echo "$filename: "

        if [ -f "${HOME}/${filename}" ] && [ ! -L "${HOME}/${filename}" ]; then
            echo -n "Backing up ${filename}... " && \
            mv "${HOME}/${filename}" "${HOME}/${filename}.bak" && \
            echo "Done."
        fi

        if [ -L "${HOME}/${filename}" ]; then
            if [ $(readlink "${HOME}/${filename}") = $cf ]; then
                echo "Already properly symlinked to ${configs_dir}."
            else
                echo "Already symlinked but NOT to the proper location. Aborting..."
            fi
        else
            echo -n "Symlinking to ${filename}... " && \
            ln -s $cf "${HOME}/${filename}" && \
            echo "Done."
        fi
        echo ""
    done
}


# handle shared configs
symlink_configs $shared_configs

# handle os-specific configs
symlink_configs $os_specific_configs