This repository has been archived by the owner on Apr 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
/
setup.tmpl
executable file
·66 lines (61 loc) · 2.71 KB
/
setup.tmpl
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
set -e
PLATFORM="$(uname -s | tr '[:upper:]' '[:lower:]')"
KUBERNETES_VERSION=__KUBERNETES_VERSION__
KUB_URL="https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/${PLATFORM}/amd64/kubectl"
scream () {
cat <<< "$@" 1>&2
exit 1
}
case "$PLATFORM" in
darwin|linux)
targetDir="/usr/local/bin"
if [[ -r /etc/os-release ]]; then
. /etc/os-release
if [[ $ID = coreos ]]; then
targetDir="/opt/bin"
unlink $HOME/.bash_profile
cp /usr/share/skel/.bash_profile $HOME/.bash_profile
chmod 775 $HOME/.bash_profile
fi
fi
;;
*)
scream "Unknown or unsupported platform: ${PLATFORM}"
;;
esac
if [[ "$#" -eq 1 && "$1" == "install" ]] ; then
echo "Downloading and installing ${PLATFORM} version of 'kubectl' v${KUBERNETES_VERSION} into ${targetDir}. This may take a couple minutes, depending on your internet speed.."
[ -d ${targetDir} ] || sudo mkdir -p ${targetDir}
sudo -E wget -q --no-check-certificate -L -O ${targetDir}/kubectl "${KUB_URL}"
[ -x ${targetDir}/kubectl ] || sudo chmod +x ${targetDir}/kubectl
# use sed to replace current values, if any; create profile file if not exists
touch -a $HOME/.bash_profile
echo "Setting environment variables.."
if ! grep -q 'export FLEETCTL_ENDPOINT' $HOME/.bash_profile ; then
echo "export FLEETCTL_ENDPOINT=http://__MASTER_IP__:4001" >> $HOME/.bash_profile
else
sed -i'*' 's|.*export FLEETCTL_ENDPOINT.*|export FLEETCTL_ENDPOINT=http://__MASTER_IP__:4001|' $HOME/.bash_profile
fi
if ! grep -q 'export KUBERNETES_MASTER=http://__MASTER_IP__:8080' $HOME/.bash_profile ; then
echo "export KUBERNETES_MASTER=http://__MASTER_IP__:8080" >> $HOME/.bash_profile
else
sed -i'*' 's|.*export KUBERNETES_MASTER.*|export KUBERNETES_MASTER=http://__MASTER_IP__:8080|' $HOME/.bash_profile
fi
__PROXY_LINE__if ! grep -q 'export NO_PROXY' $HOME/.bash_profile ; then
__PROXY_LINE__ echo "export NO_PROXY=__NO_PROXY__" >> $HOME/.bash_profile
__PROXY_LINE__ echo "export no_proxy=__NO_PROXY__" >> $HOME/.bash_profile
__PROXY_LINE__else
__PROXY_LINE__ sed -i'*' 's|.*export NO_PROXY.*|export NO_PROXY=__NO_PROXY__|' $HOME/.bash_profile
__PROXY_LINE__ sed -i'*' 's|.*export no_proxy.*|export no_proxy=__NO_PROXY__|' $HOME/.bash_profile
__PROXY_LINE__fi
export FLEETCTL_ENDPOINT=http://__MASTER_IP__:4001
export KUBERNETES_MASTER=http://__MASTER_IP__:8080
__PROXY_LINE__export NO_PROXY=__NO_PROXY__
__PROXY_LINE__export no_proxy=__NO_PROXY__
elif [[ "$#" -eq 1 && "$1" == "uninstall" ]] ; then
echo "Removing 'kubectl' v${KUBERNETES_VERSION}.."
[ -f ${targetDir}/kubectl ] && sudo rm -f ${targetDir}/kubectl
else
echo "Usage: ./setup (install|uninstall)"
fi