-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1clk.sh
executable file
·66 lines (58 loc) · 1.89 KB
/
1clk.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
version="1.0.2"
installation_path="$HOME/.local/bin/egressguy"
version_file="$installation_path/.version"
binary_file="$installation_path/release"
# check cpu architecture
if [ "$(uname -m)" == "x86_64" ]; then
goarch="amd64"
# elif [ "$(uname -m)" == "aarch64" ]; then
# goarch="arm64"
else
echo "Unsupported architecture: $(uname -m), please install manually."
exit 1
fi
# we had to notify the user for every command that requires root privileges
privileged_command() {
echo "Executing command: $@"
if [ "$EUID" -ne 0 ]; then
sudo $@ || exit 1
else
$@ || exit 1
fi
}
# check whether libpcap is installed
if [ ! -f /usr/include/pcap.h ] && [ ! -f /usr/share/licenses/libpcap/LICENSE ] && [ ! -f /usr/lib/libpcap.so ]; then
if [ -f /etc/debian_version ]; then
privileged_command "apt install libpcap-dev"
elif [ -f /etc/redhat-release ]; then
privileged_command "yum install libpcap"
elif [ -f /etc/arch-release ]; then
privileged_command "pacman -S libpcap"
else
echo "libpcap is not installed. Please install it manually."
exit 1
fi
fi
download_latest_release() {
curl https://github.com/hax0r31337/egressguy/releases/download/$version/egressguy_linux_$goarch -L -o $binary_file || exit 1
# check ELF header to ensure the binary is valid
if [ "$(head -c 4 $binary_file)" != $'\x7fELF' ]; then
echo "Failed to download egressguy binary."
rm -f $binary_file
exit 1
fi
chmod +x $binary_file
echo $version > $version_file
}
# download binary from github releases
if [ ! -f $version_file ] || [ ! -f $binary_file ]; then
mkdir -p $installation_path
download_latest_release
else
current_version=$(cat $version_file)
if [ "$current_version" != "$version" ]; then
download_latest_release
fi
fi
# run the binary
privileged_command "$binary_file $@"