forked from eirini-forks/eirini-station
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-user.sh
executable file
·232 lines (195 loc) · 5.83 KB
/
provision-user.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
#!/bin/bash
set -euo pipefail
readonly USAGE="Usage: provision.sh [-l | -c <command_name>]"
main() {
while getopts ":lch" opt; do
case ${opt} in
l)
declare -F | awk '{ print $3 }' | grep -vE "(main|git_clone)"
exit 0
;;
c)
shift $((OPTIND - 1))
for command in "$@"; do
$command
done
exit 0
;;
h)
echo "$USAGE"
exit 0
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
echo "$USAGE"
exit 1
;;
esac
done
shift $((OPTIND - 1))
echo ">>> Installing everything..."
mkdir_home_user_bin
setup_non_root_npm_install_global
install_gotools
install_docker
install_ohmyzsh
uninstall_vim_plug
install_nvim_extensions
install_cred_alert
configure_dotfiles
clone_git_repos
install_misc_tools
install_pure_zsh_theme
install_tmux_plugin_manager
install_zsh_autosuggestions
switch_to_zsh
}
mkdir_home_user_bin() {
mkdir -p "$HOME/bin"
}
setup_non_root_npm_install_global() {
mkdir -p "${HOME}/.npm-packages"
npm config set prefix "${HOME}/.npm-packages"
}
install_cred_alert() {
os_name=$(uname | awk '{print tolower($1)}')
curl -o cred-alert-cli \
"https://s3.amazonaws.com/cred-alert/cli/current-release/cred-alert-cli_${os_name}"
chmod 755 cred-alert-cli
mv cred-alert-cli "$HOME/bin/"
}
install_docker() {
echo ">>> Installing Docker"
if command -v docker; then
sudo apt upgrade docker-ce docker-ce-cli docker-ce-rootless-extras -y
else
curl -fsSL get.docker.com | sudo sh
sudo usermod -aG docker "$USER"
fi
}
install_gotools() {
echo ">>> Installing golangci-lint"
local url
url="$(curl -sSfL https://api.github.com/repos/golangci/golangci-lint/releases/latest | jq -r '.assets[]|select(.name|match("linux-amd64.deb")).browser_download_url')"
curl -sSfLo golangci-lint.deb "$url"
sudo dpkg --install golangci-lint.deb
rm -f golangci-lint.deb
echo ">>> Installing gopls"
go install golang.org/x/tools/gopls@latest
echo ">>> Installing setup-envtest"
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
}
install_ohmyzsh() {
echo ">>> Installing Oh My Zsh"
[ ! -d "$HOME/.oh-my-zsh" ] && sh -c "$(curl -fsSL https://github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# Delete default .zshrc to avoid stow conflicts
rm -f "$HOME/.zshrc"
}
install_tmux_plugin_manager() {
echo ">>> Installing TPM"
git_clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
}
install_zsh_autosuggestions() {
echo ">>> Installing zsh-autosuggestions"
git_clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
}
uninstall_vim_plug() {
# remove it now we've switched to lazy plugin manager
rm -f "$HOME/.local/share/nvim/site/autoload/plug.vim"
}
install_nvim_extensions() {
echo ">>> Installing the NeoVim extensions"
npm install -g neovim
pip3 install --upgrade pip
pip3 install --upgrade neovim
gem install neovim --user-install
}
clone_git_repos() {
echo ">>> Cloning our Git repositories"
mkdir -p "$HOME/workspace"
pushd "$HOME/workspace"
{
git_clone "git@github.com:cloudfoundry/korifi.git"
git_clone "git@github.com:cloudfoundry/korifi-ci.git"
git_clone "git@github.com:cloudfoundry/cf-k8s-secrets.git"
git_clone "git@github.com:eirini-forks/eirini-station.git"
}
popd
}
git_clone() {
local url path name branch
url=$1
path=${2:-""}
branch=${3:-""}
if [ -z "$path" ]; then
name=${url%%.git}
name=${name##*/}
path="$HOME/workspace/$name"
fi
if [ -d "$path" ]; then
echo "Repository $path already exists. Skipping git clone..."
return
fi
git clone "$url" "$path"
if [ -f "$path/.gitmodules" ]; then
git -C "$path" submodule update --init --recursive
fi
if [ -n "$branch" ]; then
git -C "$path" switch "$branch"
fi
}
configure_dotfiles() {
echo ">>> Installing eirini-home"
ssh-keyscan -t rsa github.com >>"$HOME/.ssh/known_hosts"
git_clone "git@github.com:pivotal-cf/git-hooks-core.git"
git_clone "git@github.com:cloudfoundry/eirini-private-config.git"
git_clone "git@github.com:eirini-forks/eirini-home.git"
pushd "$HOME/workspace/eirini-home"
{
git checkout master
git pull -r
./install.sh
export GIT_DUET_CO_AUTHORED_BY=1
export GIT_DUET_GLOBAL=true
git duet ae ae # initialise git-duet
git init # install git-duet hooks on eirini-home
}
popd
}
install_misc_tools() {
echo ">>> Installing Ginkgo"
go install github.com/onsi/ginkgo/v2/ginkgo@latest
echo ">>> Installing concourse-flake-hunter"
go install github.com/eirini-forks/concourse-flake-hunter@latest
echo ">>> Installing fly"
curl -sL "https://ci.korifi.cf-app.com/api/v1/cli?arch=amd64&platform=linux" -o "$HOME/bin/fly"
chmod +x "$HOME/bin/fly"
echo ">>> Installing k9s"
curl -LsSf https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_amd64.tar.gz | tar xvzf - -C "$HOME/bin" k9s
echo ">>> Installing kind"
curl -LsSf https://github.com/kubernetes-sigs/kind/releases/latest/download/kind-linux-amd64 -o "$HOME/bin/kind"
chmod +x "$HOME/bin/kind"
echo ">>> Installing shfmt"
go install mvdan.cc/sh/v3/cmd/shfmt@latest
}
install_pure_zsh_theme() {
echo ">>> Installing the pure prompt"
mkdir -p "$HOME/.zsh"
git_clone "https://github.com/sindresorhus/pure.git" "$HOME/.zsh/pure"
pushd "$HOME/.zsh/pure"
{
# pure have switched from `master` to `main` for their main branch
# TODO remove this once everyone has been migrated
if git show-ref --quiet refs/heads/master; then
git branch -m master main
git branch --set-upstream-to=origin/main
fi
git pull -r
}
popd
}
switch_to_zsh() {
echo ">>> Setting Zsh as the default shell"
sudo chsh -s /bin/zsh "$(whoami)"
}
main "$@"