-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprovision-user.sh
executable file
·253 lines (214 loc) · 6.59 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source $SCRIPT_DIR/provision-env.sh
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
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
install_openstack_clients
install_gcloud_cli
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)}')
url="$(curl -sSfL https://api.github.com/repos/pivotal-cf/cred-alert/releases/latest | jq -r '.assets[]|select(.name|match("linux")).browser_download_url')"
curl -sSfLo cred-alert-cli "$url"
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://raw.githubusercontent.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"
}
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 "https://github.com/cloudfoundry/korifi.git"
git_clone "https://github.com/cloudfoundry/korifi-ci.git"
#git_clone "https://github.com/cloudfoundry/cf-k8s-secrets.git"
git_clone "https://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"
# backing up any previous existing ssh-key
if [ -f $HOME/.ssh/authorized_keys ]; then
KEYS="$(cat $HOME/.ssh/authorized_keys)"
fi
ssh-keyscan -t rsa github.com >>"$HOME/.ssh/known_hosts"
git_clone "https://github.com/pivotal-cf/git-hooks-core.git"
#git_clone "https://github.com/cloudfoundry/eirini-private-config.git"
git_clone "https://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
# restoring previously backed up ssh-keys
if [ "$KEYS" ]; then
echo "$KEYS" >>$HOME/.ssh/authorized_keys
fi
}
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
}
install_openstack_clients() {
echo ">>> Installing openstack clients"
pip3 install python-openstackclient
pip3 install python-barbicanclient
}
install_gcloud_cli() {
echo ">>> Installing gcloud cli"
rm -rf $HOME/google-cloud-sdk
curl https://sdk.cloud.google.com >/tmp/install-gcloud-cli.sh
bash /tmp/install-gcloud-cli.sh --disable-prompts
$HOME/google-cloud-sdk/bin/gcloud components install --quiet gke-gcloud-auth-plugin
}
switch_to_zsh() {
echo ">>> Setting Zsh as the default shell"
sudo chsh -s /bin/zsh "$(whoami)"
}
main "$@"