-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup
executable file
·297 lines (254 loc) · 8.81 KB
/
setup
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/env bash
set -e
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
else
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
fi
exit "${code}"
}
trap 'error ${LINENO}' ERR
function echo_task() {
echo -e " \e[33m*\e[39m $1"
}
function echo_sub_task() {
echo -e " \e[33m*\e[39m $1"
}
function check_apt_installed() {
return dpkg -l "$1" &> /dev/null
}
function apt_install() {
if dpkg --get-selections | grep -q "^$1[[:space:]]*install$" >/dev/null; then
echo_sub_task "$1 already installed"
else
echo_sub_task "Installing $1"
sudo apt-get -qq install -y "$1"
fi
}
function brew_install() {
if brew ls --versions myformula > /dev/null; then
echo_sub_task "$1 already installed"
else
echo_sub_task "Installing $1"
brew install "$1"
fi
}
function is_sudo() {
if groups | grep -q "\\bsudo\b"; then
return 0
fi
if groups | grep -q "\\broot\b"; then
return 0
fi
return 1
}
function is_macos() {
if [ "$(uname -s)" = "Darwin\n" ]; then
return 0
fi
return 1
}
function get_distribution() {
if command -v lsb_release > /dev/null; then
echo "$(lsb_release -si) $(lsb_release -sr)"
fi
echo "$(uname -s)"
}
function get_cpuinfo() {
if is_macos; then
echo "$(sysctl -n machdep.cpu.brand_string)"
else
echo "$(sed -n 's/^model name[ \t]*: *//p' /proc/cpuinfo | uniq | sed ':a;N;$!ba;s/\n/, /g')"
fi
}
WARNS=()
function add_warn() {
WARNS+=("$1")
}
function display_warns() {
if [ ${#WARNS[@]} -gt 0 ]; then
echo -e "\n\n\e[93mWARNING:\e[39m"
for warn in "${WARNS[@]}"
do
echo -e " \e[33m*\e[39m $WARNS"
done
fi
}
# --------------------------------------------------
REPO=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo "----------------------------------------------------------------------------------------------------------------"
echo ""
echo -e " \e[94m||||||||||||"
echo -e " \e[34m88\e[94m||||||||||||"
echo -e " \e[34m8888\e[94m||||||||||||"
echo -e " \e[34m888888\e[94m||||||||||||"
echo -e " \e[34m88888888\e[94m||||||||||||"
echo -e " \e[34m8888888888\e[94m||||||||||||"
echo -e " \e[34m888888888888\e[94m||||||||||||"
echo -e " \e[94m|||||||||||||\e[34m888888888888"
echo -e " \e[94m|| \e[34m8\e[94m||||||||||||||\e[34m88888888 \e[34mUser:\e[39m $(whoami)"
echo -e " \e[94m|||| \e[34m888\e[94m||||||||||||||\e[34m8888 \e[34mHostname:\e[39m $(hostname)"
echo -e " \e[94m|||||| \e[34m88888\e[94m|||||||||||||\e[34m8 \e[34mDistro:\e[39m $(get_distribution)"
echo -e " \e[94m|||||||| \e[34m8888888\e[94m||||||||||||| \e[34mKernel:\e[39m $(uname -r)"
echo -e " \e[94m||||||||| \e[34m888888888\e[94m|||||||||||||| \e[34mShell:\e[39m $SHELL"
echo -e " \e[94m|||||||||||\e[34m88888888888\e[94m|||||||||||||| \e[34mCPU:\e[39m $(get_cpuinfo)"
echo -e " \e[94m|||||||||||\e[34m8888888888888\e[94m|||||||||||| \e[34mHome directory:\e[39m $HOME"
echo -e " \e[94m||||||||||||\e[34m888888888888\e[94m|||||||||||| \e[34mDotfiles:\e[39m $REPO"
echo -e " \e[94m||||||||||||\e[34m8888888888 \e[94m|||||||||| \e[34mSudo:\e[39m $(if is_sudo -eq 0; then echo 'Yes'; else echo 'No'; fi)"
echo -e " \e[94m||||||||||||\e[34m88888888 \e[94m|||||||||"
echo -e " \e[94m||||||||||||\e[34m888888 \e[94m|||||||"
echo -e " \e[94m||||||||||||\e[34m8888 \e[94m|||||"
echo -e " \e[94m||||||||||||\e[34m88 \e[94m|||"
echo -e " \e[94m|||||||||||| \e[94m||\e[39m"
echo ""
echo "----------------------------------------------------------------------------------------------------------------"
echo ""
echo "Executing tasks:"
# Submodules
if [ -d "$REPO/.git" ]; then
echo_task "Updating submodules"
(cd "$REPO" && git submodule update --init --recursive)
fi
if is_macos -eq 1; then
if command -v brew > /dev/null; then
echo_task "Installing brew packages"
brew_install "python3"
else
echo -e "\n\n\nPlease install brew - https://brew.sh/"
exit 0
fi
fi
# apt packages
if is_sudo -eq 0; then
if command -v apt-get > /dev/null; then
echo_task "Updating apt"
sudo apt update -qq
echo_task "Installing apt packages"
apt_install "autojump"
apt_install "curl"
apt_install "htop"
apt_install "python3"
apt_install "python3-pip"
apt_install "vim"
apt_install "zsh"
else
echo_task "Skipping apt packages"
fi
else
echo_task "Skipping apt packages (not sudo)"
fi
# gnupg
echo_task "Setting up gnupg config"
mkdir -p "$HOME/.gnupg"
ln -sf "$REPO/gnupg/gpg.conf" "$HOME/.gnupg/gpg.conf"
ln -sf "$REPO/gnupg/scd-event" "$HOME/.gnupg/scd-event"
chmod +x "$HOME/.gnupg/scd-event"
# VIM
echo_task "Setting up VIM config"
ln -sf "$REPO/vim/.vimrc" "$HOME/.vimrc"
# Local ~/bin
echo_task "Setup local bin"
mkdir -p "$HOME/bin"
for f in $REPO/bin/*
do
bin_filename=$(basename "$f")
echo_sub_task "$bin_filename"
ln -sf "$REPO/bin/$bin_filename" "$HOME/bin/$bin_filename"
done
for f in $REPO/scripts/bin/*
do
bin_filename=$(basename "$f")
echo_sub_task "$bin_filename"
ln -sf "$REPO/scripts/bin/$bin_filename" "$HOME/bin/$bin_filename"
done
# Git
echo_task "Setting up git"
git config --global core.editor vim &> /dev/null
git config --global push.default current &> /dev/null
# Gnome
if command -v gsettings > /dev/null; then
echo_task "Setting up gnome"
# echo_sub_task "Nautilus"
# gsettings set org.gnome.nautilus.preferences default-folder-viewer "list-view"
# gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 24
# echo_sub_task "Terminal"
# dconf load /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/ < "$REPO/gnome/terminal/profiles/main-profile.dconf"
echo_sub_task "gtk-3.0"
mkdir -p "$HOME/.config/gtk-3.0"
ln -sf "$REPO/gnome/gtk-3.0/gtk.css" "$HOME/.config/gtk-3.0/gtk.css"
else
echo_task "Skipping gnome setup"
fi
# Fonts
echo_task "Fonts"
if [ -d "$HOME/.fonts" ]; then
echo_sub_task "Symlink already exists"
else
echo_sub_task "Creating symlink"
ln -sf "$REPO/fonts" "$HOME/.fonts"
if command -v fc-cache > /dev/null; then
echo_sub_task "Updating fc-cache"
fc-cache -f
else
echo_sub_task "Skipping fc-cache"
fi
fi
# Terminator
echo_task "Setting up terminator"
mkdir -p "${HOME}/.config/terminator"
cp "$REPO/terminator/config" "$HOME/.config/terminator/config"
# Zellij
if [ ! -f "${HOME}/bin/zellij" ]; then
curl -s -L -o "${HOME}/zellij.tar.gz" https://github.com/zellij-org/zellij/releases/latest/download/zellij-x86_64-unknown-linux-musl.tar.gz
tar zxvf "${HOME}/zellij.tar.gz" -C "${HOME}/bin"
rm "${HOME}/zellij.tar.gz"
fi
# Install AWS CLI
if pip freeze | grep -q "awscli"; then
echo_task "awscli already installed"
else
echo_task "Install awscli"
pip3 install --user awscli | sed 's/^/ /'
fi
# SSH Config
if [ -f "$HOME/.aws/credentials" ]; then
echo_task "Applying SSH config"
ssh_result=$(ssh-config --apply)
echo_sub_task "${ssh_result}"
else
add_warn "SSH config not applied because awscli is not installed and/or AWS credentials do not exist."
fi
# Gradle
echo_task "Setting up gradle"
mkdir -p "$HOME/.gradle"
ln -sf "$REPO/gradle/gradle.properties" "$HOME/.gradle/gradle.properties"
# ZSH
echo_task "Setting up ZSH"
if [[ "$SHELL" =~ .*zsh$ ]]; then
echo_task "ZSH is the current shell"
else
if [[ $EUID -ne 0 ]]; then
echo_task "Changing shell from ${SHELL} to zsh"
sudo chsh -s "$(which zsh)" "$USER"
echo -e "\n\n\e[93mWARNING:\e[39m: Please logout and log back in for your shell change to take affect."
fi
fi
if [ -d "$HOME/.oh-my-zsh" ]; then
echo_sub_task "oh-my-zsh already installed"
else
echo_sub_task "Installing oh-my-zsh"
zsh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"<<<"exit" || [ -d "$HOME/.oh-my-zsh" ]
rm -rf "$HOME/.zshrc"
fi
ln -sf "$REPO/zsh/.zshrc" "$HOME/.zshrc"
ln -sf "$REPO/zsh/.zprofile" "$HOME/.zprofile"
ln -sf "$REPO/zsh/.zshenv" "$HOME/.zshenv"
ln -sf "$REPO/zsh/custom/themes/jagnoster.zsh-theme" "$HOME/.oh-my-zsh/custom/themes/jagnoster.zsh-theme"
# End script, display any warnings
display_warns
echo -e "\n\e[32mSetup complete\e[39m"
exit 0