-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
install.sh
executable file
·179 lines (136 loc) · 3.49 KB
/
install.sh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# curl https://github.com/srevinsaju/zap/raw/main/install.sh | sh
# A Bash Script to auto fetch latest release from srevinsaju/zap releases
# Error Handling
# Pipefall instead of error checks to retain original error
set -euo pipefail
echo
echo "####################"
echo
echo '~ ZAP Installer ~'
echo
echo "####################"
echo
# Config
REPO="srevinsaju/zap"
# Architecture
if [ -z ${ARCH+x} ]; then
MACHINE_ARCH="$(uname -m)"
if [ "$MACHINE_ARCH" = "amd64" ]; then
ARCH="amd64"
elif [ "$MACHINE_ARCH" = "x86_64" ]; then
ARCH="amd64"
elif [ "$MACHINE_ARCH" = "i386" ]; then
ARCH="386"
elif [ "$MACHINE_ARCH" = "i686" ]; then
ARCH="386" # both are 32bit, should be compatible
elif [ "$MACHINE_ARCH" = "aarch64" ]; then
ARCH="arm64"
elif [ "$MACHINE_ARCH" = "arm64" ]; then
ARCH="arm64"
elif [ "$MACHINE_ARCH" = "arm" ]; then
ARCH="arm"
fi
export ARCH
fi
echo "[~] Platform Arch: $ARCH"
echo
echo "[~] Requirements Check:"
# required: curl
if ! command -v curl &>/dev/null; then
echo
echo [!] Command curl is required. Please install curl.
exit 1
else
echo -e [OK] curl
fi
# required: grep
if ! command -v grep &>/dev/null; then
echo
echo [!] Command grep was not found. Please install package containing grep tool.
exit 1
else
echo -e [OK] grep
fi
# required: jq
if ! command -v jq &>/dev/null; then
echo
echo [!] Command jq was not found. Please install jq from your package manager....
echo
echo refer to https://github.com/stedolan/jq for instruction and downloads.
echo
exit 1
else
echo -e [OK] jq
fi
if [ "$(which wget)" ]; then
echo -e [OK] wget \(optional\)
fi
echo
# Get releases
RELEASE_API_URL="https://api.github.com/repos/$REPO/releases"
echo [~] Getting Latest zap release....
RELEASES="$(curl -sN $RELEASE_API_URL)"
# RELEASES="$(cat r.json)"
# List releases
COMPATIBLE_RELEASE="$(echo "$RELEASES" | jq -rc '.[].assets[].browser_download_url' | grep -m 1 "$ARCH")"
if [ -z "$COMPATIBLE_RELEASE" ]; then
echo [!] No compatible releases found....
exit 1
fi
echo
echo [~] Found latest zap version....
echo
# Download release
echo [~] Downloading....
echo "[>] Download URL: $COMPATIBLE_RELEASE"
echo
TEMP_FILE="$(mktemp /tmp/zap.installer.XXXXXXXXXX)"
if [ -z "$(which wget)" ]; then
echo [~] Using Curl
echo
curl -L "$COMPATIBLE_RELEASE" -o "$TEMP_FILE"
else
echo [~] wget is available, using wget.
echo
wget "$COMPATIBLE_RELEASE" -O "$TEMP_FILE"
fi
echo
# Installation
# Root and No Root
if [ "$EUID" -eq 0 ]; then
echo [~] Script is running as root.
echo
echo [~] Installing System-Wide
sudo mv "$TEMP_FILE" /usr/local/bin/zap
sudo chmod +x /usr/local/bin/zap
# Done
echo [~] Done....
else
echo [~] Script is not running as root user
echo
echo '[~] Installing Locally to ~/.local/bin/'
mkdir -p ~/.local/bin
mv "$TEMP_FILE" ~/.local/bin/zap
chmod +x ~/.local/bin/zap
# Add to $PATH
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo '[~] Adding ~/.local/bin to $PATH'
PATH="$PATH:$HOME/.local/bin/"
if [ -f ~/.zshrc ]; then
echo '[~] Adding .local/bin to ~/.zshrc'
echo "# Added by zap installation script" >> ~/.zshrc
echo "PATH=\$PATH:\$HOME/.local/bin/" >> ~/.zshrc
fi
if [ -f ~/.bashrc ]; then
echo '[~] Adding .local/bin to ~/.bashrc'
echo "# Added by zap installation script" >> ~/.bashrc
echo "PATH=\$PATH:\$HOME/.local/bin" >> ~/.bashrc
fi
fi
# Done
echo [~] Done....
fi
# Installation Complete
echo
echo [~] Installation Complete....