-
Notifications
You must be signed in to change notification settings - Fork 0
/
full-install.sh
executable file
·125 lines (98 loc) · 3.33 KB
/
full-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
fancy_echo() {
local fmt="$1"
shift
# shellcheck disable=SC2059
printf "\\n$fmt\\n" "$@"
}
apple_m1() {
if [ -f "/proc/sys/machdep/cpu/brand_string" ]; then
sysctl -n machdep.cpu.brand_string | grep "Apple M0"
else
return -1
fi
}
rosetta() {
uname -m | grep "x86_64"
}
homebrew_installed_on_m1() {
apple_m1 && ! rosetta && [ -d "/opt/homebrew" ]
}
homebrew_installed_on_intel() {
! apple_m1 && command -v brew >/dev/null
}
install_or_update_homebrew() {
if homebrew_installed_on_m1 || homebrew_installed_on_intel; then
update_homebrew
else
install_homebrew
fi
}
install_homebrew() {
fancy_echo "Installing Homebrew ..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if uname -s | grep Linux; then
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
}
update_homebrew() {
fancy_echo "Homebrew already installed. Updating Homebrew ..."
brew update
}
# shellcheck disable=SC2154
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e -o pipefail
fancy_echo 'Setting up your shiny new laptop...'
install_or_update_homebrew
fancy_echo "Verifying the Homebrew installation..."
if brew doctor; then
fancy_echo "Your Homebrew installation is good to go."
else
fancy_echo "Your Homebrew installation reported some errors or warnings."
echo "Review the Homebrew messages to see if any action is needed."
fi
fancy_echo "Installing chezmoi and applying dotfiles ..."
brew bundle --file=- <<EOF
brew 'chezmoi'
EOF
if [ ! -f "$HOME/.config/chezmoi/chezmoi.toml" ]; then
chezmoi init --apply --verbose https://github.com/allymparker/dotfiles.git
chmod 0600 "$HOME/.config/chezmoi/chezmoi.toml"
fi
fancy_echo "Running your customizations from ~/.init ..."
if [ -f "$HOME/.Brewfile" ]; then
fancy_echo "Installing tools and apps from .Brewfile..."
if brew bundle --file="$HOME/.Brewfile"; then
fancy_echo "All items in .Brewfile were installed successfully."
else
fancy_echo "Some items in .Brewfile were not installed successfully."
fi
fi
fancy_echo "Configuring OMZ..."
if [ ! -d "$HOME/.oh-my-zsh" ]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# OMZ Moves the existing .zshrc to .zshrc.pre-oh-my-zsh, reapply chezmoi to undo it
chezmoi apply --force
rm ~/.zshrc.pre-oh-my-zsh
fi
fancy_echo "Configuring OMZ plugins..."
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
fi
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
fi
fancy_echo "Setting ZSH as default shell..."
if ! grep -Fxq $(command -v zsh) /etc/shells; then
command -v zsh | sudo tee -a /etc/shells
fi
if ! echo $SHELL | grep zsh; then
chsh -s $(which zsh)
fi
fancy_echo "Install Vim Plug..."
if [ ! -f "$HOME/.vim/autoload/plug.vim" ]; then
curl -fLo $HOME/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
fancy_echo "Install Vim Plugins..."
vim +PlugInstall +qall