-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.sh
executable file
·62 lines (51 loc) · 1.4 KB
/
prepare.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
#!/bin/sh
if [ ! -f "./.bin/kubectl" ]; then
case "$OSTYPE" in
darwin*) os="darwin" ;;
*) os="linux" ;;
esac
case $(uname -m) in
arm64) arch="arm64" ;;
*) arch="amd64" ;;
esac
mkdir -p ./.bin
curl -L https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/$os/$arch/kubectl -o ./.bin/kubectl
chmod +x ./.bin/kubectl
fi
cat > ./.envrc <<'EOL'
export_function() {
local name=$1
local alias_dir=$PWD/.direnv/aliases
mkdir -p "$alias_dir"
PATH_add "$alias_dir"
local target="$alias_dir/$name"
if declare -f "$name" >/dev/null; then
echo "#!$SHELL" > "$target"
declare -f "$name" >> "$target" 2>/dev/null
echo "$name \$*" >> "$target"
chmod +x "$target"
fi
}
kubectl() {
bin_path=$PWD
while [[ "$bin_path" != "" && ! -e "$bin_path/.bin" ]]; do
bin_path=${bin_path%/*}
done
cfg_path=$PWD
while [[ "$cfg_path" != "" && ! -f "$cfg_path/kubeconfig" ]]; do
cfg_path=${cfg_path%/*}
done
ns_path=$PWD
while [[ "$ns_path" != "" && ${ns_path##*/} != "ns-"* ]]; do
ns_path=${ns_path%/*}
done
ns=${ns_path##*/}
if [[ "$ns" == "" ]]; then
ns="default"
fi
$bin_path/.bin/kubectl --kubeconfig=$cfg_path/kubeconfig --namespace=${ns/ns-/} $*
}
export_function kubectl
export SOPS_PGP_FP="1d1a32d148edf1e8a536f7a08a82a50a2df52ee4"
EOL
direnv allow