-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·462 lines (441 loc) · 16.9 KB
/
bootstrap
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#!/usr/bin/env zsh
#
#
# Utilities that we need to get started.
(( ${+commands[gh]} )) || { echo "You need to install gh (https://cli.github.com/)" && exit 1; }
(( ${+commands[curl]} )) || sudo apt-get install -y curl || { echo "You need to install curl" && exit 1; }
(( ${+commands[jq]} )) || sudo apt-get install -y jq || { echo "You need to install jq" && exit 1; }
MISE_PKGS=(
awscli@latest
bat
bat-extras
cheat
delta
direnv
dive
fd
github-cli
go
helm
k9s
kubectl
lsd
neovim@stable
node@lts
tflint
tfswitch
zoxide
)
PYTHON_PKGS=(
ansible
argcomplete
'boto3[crt]'
httpie
pip
pipreqs
pre-commit
)
PYTHON_VERSION=$(curl --silent https://endoflife.date/api/python/3.12.json |jq -r '.latest')
# Set NEOVIM_BUILD to nightly or latest. If set to nightly.
NEOVIM_BUILD="stable"
while getopts 'M' OPT; do
case $OPT in
M) setup_MINIMAL=1 ;;
esac
done
kernel=$(uname -s | tr "[:upper:]" "[:lower:]")
case "$(uname -m)" in
x86_64)
machine=amd64
;;
*)
die "Machine $(uname -m) not supported by the installer. Sorry\n"
;;
esac
MY_TMP=/tmp/ybootstrap$$
mkdir -p $MY_TMP
# Check if we set up a file for public github settings. On my work machine, our local github settings are in my default environment and I use direnv to set the public ones where needed. direnv doesn't help in a script :)
if [[ -s ~/.github_public ]]; then
source ~/.github_public
fi
# Make ~/.local/bin our official user bin dir
home_bin=~/.local/bin
if [[ ! -d $home_bin ]]; then
mkdir -p $home_bin
fi
if [[ -d ${HOME}/bin && ! -L ${HOME}/bin ]]; then
cp -n ${HOME}/bin/* ${HOME}/.local/bin
mv ${HOME}/bin ${HOME}/bin-old
ln -s $home_bin ${HOME}/bin
fi
## Like an "UPSERT," clone or update the git project and return if a config/install is warranetd because of initial clone or chanegs were pulled.
upinst_from_git() {
readonly git_url=${1:?"Supply the project git url as first parameter to install_from_git()"}
readonly repo_name=${${git_url##*/}%.git}
readonly passed_clone_target=${2}
if [[ -z ${passed_clone_target// } ]]; then
if [[ -d ${HOME}/git/github ]]; then
local GITHUB_CLONE_DIR="${HOME}/git/github"
else
local GITHUB_CLONE_DIR="${HOME}/git"
fi
local clone_target="${GITHUB_CLONE_DIR}/${repo_name}"
else
local clone_target=${passed_clone_target}
fi
local EXIT_CODE=1 # this is an exit code, so "1" means false/fail
if [[ -d ${clone_target} ]]; then
cd $clone_target
git remote update
readonly local_ref=$(git rev-parse @)
readonly remote_ref=$(git rev-parse @{u})
if [[ $local_ref != $remote_ref ]]; then
git pull
EXIT_CODE=0
fi
cd -
else
git clone $git_url $clone_target
EXIT_CODE=0
fi
return $EXIT_CODE
}
gh_latest_release() {
local this_repo=$1
local latest_release=$(GH_HOST=github.com gh release list --limit 1 --exclude-pre-releases --exclude-drafts --repo $this_repo | cut -f3)
echo $latest_release
}
INITIAL_PWD=$PWD
# OS Type specific stuff first
case $(uname) in
Linux)
local arch=$(dpkg-architecture -q DEB_BUILD_ARCH)
source /etc/os-release
if [[ $ID != "ubuntu" && $ID != "linuxmint" ]]; then
echo "I only wrote this for ubuntu."
exit 1
fi
cd $MY_TMP
# Latest git
if [[ "$NAME" == "Ubuntu" ]]; then
if [[ 21 > $VERSION_ID ]]; then
# Earlier than jammy
if ! grep -q git-core/ppa /etc/apt/sources.list.d/* 2>/dev/null; then
sudo add-apt-repository -y ppa:git-core/ppa
fi
else
if ! add-apt-repository -L | grep -q git-core/ppa; then
sudo add-apt-repository -y -P ppa:git-core/ppa
fi
fi
fi
if [[ $ID == "ubuntu" && $VERSION_ID -le 22 ]]; then
CURSES_DEV_PKG="libncursesw5-dev"
LIBEFUSE_PKG="libfuse2"
else
CURSES_DEV_PKG="libncurses-dev"
LIBEFUSE_PKG="libfuse2t64"
fi
for pkg in $LIBEFUSE_PKG fonts-firacode fonts-hack fonts-symbola curl git libcurl4-openssl-dev jq source-highlight fd-find ripgrep liblua5.3-dev lua5.3 cmake ugrep; do
dpkg -s $pkg &>/dev/null \
|| sudo apt-get install -y $pkg
done
SCRIPT_HOME=$(readlink -f ${0%/*})
for pkg in make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm $CURSES_DEV_PKG xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev shellcheck docker.io plocate; do
dpkg -s $pkg &>/dev/null \
|| sudo apt-get install -y $pkg
done
if [[ $XDG_SESSION_TYPE == wayland ]]; then
for pkg in qtwayland5; do
dpkg -s $pkg &>/dev/null \
|| sudo apt-get install -y $pkg
done
fi
# Manage neovim outside of mise and install it in a global spot
print "Neovim"
if [[ ${NEOVIM_BUILD} == "stable" ]]; then
local latest_neovim_version=$(gh_latest_release "neovim/neovim")
local installed_neovim_version=$(/usr/local/bin/nvim --version 2>/dev/null | head -1 | awk '{print $2}' |cut -d- -f1)
if [[ ${installed_neovim_version} != $latest_neovim_version ]]; then
print "Updating from ${installed_neovim_version} to $latest_neovim_version"
GH_HOST=github.com gh release download ${latest_neovim_version} --pattern "nvim.appimage" --repo neovim/neovim -D $MY_TMP \
&& sudo install -m 755 ${MY_TMP}/nvim.appimage /usr/local/bin/nvim.appimage
[[ -L /usr/local/bin/nvim ]] || sudo ln -s /usr/local/bin/nvim.appimage /usr/local/bin/nvim
fi
elif [[ ${NEOVIM_BUILD} == "nightly" ]]; then
read -q "yn?Do you wish to refresh neovim nightly? "
case $yn in
[Yy]*)
print "\nInstalling latest nightly build."
GH_HOST=github.com gh release download nightly --pattern "nvim.appimage" --repo neovim/neovim -D $MY_TMP \
&& sudo install -m 755 ${MY_TMP}/nvim.appimage /usr/local/bin/nvim.appimage
[[ -L /usr/local/bin/nvim ]] || sudo ln -s /usr/local/bin/nvim.appimage /usr/local/bin/nvim
;;
*)
print "\nLeaving current version installed."
;;
esac
fi
# Latest mise-en-place
print "Checking for mise-en-place"
curl -sSL https://api.github.com/repos/jdx/mise/releases/latest -o ${MY_TMP}/mise_latest.json
local LATEST_MISE_VERSION=$(jq -r '.name' ${MY_TMP}/mise_latest.json)
if whence -p mise &>/dev/null; then
# Use mise to update itself
print "Running mise self-update"
mise self-update --yes
else
print "Installing mise $LATEST_MISE_VERSION fresh"
local GH_DOWNLOAD_URL=$(jq -r '.assets[].browser_download_url' ${MY_TMP}/mise_latest.json | grep 'linux-x64$')
(cd $MY_TMP && curl -sLSO $GH_DOWNLOAD_URL \
&& install -m 755 ${MY_TMP}/mise-*-linux-x64 $home_bin/mise)
fi
# Install mise tools
# for tool in ${MISE_PKGS[@]};do
# mise use --yes --global $tool
# done
# If we manage mise tools from ~/.config/yadm/bootstrap then this should be enough.
mise upgrade --yes
# Make sure we set an npm prefix for our user.
npm config set prefix '~/.local/'
corepack enable
# chruby
echo "chruby"
eval $(grep '^CHRUBY_VERSION' /usr/local/share/chruby/chruby.sh)
if [[ $CHRUBY_VERSION == "0.3.9" ]]; then
echo "up to date"
else
curl -sLS https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz -o chruby-0.3.9.tar.gz \
&& tar -xzf chruby-0.3.9.tar.gz \
&& cd chruby-0.3.9/ \
&& sudo make install
cd $MY_TMP
fi
# ruby-install
echo "ruby-install"
if [[ $(ruby-install --version | awk '{print $2}') == "0.9.3" ]]; then
echo "up to date"
else
curl -sLS https://github.com/postmodern/ruby-install/archive/v0.9.3.tar.gz -o ruby-install-0.9.3.tar.gz \
&& tar -xzf ruby-install-0.9.3.tar.gz \
&& cd ruby-install-0.9.3/ \
&& sudo make install
cd $MY_TMP
fi
# Hack Nerd font
echo "Install Hack Nerd, UbuntuNerd, and MesloLGS fonts"
need_nerd_font=0
if [[ -f "${HOME}/.local/share/fonts/HackNerdFont-Regular.ttf" ]]; then
if [[ $(strings "${HOME}/.local/share/fonts/HackNerdFont-Regular.ttf" |grep -w Version: |head -1 |awk '{print $3}') != "3.2.1" ]]; then
need_nerd_font=1
fi
else
need_nerd_font=1
fi
if [[ -f "${HOME}/.local/share/fonts/UbuntuNerdFont-Medium.ttf" ]]; then
if [[ $(strings "${HOME}/.local/share/fonts/UbuntuNerdFont-Medium.ttf" |grep -w Version: |head -1 |awk '{print $3}') != "3.2.1" ]]; then
need_nerd_font=1
fi
else
need_nerd_font=1
fi
if [[ $need_nerd_font -eq 1 ]]; then
(cd $MY_TMP && \
curl -sLSO "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/{Hack,Ubuntu,UbuntuMono,NerdFontsSymbolsOnly}.zip" \
&& rm ~/.local/share/fonts/*Nerd*
unzip -u Hack.zip \*.ttf -d ~/.local/share/fonts \
&& unzip -u Ubuntu.zip \*.ttf -d ~/.local/share/fonts \
&& unzip -u UbuntuMono.zip \*.ttf -d ~/.local/share/fonts \
&& unzip -u NerdFontsSymbolsOnly.zip \*.ttf -d ~/.local/share/fonts \
&& fc-cache -f -v ~/.local/share/fonts)
fi
if [[ ! -f "${HOME}/.local/share/fonts/MesloLGS_NF_Regular.ttf" ]]; then
autoload zmv
(cd $MY_TMP && \
curl -sLSO "https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20{Regular,Bold,Italic,Bold%20Italic}.ttf" \
&& zmv '*%20*' '${f:gs/\%20/_}' \
&& mv MesloLGS_NF*.ttf ~/.local/share/fonts/ \
&& fc-cache -f -v ~/.local/share/fonts)
fi
# kitty
local KITTY_VERSION="1"
local LATEST_KITTY="2"
if whence kitty &>/dev/null; then
local KITTY_VERSION=$(kitty --version | awk '{print $2}')
local LATEST_KITTY=$(curl --silent https://sw.kovidgoyal.net/kitty/current-version.txt)
fi
if [[ $KITTY_VERSION != $LATEST_KITTY ]];then
curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin launch=n
# Place the kitty.desktop file somewhere it can be found by the OS
cp ~/.local/kitty.app/share/applications/kitty.desktop ~/.local/share/applications/
# If you want to open text files and images in kitty via your file manager also add the kitty-open.desktop file
cp ~/.local/kitty.app/share/applications/kitty-open.desktop ~/.local/share/applications/
# Update the paths to the kitty and its icon in the kitty.desktop file(s)
sed -i "s|Icon=kitty|Icon=/home/$USER/.local/kitty.app/share/icons/hicolor/256x256/apps/kitty.png|g" ~/.local/share/applications/kitty*.desktop
sed -i "s|Exec=kitty|Exec=/home/$USER/.local/kitty.app/bin/kitty|g" ~/.local/share/applications/kitty*.desktop
fi
# Latest doggo
print "doggo"
local current_doggo_version=$(doggo --version 2>/dev/null| awk '{print $1}')
local latest_doggo_version=$(gh_latest_release "mr-karan/doggo")
if [[ "${current_doggo_version}" != "${latest_doggo_version}" ]]; then
print "Updating from ${current_doggo_version} to ${latest_doggo_version}"
local build_artifact="doggo_${latest_doggo_version#v}_Linux_$(uname -m).tar.gz"
mkdir -p "${MY_TMP}/doggo"
GH_HOST=github.com gh release download --pattern $build_artifact --repo mr-karan/doggo -D $MY_TMP \
&& tar -C "${MY_TMP}" -xzf "$MY_TMP/${build_artifact}" \
&& cp "${MY_TMP}/${build_artifact/.tar.gz/}/doggo" "${home_bin}" \
&& chmod 755 "${home_bin}/doggo"
mkdir -p ~/.zcompletions && "${home_bin}/doggo" completions zsh >| ~/.zcompletions/_doggo
fi
# Latest tenv
print "tenv"
local current_tenv_version=$(tenv version 2>/dev/null| awk '{print $3}')
local latest_tenv_version=$(gh_latest_release "tofuutils/tenv")
if [[ "${current_tenv_version}" != "${latest_tenv_version}" ]]; then
print "Updating from ${current_tenv_version} to ${latest_tenv_version}"
local build_artifact="tenv_${latest_tenv_version}_Linux_x86_64.tar.gz"
mkdir -p "${MY_TMP}/tenv"
GH_HOST=github.com gh release download --pattern $build_artifact --repo tofuutils/tenv -D $MY_TMP \
&& tar -C "${MY_TMP}/tenv" -xf $MY_TMP/tenv*.tar.gz \
&& install -D -t "${HOME}/.tenv/bin" ${MY_TMP}/tenv/t*
fi
# Latest fzf
print "fzf"
local current_fzf_version=$(fzf --version 2>/dev/null| awk '{print $1}')
local latest_fzf_version=$(gh_latest_release "junegunn/fzf")
if [[ "${current_fzf_version#v}" != "${latest_fzf_version#v}" ]]; then
print "Updating from ${current_fzf_version#v} to ${latest_fzf_version#v}"
local build_artifact="fzf-${latest_fzf_version#v}-linux_amd64.tar.gz"
mkdir -p "${MY_TMP}/fzf"
GH_HOST=github.com gh release download --pattern $build_artifact --repo junegunn/fzf -D $MY_TMP \
&& tar -C "${MY_TMP}/fzf" -xzf $MY_TMP/$build_artifact \
&& install -D -t "${home_bin}" ${MY_TMP}/fzf/fzf
fi
# Latest aws-iam-authenticator
print "aws-iam-authenticator"
local current_aws_iam_auth_version=$(aws-iam-authenticator version | jq -r '.Version' 2>/dev/null)
local latest_aws_iam_auth_version=$(gh_latest_release "kubernetes-sigs/aws-iam-authenticator")
if [[ "${current_aws_iam_auth_version#v}" != "${latest_aws_iam_auth_version#v}" ]]; then
print "Updating from ${current_aws_iam_auth_version#v} to ${latest_aws_iam_auth_version#v}"
local build_artifact="aws-iam-authenticator_${latest_aws_iam_auth_version#v}_linux_amd64"
mkdir -p "${MY_TMP}/aws-iam-authenticator"
GH_HOST=github.com gh release download --pattern $build_artifact --repo kubernetes-sigs/aws-iam-authenticator -D $MY_TMP \
&& install -m 755 ${MY_TMP}/$build_artifact "${home_bin}/aws-iam-authenticator"
fi
;;
Darwin)
# This section is pretty much abandoned because I don't use MacOS anymore.
if command -v brew &>/dev/null; then
echo "homebrew already installed"
else
echo "Installing homebrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew tap homebrew/cask-fonts
# Base stuff we need.
NEEDED_PACKAGES=(
openssl
readline
sqlite
xz
zlib
keychain
kubernetes-cli
coreutils
findutils
go
shfmt
bat
ugrep
bat-extras
git
chruby
ruby-install
direnv
jq
jsonlint
prettier
gh
lsd
gnu-getopt
fd
ripgrep
fzf
selene
zoxide
shellcheck
font-hack-nerd-font
font-fira-code
helm
)
brew list > ${MY_TMP}/brews.$$
for pkg in ${NEEDED_PACKAGES[*]}; do
grep -w $pkg ${MY_TMP}/brews.$$ &>/dev/null \
|| brew install $pkg
done
SCRIPT_HOME=$(greadlink -f ${0%/*})
# Make sure we set an npm prefix for our user.
npm config set prefix '~/.local/'
npm install --location=global neovim
# dive
echo "dive"
latest_dive_version=$(gh_latest_release "wagoodman/dive")
installed_dive_version=$(dive --version 2>/dev/null|awk '{print $2}')
if [[ ${installed_dive_version#v} != ${latest_dive_version#v} ]]; then
GH_HOST=github.com gh release download --pattern '*darwin_amd64.tar.gz' --repo wagoodman/dive -D ${MY_TMP} \
&& tar -C ${MY_TMP} -xzf ${MY_TMP}/dive-*darwin_amd64.tar.gz \
&& cp ${MY_TMP}/dive ${home_bin} \
&& chmod 755 ${home_bin}/dive
fi
# neovim
if [[ "NVIM v${NEOVIM_VERSION}" != $(nvim --version |head -1) ]]; then
echo neovim
curl -sLSo ${MY_TMP}/nvim-macos.tar.gz https://github.com/neovim/neovim/releases/download/v${NEOVIM_VERSION}/nvim-macos.tar.gz \
&& gtar -C ~/.local/ -xzf ${MY_TMP}/nvim-macos.tar.gz \
&& ln -sf ~/local/nvim-macos/bin/nvim ${home_bin}/nvim
fi
# kitty
local KITTY_VERSION="1"
local LATEST_KITTY="2"
if whence kitty &>/dev/null; then
local KITTY_VERSION=$(kitty --version | awk '{print $2}')
local LATEST_KITTY=$(curl --silent https://sw.kovidgoyal.net/kitty/current-version.txt)
fi
if [[ $KITTY_VERSION != $LATEST_KITTY ]];then
curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin launch=n
fi
;;
*)
echo "Unknown OS type"
exit
;;
esac
##
echo "pyenv"
if upinst_from_git https://github.com/pyenv/pyenv.git ~/.pyenv; then
(cd ~/.pyenv && src/configure && make -C src)
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
fi
if [[ -d ~/.pyenv/plugins/pyenv-virtualenv ]]; then
(cd ~/.pyenv/plugins/pyenv-virtualenv && git pull)
else
git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
fi
if ! pyenv global $PYTHON_VERSION &>/dev/null; then
print "Using pyenv to install python $PYTHON_VERSION"
pyenv install $PYTHON_VERSION
pyenv global $PYTHON_VERSION
PIP_OPTIONS="--force-reinstall"
fi
echo "Python packages:"
for pkg in ${PYTHON_PKGS[@]};do
python3 -m pip install --upgrade --user ${PIP_OPTIONS} $pkg | grep -v "Requirement already satisfied"
done
print "Ruby Gems"
for pkg in aws-sdk-ec2 bundler fileutils octokit asciidoctor kramdown-asciidoc;do
gem install $pkg
done
rm -rf ${MY_TMP}