-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·146 lines (116 loc) · 3.34 KB
/
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# vim:ft=sh ts=2 sw=2
error() {
echo "[ERROR] $1"
exit 1
}
require-sudo() {
sudo -v --prompt "Administrator privilege required. Please type your password: "
# Keep-alive: update existing `sudo` time stamp until `.osx` has finished
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
}
install-xcode() {
if ! xcode-select --print-path &>/dev/null; then
# Install XCode Command Line Tools.
xcode-select --install &>/dev/null
# Wait until XCode Command Line Tools installation has finished.
until xcode-select --print-path &>/dev/null; do
sleep 1
done
fi
}
install-brew() {
if command -v brew &> /dev/null
then
echo "'brew' already exists. skipping installation.."
return 0
fi
if ! /opt/homebrew/bin/brew shellenv 2>&1; then
echo "homdbrew not found. installing.."
require-sudo
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
if [ $? -ne 0 ]; then
error "Failed to install brew"
fi
else
echo "Found brew at $(whereis brew). Skipping install."
fi
if ! eval "$(/opt/homebrew/bin/brew shellenv)"; then
error "Failed to run brew shellenv"
fi
}
install-yay() {
if command -v yay &> /dev/null
then
echo "'yay' already exists. skipping installation.."
return 0
fi
rm -rf ~/.install/yay
mkdir -p ~/.install
sudo pacman -Sy --needed base-devel git
git clone https://aur.archlinux.org/yay.git ~/.install/yay
cd ~/.install/yay && makepkg -si
if [ $? -ne 0 ]; then
error "Failed to install 'yay'"
fi
}
install-nimf() {
if command -v nimf &> /dev/null
then
echo "'nimf' already exists. skipping installation.."
return 0
fi
rm -rf ~/.install/libhangul-git
git clone https://aur.archlinux.org/libhangul-git.git ~/.install/libhangul-git
cd ~/.install/libhangul-git && makepkg -si
# if [ $? -ne 0 ]; then
# error "Failed to install 'libhangul-git'"
# fi
rm -rf ~/.install/nimf
git clone https://github.com/hamonikr/nimf.git ~/.install/nimf
cd ~/.install/nimf && makepkg -si
# if [ $? -ne 0 ]; then
# error "Failed to install 'nimf'"
# fi
}
# Determine OS
uname_out="$(uname -s)"
case "${uname_out}" in
Linux*) machine=Linux ;;
Darwin*) machine=Mac ;;
*) machine="UNKNOWN:${uname_out}" ;;
esac
echo "Detected OS: ${machine}"
if [ "$machine" == "Mac" ]; then
install-xcode
install-brew
command -v chezmoi &> /dev/null || brew install chezmoi
chezmoi init github.com/xvzc/dotfiles || error "Filed to init chezmoi"
chezmoi apply -R || error "Failed to apply dotfiles"
brewfile="$HOME/.local/share/chezmoi/setup/Brewfile"
if ! brew bundle --no-lock --no-upgrade --file="$brewfile"; then
error "Failed to install MacOS packages"
fi
source "$HOME/.local/share/chezmoi/setup/macos-setup.sh" && all
elif [ "$machine" == "Linux" ]; then
echo "Installing Linux packages.."
install-yay
command -v chezmoi &> /dev/null || yay -Sy chezmoi
chezmoi init github.com/xvzc/dotfiles || error "Filed to init chezmoi"
chezmoi apply -R || error "Failed to apply dotfiles"
yay -S --needed --noconfirm - < ~/.local/share/chezmoi/setup/arch-packages.txt
# install-nimf
else
error "Cannot determine operating system."
fi
# install cargo
if ! command -v cargo &> /dev/null; then
curl https://sh.rustup.rs -sSf | sh
fi
# Install neovim version manager
bob install nightly
bob use nightly