forked from meshery/meshery
/
meshery
106 lines (88 loc) · 3.08 KB
/
meshery
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
# Copyright 2019 Layer5 Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#!/usr/bin/env bash
####### COMMON FUNCTIONS
############################
command_exists() {
command -v $1 >/dev/null 2>&1
}
####### IDENTIFY OS
############################
OSARCHITECTURE="$(uname -m)"
OS="$(uname)"
if [ "x${OS}" = "xDarwin" ] ; then
OSEXT="Darwin"
else
OSEXT="Linux"
fi
####### PREFLIGHT CHECK
############################
if ! command_exists curl ; then
echo "Missing required utility: 'curl'. Please install 'curl' and try again."
exit;
fi
if [ "x${MESHERY_VERSION}" = "x" ] ; then
MESHERY_VERSION=$(curl -L -s https://api.github.com/repos/layer5io/meshery/releases | \
grep tag_name | sed "s/ *\"tag_name\": *\"\\(.*\\)\",*/\\1/" | \
grep -v "rc\.[0-9]$"| head -n 1 )
fi
if [ "x${MESHERY_VERSION}" = "x" ] ; then
printf "Unable to get latest mesheryctl version. Set MESHERY_VERSION env var and re-run. For example: export MESHERY_VERSION=v0.1.6"
exit;
fi
NAME="mesheryctl-${MESHERY_VERSION}"
URL="https://github.com/layer5io/meshery/releases/download/${MESHERY_VERSION}/mesheryctl_${MESHERY_VERSION:1}_${OSEXT}_${OSARCHITECTURE}.zip"
printf "\nDownloading %s for %s...\n\n" "$NAME" "$OSEXT"
curl -L ${URL} -o ${PWD}/meshery.zip
printf "\nExtracting %s...\n" "$NAME"
unzip -o ${PWD}/meshery.zip
# Use user provided installation path from env variable(MESHERY_INSTALL_DIR)
# by default its /usr/local/bin
install_dir=${MESHERY_INSTALL_DIR}
if [ -z "$install_dir" ]
then
install_dir="/usr/local/bin"
fi
printf "\nInstalling mesheryctl in $install_dir.\n"
WHOAMI=$(whoami)
if mv ${PWD}/mesheryctl $install_dir/mesheryctl ; then
echo "mesheryctl installed."
else
if sudo mv ${PWD}/mesheryctl $install_dir/mesheryctl ; then
echo "Permission Resolved: mesheryctl installed using sudo permissions."
else
echo "Cannot install mesheryctl. Check permissions of $WHOAMI for $install_dir."
exit 1
fi
fi
#Transfering permissions and ownership to client USER
if [ "$SUDO_USER" == "" ] ;
then
if chown $WHOAMI $install_dir/mesheryctl ; then
echo "permissions moved to "$WHOAMI
else
echo "Unable to write to $install_dir. Please verify write permission for $WHOAMI."
exit 1
fi
else
if chown $SUDO_USER /usr/local/bin/mesheryctl ; then
echo "permissions moved to "$SUDO_USER
else
echo "Unable to write to $install_dir/mesheryctl. Please verify write permission for $SUDO_USER."
exit 1
fi
fi
printf "Removing installation files and opening Meshery..."
rm -rf meshery.zip LICENSE README.md
mesheryctl system start --yes