-
Notifications
You must be signed in to change notification settings - Fork 308
/
local_install.sh.go
97 lines (79 loc) · 2.49 KB
/
local_install.sh.go
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
// Copyright 2020 PingCAP, Inc.
//
// 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,
// See the License for the specific language governing permissions and
// limitations under the License.
package install
import "io/ioutil"
// WriteLocalInstallScript writes the install script into specified path
func WriteLocalInstallScript(path string) error {
return ioutil.WriteFile(path, []byte(script), 0755)
}
var script = `#!/bin/sh
case $(uname -s) in
Linux|linux) os=linux ;;
Darwin|darwin) os=darwin ;;
*) os= ;;
esac
if [ -z "$os" ]; then
echo "OS $(uname -s) not supported." >&2
exit 1
fi
case $(uname -m) in
amd64|x86_64) arch=amd64 ;;
arm64|aarch64) arch=arm64 ;;
*) arch= ;;
esac
if [ -z "$arch" ]; then
echo "Architecture $(uname -m) not supported." >&2
exit 1
fi
if [ -z "$TIUP_HOME" ]; then
TIUP_HOME=$HOME/.tiup
fi
bin_dir=$TIUP_HOME/bin
mkdir -p "$bin_dir"
script_dir=$(cd $(dirname $0) && pwd)
install_binary() {
tar -zxf "$script_dir/tiup-$os-$arch.tar.gz" -C "$bin_dir" || return 1
# Use the offline root.json
cp "$script_dir/root.json" "$bin_dir" || return 1
# Remove old manifests
rm -rf $TIUP_HOME/manifests
return 0
}
if ! install_binary; then
echo "Failed to download and/or extract tiup archive."
exit 1
fi
chmod 755 "$bin_dir/tiup"
bold=$(tput bold 2>/dev/null)
sgr0=$(tput sgr0 2>/dev/null)
echo "Detected shell: ${bold}$SHELL${sgr0}"
case $SHELL in
*bash*) PROFILE=$HOME/.bash_profile;;
*zsh*) PROFILE=$HOME/.zshrc;;
*) PROFILE=$HOME/.profile;;
esac
echo "Shell profile: ${bold}$PROFILE${sgr0}"
case :$PATH: in
*:$bin_dir:*) : "PATH already contains $bin_dir" ;;
*) printf 'export PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
echo "$PROFILE has been modified to to add tiup to PATH"
echo "open a new terminal or ${bold}source ${PROFILE}${sgr0} to use it"
;;
esac
echo "Installed path: ${bold}$bin_dir/tiup${sgr0}"
echo "==============================================="
echo "1. ${bold}source ${PROFILE}${sgr0}"
echo "2. ${bold}export TIUP_MIRRORS=${script_dir}${sgr0}"
echo "3. Have a try: ${bold}tiup playground${sgr0}"
echo "==============================================="
`