dotfiles/install

166 lines
4.2 KiB
Plaintext
Raw Normal View History

2020-07-25 23:39:09 +00:00
#!/usr/bin/env bash
if [[ $(uname) == 'Darwin' ]]; then
2020-07-25 23:39:09 +00:00
if ! command -v brew &>/dev/null
then
# We need to update bash, so we'll start with setting up homebrew.
./osx/pre_install
exit
fi
fi
2017-05-01 08:22:20 +00:00
2020-05-14 04:36:01 +00:00
source "script_helpers/printing.sh"
source "script_helpers/core.sh"
source "script_helpers/platform.sh"
source "script_helpers/file_ops.sh"
2017-05-01 08:22:20 +00:00
2021-02-18 03:38:53 +00:00
dotfiles_dir=$PWD
os_is_windows is_windows
2020-07-25 23:39:09 +00:00
os_is_macos is_macos
os_is_linux is_linux
2020-05-14 04:36:01 +00:00
# Check for admin permissions when running on Windows.
2020-03-15 18:44:36 +00:00
if [[ $is_windows -eq 1 ]]; then
# `openfiles` is a command present on all supported Windows versions,
# requires admin privileges, and has no side effects.
openfiles &>/dev/null
2020-05-14 04:36:01 +00:00
admin_error=$?
if [[ ! $admin_error -eq 0 ]]; then
fatal "You need to run this in an admin shell!"
fi
2017-05-01 08:22:20 +00:00
fi
2020-05-14 04:36:01 +00:00
set -e
2017-11-21 02:39:58 +00:00
2020-05-14 04:36:01 +00:00
####################################################################################################
# Helpers
####################################################################################################
2017-11-21 02:39:58 +00:00
2020-08-09 19:25:35 +00:00
use_shell() {
shell=$1
if hash chsh >/dev/null 2>&1; then
printf "\n${BLUE}Changing the default shell to $shell${NORMAL}\n"
chsh -s $(which $shell)
else
error "\nUnable to change the shell because this system does not have chsh.\n"
fi
}
2017-11-21 02:39:58 +00:00
setup_zsh() {
2020-08-09 19:25:35 +00:00
printf "${MAGENTA}==> ${NORMAL}Setting up zsh...\n"
2020-07-25 23:39:09 +00:00
if [[ $is_linux -eq 1 ]]; then
sudo apt install zsh
fi
2021-02-18 03:38:53 +00:00
make_link .dotfiles/zsh/core .zsh
2020-07-25 23:39:09 +00:00
FILES=()
FILES+=('zshrc')
FILES+=('zlogin')
for file in "${FILES[@]}"
do
2021-02-18 03:38:53 +00:00
make_link .dotfiles/zsh/$file .$file
2020-07-25 23:39:09 +00:00
done
2017-11-21 02:39:58 +00:00
}
2020-08-09 19:25:35 +00:00
setup_bash() {
printf "${MAGENTA}==> ${NORMAL}Setting up bash...\n"
FILES=()
FILES+=('bashrc')
FILES+=('bash_profile')
FILES+=('inputrc')
for file in "${FILES[@]}"
do
2021-02-18 03:38:53 +00:00
make_link .dotfiles/bash/$file .$file
2020-08-09 19:25:35 +00:00
done
}
2020-05-14 04:36:01 +00:00
####################################################################################################
# Setup
####################################################################################################
pushd "$HOME" &>/dev/null
2021-02-18 03:38:53 +00:00
make_link $dotfiles_dir .dotfiles 1 # expand source path in case we're reinstalling and the cwd is a symlink.
2020-05-14 04:36:01 +00:00
2020-08-09 19:25:35 +00:00
if [[ $is_windows -eq 1 ]]; then
2020-09-30 01:51:11 +00:00
do_vim_copy=1
if [[ -d "$PWD/.vim" ]]; then
printf "\n${BOLD}Vim folder already found at destination. Overwrite? [1,0]\n> ${NORMAL}"
read -e copy_vim
if [[ $copy_vim != "0" && $copy_vim != "1" ]]; then
fatal "Invalid value '$copy_vim'"
elif [[ $copy_vim == "0" ]]; then
do_vim_copy=0
printf "\n"
fi
fi
if [[ $do_vim_copy -eq 1 ]]; then
printf "${MAGENTA}==> ${NORMAL}Copying ${YELLOW}.dotfiles/vim${NORMAL} to ${YELLOW}$PWD/.vim${NORMAL}\n"
cp -r .dotfiles/vim .vim
fi
2020-08-09 19:25:35 +00:00
else
2021-02-18 03:38:53 +00:00
make_link .dotfiles/vim .vim
2020-08-09 19:25:35 +00:00
fi
2020-05-14 04:36:01 +00:00
FILES=()
2020-09-30 01:51:11 +00:00
FILES+=('env.loader')
2020-05-14 04:36:01 +00:00
FILES+=('aliases')
FILES+=('gitconfig')
FILES+=('vimrc')
FILES+=('curlrc')
for file in "${FILES[@]}"
do
2021-02-18 03:38:53 +00:00
make_link .dotfiles/$file .$file
2020-05-14 04:36:01 +00:00
done
2020-08-09 19:25:35 +00:00
set +e
2020-09-30 01:51:11 +00:00
git_comp_filename=".git-completion.bash"
printf "${MAGENTA}==> ${NORMAL}Downloading Git completion list to ${YELLOW}$PWD/$git_comp_filename${NORMAL}\n"
2020-08-09 19:25:35 +00:00
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o $git_comp_filename
set -e
2020-05-14 04:36:01 +00:00
#########################
2020-08-09 19:25:35 +00:00
# Setup platform files
2020-05-14 04:36:01 +00:00
#########################
2020-08-09 19:25:35 +00:00
2020-05-14 04:36:01 +00:00
if [[ $is_windows -eq 1 ]]; then
2020-08-09 19:25:35 +00:00
printf "\n${BOLD}Setting up Windows${NORMAL}\n\n"
os_name="windows"
# Already using bash if running msys2.
setup_bash
elif [[ $is_macos -eq 1 ]]; then
printf "\n${BOLD}Setting up MacOS${NORMAL}\n\n"
os_name="osx"
setup_zsh
setup_bash
use_shell zsh
elif [[ $is_linux -eq 1 ]]; then
printf "\n${BOLD}Setting up Linux${NORMAL}\n\n"
os_name="linux"
setup_zsh
setup_bash
use_shell bash
2020-05-14 04:36:01 +00:00
fi
2017-11-21 02:39:58 +00:00
2020-08-09 19:25:35 +00:00
if [[ $os_name != "" ]]; then
if [ -f .dotfiles/$os_name/env.platform ]; then
2021-02-18 03:38:53 +00:00
make_link .dotfiles/$os_name/env.platform .env.platform
2020-08-09 19:25:35 +00:00
fi
2017-11-21 02:39:58 +00:00
2020-08-09 19:25:35 +00:00
if [ -f .dotfiles/$os_name/gitconfig.platform ]; then
2021-02-18 03:38:53 +00:00
make_link .dotfiles/$os_name/gitconfig.platform .gitconfig.platform
2020-08-09 19:25:35 +00:00
fi
2017-11-21 02:39:58 +00:00
2021-02-18 03:38:53 +00:00
$dotfiles_dir/$os_name/install
2017-05-01 08:22:20 +00:00
fi
2020-05-14 04:36:01 +00:00
popd "$HOME" &>/dev/null
printf "${BOLD}${GREEN}Done!${NORMAL}\n"