-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.sh
executable file
·235 lines (199 loc) · 6.35 KB
/
sync.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/sh
set -e
dotfiles_url="https://raw.githubusercontent.com/lavignes/dotfiles/mainline"
workdir="$(mktemp -d)"
echo "The temp working directory will be $workdir"
require_command() {
if ! [ -x "$(command -v "$1")" ]; then
echo "Couldn't find $1 on your system. I cannot continue..."
exit 1
fi
}
if [ -x "$(command -v "apt")" ]; then
os_pkg_manager="apt"
fi
if [ -x "$(command -v "yum")" ]; then
os_pkg_manager="yum"
fi
confirm() {
echo "$1"
echo "Is this ok [y]es/[n]o/[s]kip ?"
read -r choice
case "$choice" in
y|yes|Y)
return 0
;;
s|skip|S)
return 1
;;
*)
echo "Exiting..."
exit 1
;;
esac
}
apt_install() {
if [ -x "$(command -v "$2")" ]; then
return
fi
if [ -x "$(command -v "$1")" ]; then
return
fi
if [ "$os_pkg_manager" != "apt" ]; then
return
fi
echo "Couldn't find $1. I'll try to install it..."
sudo apt -y install "$1"
}
yum_install() {
if [ -x "$(command -v "$1")" ]; then
return
fi
if [ "$os_pkg_manager" != "yum" ]; then
return
fi
echo "Couldn't find $1. I'll try to install it..."
sudo yum -y install "$1"
}
sync_git() {
apt_install "git"
yum_install "git"
require_command "git"
if confirm "I will now replace your git configuration."; then
rm -f "$HOME/.gitconfig"
curl -sSLo "$HOME/.gitconfig" "$dotfiles_url/home/.gitconfig"
fi
}
sync_shell() {
apt_install "zsh"
yum_install "zsh"
require_command "zsh"
if confirm "I will now reinstall oh-my-zsh and replace your zsh configuration."; then
rm -rf "$HOME/.oh-my-zsh"
rm -f "$HOME/.zshrc"
curl -sSLo "$workdir/install.sh" "https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh"
chmod +x "$workdir/install.sh"
"$workdir/install.sh" "" "--unattended"
curl -sSLo "$HOME/.zshrc" "$dotfiles_url/home/.zshrc"
if [ "$(basename "$SHELL")" != "zsh" ]; then
echo "The current shell does not seem like zsh. I can fix that..."
echo "You'll probably have to provide a password :("
chsh -s "$(command -v zsh)"
fi
apt_install "tmux"
yum_install "tmux"
rm -f "$HOME/.tmux.conf"
curl -sSLo "$HOME/.tmux.conf" "$dotfiles_url/home/.tmux.conf"
fi
}
sync_node() {
if confirm "I will now install nvm and update to the latest nodejs."; then
eval "$(curl -sSL "https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh")"
NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 16
nvm use 16
nvm alias default 16
fi
}
sync_rust() {
if confirm "I will now install rustup and cargo."; then
curl -sSL "https://sh.rustup.rs" | sh -s -- --no-modify-path -y
export PATH="$HOME/.cargo/bin:$PATH"
fi
}
ag_install() {
if [ -x "$(command -v "ag")" ]; then
return
fi
if [ "$os_pkg_manager" != "yum" ]; then
return
fi
yum_install "pkgconfig"
yum_install "automake"
yum_install "gcc"
yum_install "zlib-devel"
yum_install "pcre-devel"
yum_install "xz-devel"
git clone "https://github.com/ggreer/the_silver_searcher.git" "$workdir/the_silver_searcher"
pushd "$workdir/the_silver_searcher"
./build.sh
sudo make install
popd
}
sync_vim() {
apt_install "vim"
yum_install "vim"
require_command "vim"
sync_node
apt_install "clangd"
apt_install "silversearcher-ag" "ag"
ag_install
if confirm "I will now replace your vim configuration."; then
rm -rf "$HOME/.vim"
rm -f "$HOME/.vimrc"
rm -rf "$HOME/.config/nvim"
curl -sSLo "$HOME/.vimrc" "$dotfiles_url/home/.vimrc"
curl -sSLo "$HOME/.config/nvim/init.vim" --create-dirs \
"$dotfiles_url/home/.config/nvim/init.vim"
curl -sSLo "$HOME/.vim/autoload/plug.vim" --create-dirs \
"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
set -- "coc-settings.json"
for f in "$@"; do
curl -sSLo "$HOME/.vim/$f" "$dotfiles_url/home/.vim/$f"
done
cargo install --git https://github.com/wgsl-analyzer/wgsl-analyzer wgsl_analyzer
echo "This will look weird. But in 5 seconds I will start vim and set it up."
echo "Don't worry, it will close right afterward..."
sleep 5
vim -c ":PlugInstall" -c ":qall!"
vim -c ":CocInstall -sync coc-rust-analyzer" -c ":qall!"
vim -c ":CocInstall -sync coc-clangd" -c ":qall!"
fi
}
sync_gui() {
if [ -z "$XDG_SESSION_TYPE" ]; then
echo "I don't think you have a gui..."
echo "That's it! Everything is up to date!"
return
fi
if confirm "All the basic stuff is done. I can now setup the gui."; then
sudo add-apt-repository -y ppa:papirus/papirus
sudo add-apt-repository -y ppa:aslatter/ppa
sudo apt-add-repository -y ppa:neovim-ppa/unstable
sudo apt update
apt_install "papirus-icon-theme"
apt_install "alacritty"
apt_install "neovim"
papirus-folders -t Papirus -C nordic -u
papirus-folders -t Papirus-Dark -C nordic -u
mkdir -p "$HOME/.local/share/fonts"
curl -sSLo "$HOME/.local/share/fonts/PerfectDOSVGA437Win.ttf" "$dotfiles_url/home/.local/share/fonts/PerfectDOSVGA437Win.ttf"
fc-cache -f
rm -rf "$HOME/.config/alacritty"
mkdir -p "$HOME/.config/alacritty"
curl -sSLo "$HOME/.config/alacritty/alacritty.toml" "$dotfiles_url/home/.config/alacritty/alacritty.toml"
fi
if confirm "If you're using an apple keyboard driver, I can configure it to act right on linux"; then
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode
echo "options hid_apple fnmode=2" | sudo tee -a /etc/modprobe.d/hid_apple.conf
sudo update-initramfs -u -k all
fi
echo "That's it! You should log out and log back in."
}
sync_bin() {
mkdir -p "$HOME/bin"
set -- "ssh-tunnel" "modplay" "xsig"
for f in "$@"; do
curl -sSLo "$HOME/bin/$f" "$dotfiles_url/home/bin/$f"
chmod +x "$HOME/bin/$f"
done
}
require_command "curl"
sync_git
sync_shell
sync_rust
sync_vim
sync_bin
sync_gui