152 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			152 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| if [[ $(uname) == 'Darwin' ]]; then
 | |
|     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
 | |
| 
 | |
| source "script_helpers/printing.sh"
 | |
| source "script_helpers/core.sh"
 | |
| source "script_helpers/platform.sh"
 | |
| source "script_helpers/file_ops.sh"
 | |
| 
 | |
| cwd=$PWD
 | |
| confirm_link=0
 | |
| os_is_windows is_windows
 | |
| os_is_macos is_macos
 | |
| os_is_linux is_linux
 | |
| 
 | |
| if [[ $is_windows -eq 1 ]]; then
 | |
|     # Check for admin permissions.
 | |
|     net session &>/dev/null
 | |
|     admin_error=$?
 | |
|     if [[ ! $admin_error -eq 0 ]]; then
 | |
|         fatal "You need to run this in an admin shell!"
 | |
|     fi
 | |
| fi
 | |
| 
 | |
| set -e
 | |
| 
 | |
| ####################################################################################################
 | |
| # Helpers
 | |
| ####################################################################################################
 | |
| 
 | |
| 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
 | |
| }
 | |
| 
 | |
| setup_zsh() {
 | |
|     printf "${MAGENTA}==> ${NORMAL}Setting up zsh...\n"
 | |
| 
 | |
|     if [[ $is_linux -eq 1 ]]; then
 | |
|         sudo apt install zsh
 | |
|     fi
 | |
| 
 | |
|     setup_dir .dotfiles/zsh/core .zsh
 | |
| 
 | |
|     FILES=()
 | |
|     FILES+=('zshrc')
 | |
|     FILES+=('zlogin')
 | |
| 
 | |
|     for file in "${FILES[@]}"
 | |
|     do
 | |
|         setup_file .dotfiles/zsh/$file .$file
 | |
|     done
 | |
| }
 | |
| 
 | |
| setup_bash() {
 | |
|     printf "${MAGENTA}==> ${NORMAL}Setting up bash...\n"
 | |
| 
 | |
|     FILES=()
 | |
|     FILES+=('bashrc')
 | |
|     FILES+=('bash_profile')
 | |
|     FILES+=('inputrc')
 | |
| 
 | |
|     for file in "${FILES[@]}"
 | |
|     do
 | |
|         setup_file .dotfiles/bash/$file .$file
 | |
|     done
 | |
| }
 | |
| 
 | |
| ####################################################################################################
 | |
| # Setup
 | |
| ####################################################################################################
 | |
| 
 | |
| pushd "$HOME" &>/dev/null
 | |
| 
 | |
| setup_dir $cwd .dotfiles
 | |
| 
 | |
| if [[ $is_windows -eq 1 ]]; then
 | |
|     printf "${MAGENTA}==> ${NORMAL}Copy ${YELLOW}.dotfiles/vim${NORMAL} to ${YELLOW}$PWD/.vim${NORMAL}\n"
 | |
|     cp -r  .dotfiles/vim .vim
 | |
| else
 | |
|     setup_dir .dotfiles/vim .vim
 | |
| fi
 | |
| 
 | |
| FILES=()
 | |
| FILES+=('env.common')
 | |
| FILES+=('aliases')
 | |
| FILES+=('gitconfig')
 | |
| FILES+=('vimrc')
 | |
| FILES+=('curlrc')
 | |
| 
 | |
| for file in "${FILES[@]}"
 | |
| do
 | |
|     setup_file .dotfiles/$file .$file
 | |
| done
 | |
| 
 | |
| set +e
 | |
| git_comp_filename=".git-completions.bash"
 | |
| printf "${MAGENTA}==> ${NORMAL}Download git completions list to ${YELLOW}$PWD/$git_comp_filename${NORMAL}\n"
 | |
| curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o $git_comp_filename
 | |
| set -e
 | |
| 
 | |
| #########################
 | |
| # Setup platform files
 | |
| #########################
 | |
| 
 | |
| if [[ $is_windows -eq 1 ]]; then
 | |
|     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
 | |
| fi
 | |
| 
 | |
| if [[ $os_name != "" ]]; then
 | |
|     if [ -f .dotfiles/$os_name/env.platform ]; then
 | |
|         setup_file .dotfiles/$os_name/env.platform .env.platform
 | |
|     fi
 | |
| 
 | |
|     if [ -f .dotfiles/$os_name/gitconfig.platform ]; then
 | |
|         setup_file .dotfiles/$os_name/gitconfig.platform .gitconfig.platform
 | |
|     fi
 | |
| 
 | |
|     $cwd/$os_name/install
 | |
| fi
 | |
| 
 | |
| popd "$HOME" &>/dev/null
 | |
| 
 | |
| printf "${BOLD}${GREEN}Done!${NORMAL}\n"
 |