-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-rancher-cli
107 lines (93 loc) · 3.82 KB
/
install-rancher-cli
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
#!/bin/bash
## local variables
RANCHER_CLI_VERSION='v2.0.5'
RANCHER_REPO='https://github.com/rancher/cli'
OPERATING_SYSTEM=$(uname -s)
case "${OPERATING_SYSTEM}" in
Linux*)
DISTRO_TYPE='linux'
RANCHER_DISTRO='rancher-linux-amd64';;
Darwin*)
DISTRO_TYPE='unix'
RANCHER_DISTRO='rancher-darwin-amd64';;
CYGWIN*)
DISTRO_TYPE='windows'
RANCHER_DISTRO='rancher-windows-amd64';;
MINGW*)
DISTRO_TYPE='windows'
RANCHER_DISTRO='rancher-windows-amd64';;
*)
echo ''
echo 'Error: operating system not known, please open an issue:'
echo ''
echo 'https://github.com/jeff1evesque/machine-learning/issues/new'
echo ''
exit 1
esac
## download rancher-cli
if [ "$DISTRO_TYPE" = 'unix' ]; then
curl -OL "$RANCHER_REPO/releases/download/$RANCHER_CLI_VERSION/$RANCHER_DISTRO-$RANCHER_CLI_VERSION.tar.gz"
tar zxf "$RANCHER_DISTRO-$RANCHER_CLI_VERSION.tar.gz"
rm "$RANCHER_DISTRO-$RANCHER_CLI_VERSION.tar.gz"
sudo mv rancher-"$RANCHER_CLI_VERSION"/rancher /usr/local/bin/rancher
sudo chmod +x /usr/local/bin/rancher
elif [ "$DISTRO_TYPE" = 'linux' ]; then
if ! type curl &>/dev/null; then
sudo apt-get -y install curl || sudo yum -y install curl || (echo 'curl cannot install' && exit 1)
fi
curl -OL "$RANCHER_REPO/releases/download/$RANCHER_CLI_VERSION/$RANCHER_DISTRO-$RANCHER_CLI_VERSION.tar.gz"
tar zxf "$RANCHER_DISTRO-$RANCHER_CLI_VERSION.tar.gz"
rm "$RANCHER_DISTRO-$RANCHER_CLI_VERSION.tar.gz"
sudo mv rancher-"$RANCHER_CLI_VERSION"/rancher /usr/local/bin/rancher
sudo chmod +x /usr/local/bin/rancher
elif [ "$DISTRO_TYPE" = 'windows' ]; then
WINDOWS_CURRENT_VERSION=$(
powershell.exe \
-NoProfile -InputFormat None -ExecutionPolicy Bypass \
-Command "((
Get-ItemProperty -path 'HKLM:\software\microsoft\Windows NT\CurrentVersion'
).ProductName).split(' ')[1]"
)
curl -OL "$RANCHER_REPO/releases/download/$RANCHER_CLI_VERSION/$RANCHER_DISTRO-$RANCHER_CLI_VERSION.zip"
unzip -j "$RANCHER_DISTRO-$RANCHER_CLI_VERSION.zip"
mkdir -p /c/programdata/rancher/bin
mv -f rancher.exe /c/programdata/rancher/bin
rm "$RANCHER_DISTRO-$RANCHER_CLI_VERSION.zip"
## install python
command -v python >/dev/null 2>&1 || INSTALL_PYTHON=true
if [[ $OPERATING_SYSTEM == MINGW* ]] && [[ $INSTALL_PYTHON == true ]]; then
PYTHON_VERSION=$(echo ${PYTHON_VERSION_FULL%.*} | tr --delete .)
while [[ "$INSTALL_PYTHON" != 'y' ]] && [[ "$INSTALL_PYTHON" != 'n' ]]
do
echo ''
echo "Windows (MINGW*) installation for rancher-cli,"
echo "depends on 'choco', and 'python'."
echo ''
echo '[Y]: install'
echo '[N]: do not install'
echo ''
read -rp 'Proceed with installation: ' INSTALL_PYTHON
done
if [ "${INSTALL_PYTHON,,}" = 'y' ]; then
powershell.exe -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
"
## current process
PATH="$PATH:/c/programdata/chocolatey/bin:/c/programdata/rancher/bin:/c/python$PYTHON_VERSION"
## successive processes
setx PATH "%PATH%;C:\programdata\chocolatey\bin;C:\programdata\rancher\bin;C:\python$PYTHON_VERSION"
## install python
choco install -f python --version "$PYTHON_VERSION_FULL"
else
echo 'terminating rancher installation...'
exit 0
fi
fi
else
echo ''
echo 'Error: distro not known, please open an issue:'
echo ''
echo 'https://github.com/jeff1evesque/machine-learning/issues/new'
echo ''
exit 1
fi