-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfast_krew.sh
executable file
·66 lines (60 loc) · 1.49 KB
/
fast_krew.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
#!/bin/bash
get_index_path()
{
INDEX_BASE=$(kubectl krew version | awk '/IndexPath/{print $2}')
INDEX_PATH=$INDEX_BASE/plugins/$NAME.yaml
echo "$INDEX_PATH"
}
get_plugin_url()
{
NAME=$1
URL=$(grep 'uri: ' "$INDEX_FILE" | grep -Po "https://.*" | grep -Pvi '(darwin)|(windows)|(linux.*386)|(linux.*arm)' | uniq)
echo "$URL"
}
download_use_axel()
{
NUM_CONN=$1
URL=$2
TARGET=$3
BASE_NAME=$(basename "$URL")
echo "axel -n $NUM_CONN -o $TARGET $URL"
axel -n "$NUM_CONN" -o "$TARGET" "$URL"
}
install_plugin()
{
INDEX_FILE=$1
PLUGIN_FILE=$2
echo "kubectl krew install --manifest=$INDEX_FILE --archive=$PLUGIN_FILE"
kubectl krew install --manifest="$INDEX_FILE" --archive="$PLUGIN_FILE"
}
main()
{
if [[ $1 == '-n' ]]; then
shift
NUM_CONN=$1
shift
else
NUM_CONN=100
fi
NAME=$1
if [[ -z $NAME ]]; then
kubectl krew search
exit 0
fi
if kubectl krew list | grep -q "$NAME"; then
echo "Skipping plugin '$NAME', it is already installed"
exit 0
fi
INDEX_FILE=$(get_index_path "$NAME")
if [[ ! -f "$INDEX_FILE" ]]; then
echo "Failed to load plugin '${NAME}' from the index: open ${INDEX_FILE}: no such file or directory"
exit 1
fi
URL=$(get_plugin_url "$NAME")
BASE_NAME=$(basename "$URL")
TARGET=/tmp/"$BASE_NAME"
download_use_axel "$NUM_CONN" "$URL" "$TARGET"
install_plugin "$INDEX_FILE" "$TARGET"
rm -rf "$TARGET"
}
main "$@"