diff options
author | William Carroll <wpcarro@gmail.com> | 2018-04-25T17·35-0400 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2018-07-19T16·00-0400 |
commit | 3135e5faf23f83900d16bfd465b4442d51e36377 (patch) | |
tree | cc821e623fa139275ecb97ede4561bdf904d55dc /configs/setup | |
parent | 3c8e6f0cc5eac51e369b8ffbd0441366cdc6da40 (diff) |
Refactor install scripts
- Support emacs installation - Export DOTFILES env var to simplify setup. - Change filenames for consistency
Diffstat (limited to 'configs/setup')
-rwxr-xr-x | configs/setup | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/configs/setup b/configs/setup new file mode 100755 index 000000000000..e81b49442f42 --- /dev/null +++ b/configs/setup @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +dotfiles_path="${HOME}/dotfiles" +configs_dir="${dotfiles_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 |