-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdncat-uninstall.sh
69 lines (55 loc) · 1.69 KB
/
dncat-uninstall.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
#!/bin/bash
#
# DESCRIPTION
# DotnetCat uninstaller script for ARM64 and x64 Linux systems.
# REPOSITORY
# https://github.com/vandavey/DotnetCat
APP_DIR="/opt/dncat"
BIN_DIR="${APP_DIR}/bin"
# Write an error message to stderr and exit.
error() {
echo -e "\033[91m[x]\033[0m ${*}" >&2
exit 1
}
# Write a status message to stdout.
status() {
echo -e "\033[96m[*]\033[0m ${*}"
}
# Remove the bin directory environment path export from a file.
remove_bin_export() {
local line_num
local line="export PATH=\"\${PATH}:${BIN_DIR}\""
if [[ -f $1 ]] && grep -q "${line}" "${1}"; then
line_num=$(cat -n "${1}" | grep "${line}" | awk '{print $1}')
if [[ -n $line_num ]]; then
if ! sed -i "${line_num}d" "${1}"; then
error "Failed to remove path export at '${1}':${line_num}"
fi
status "Removed environment path export at '${1}':${line_num}"
fi
fi
}
ARCH=$(uname -m)
# Validate CPU architecture
if [[ ! $ARCH =~ ^(aarch64|x86_64)$ ]]; then
error "Unsupported processor architecture: '${ARCH}'"
fi
# Require elevated shell privileges
if ! sudo -n true 2> /dev/null; then
status "Elevated shell privileges required..."
if ! sudo -v; then
error "Failed to elevate shell privileges"
fi
fi
# Remove all application files
if [[ -d $APP_DIR ]]; then
status "Removing application files from '${APP_DIR}'..."
if ! sudo rm -rv $APP_DIR; then
error "Failed to remove application files from '${APP_DIR}'"
fi
else
status "No application files to remove from '${APP_DIR}'"
fi
remove_bin_export ~/.bashrc
remove_bin_export ~/.zshrc
status "DotnetCat was successfully uninstalled"