-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-witness-cli
executable file
·129 lines (104 loc) · 3.19 KB
/
install-witness-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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
APP_NAME="witness"
export VERSION=`curl --silent -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/witnesschain-com/dcl-operator-cli/releases/latest | grep tag_name| cut -d "\"" -f 4`
echo "${APP_NAME} version: " $VERSION
RELEASE_URL="https://github.com/witnesschain-com/dcl-operator-cli/releases/download/$VERSION"
print_hr() {
local length=${1:-30} # Default length of the horizontal line
local char=${2:-"-"} # Default character for the line
for ((i=1; i<=$length; i++)); do
printf "%s" "$char"
done
printf "\n"
}
print_title() {
local title="$1"
local length=${#title}
print_hr $length "="
echo "$title"
print_hr $length "="
}
print_error() {
local message="$@"
printf "%s" "$(tput setaf 1)$message$(tput sgr0)" >&2
}
print_info() {
local message="$@"
printf "%s" "$(tput setaf 3)$message$(tput sgr0)"
}
print_success() {
local message="$@"
printf "%s" "$(tput setaf 2)$message$(tput sgr0)"
}
print_hr 40
printf "\n"
print_title "Setting up WitnessChain CLI"
printf "\n- Platform Details:\n"
PLATFORM=$(uname)
ARCH=$(uname -m)
if [ "$PLATFORM" = "Linux" ] && [ "$ARCH" = "x86_64" ]; then
print_success " Operating System: Linux"
printf "\n"
print_success " Architecture: x86_64"
printf "\n"
BINARY_NAME="witness_linux_x86_64"
elif [ "$PLATFORM" = "Darwin" ] && [ "$ARCH" = "arm64" ]; then
print_success " Operating Systems: macOS\n"
printf "\n"
print_success " Architecture: arm64\n"
printf "\n"
BINARY_NAME="witness_apple_silicon"
else
print_error " Unable to identify platform for the binaries, please setup manually"
printf "\n"
print_hr 40
exit 1
fi
mkdir -p ~/.witnesschain
if [ $? != 0 ]; then
print_info " 🟡 Unable to create .witnesschain directory at home, going forward with current directory\n\n"
PATH_TO_CLI="."
fi
cd "$PATH_TO_CLI" || exit
mkdir -p config
printf "\n\n- 🏃 Downloading $APP_NAME...\n"
curl -# -fSL -o "$APP_NAME" "$RELEASE_URL/$BINARY_NAME"
if [ $? = 0 ]; then
print_success " ✅ Download completed. "
else
print_error " ❌ Error downloading the binaries. exiting.."
printf "\n"
print_hr 40
exit 1
fi
chmod +x "$APP_NAME"
if [ $? != 0 ]; then
print_error " Unable to set executable permission for $PWD/$APP_NAME"
printf "\n"
print_hr 40
exit 1
fi
mkdir -p ~/.local/bin
if [ $? != 0 ]; then
print_error " Unable to create ~/.local/bin"
printf "\n"
print_hr 40
exit 1
fi
mv "$APP_NAME" ~/.local/bin/
if [ $? = 0 ]; then
print_success "Installation successful. $APP_NAME installed in $HOME/.local/bin/"
printf "\n\n\n"
else
print_error "Unable to move $APP_NAME to ~/.local/bin "
printf "\n"
print_hr 40
exit 1
fi
print_info "Please start a new terminal session if following commands does not work."
print_info "Add export PATH=~/.local/bin/:\$PATH in your ~/.bashrc file for bash shell or ~/.zshrc for zsh shell. Then restart the terminal."
printf "\n\n"
print_info "Run the following command to test your installation:"
printf "\n\n"
print_info "$APP_NAME --version"
printf "\n\n\n"