-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
76 lines (62 loc) · 1.91 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
#!/bin/bash
# This script installs the ipshield deploy to /usr/local/bin/ipshield from Github release
args=("$@")
custom_version=${args[0]}
# Function to detect latest GitHub release
get_latest_release() {
local repo=$1
curl -s "https://api.github.com/repos/${repo}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}
if [ -z "$custom_version" ]; then
custom_version=$(get_latest_release "scmmishra/ipshield")
fi
# Function to detect platform, architecture, etc.
detect_platform() {
OS=$(uname -s)
ARCH=$(uname -m)
case $OS in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*)
echo "Unsupported operating system: $OS"
exit 1
;;
esac
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64 | arm64) ARCH="arm64" ;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
echo "Detected platform: $OS $ARCH"
}
# Function to download file from GitHub release
download_from_github() {
local repo=$1
local release=$2
local name=$3
local release_without_prefix=${release#v}
local filename=${name}_${release_without_prefix}_${OS}_${ARCH}.tar.gz
# Construct download URL
local download_url="https://github.com/${repo}/releases/download/${release}/${filename}"
# Use curl to download the file quietly
echo "Downloading ${name} ${release} from GitHub release"
curl -sL -o "${filename}" "${download_url}"
# Determine the binary directory
local binary_dir=""
if [ "$OS" == "linux" ] || [ "$OS" == "darwin" ]; then
binary_dir="/usr/local/bin"
fi
echo "Installing ${name}"
sudo tar -xzvf "${filename}" --exclude='LICENSE' --exclude='README.md' -C "${binary_dir}" &> /dev/null
# Make the binary executable
sudo chmod +x "${binary_dir}/ipshield"
# Cleanup
rm "${filename}"
echo "${name} installed successfully to ${binary_dir}/ipshield"
}
echo "// IPShield //"
detect_platform
download_from_github "scmmishra/ipshield" $custom_version "ipshield"