Merge branch 'main' into patch-1

This commit is contained in:
Daniel Hansson 2023-10-05 08:22:32 +02:00 committed by GitHub
commit 240404a35f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 357 additions and 1 deletions

118
lib.sh
View File

@ -6,13 +6,20 @@ true
############ Variables
# PATH & DIR
RUSTDESK_INSTALL_DIR=/var/lib/rustdesk-server
RUSTDESK_LOG_DIR=/var/log/rustdesk-server
# OS
ARCH=$(uname -m)
TITLE="RustDesk Linux installer"
get_wanip4() {
WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org)
}
# Whiptail menus
TITLE="RustDesk - $(date +%Y)"
[ -n "$SCRIPT_NAME" ] && TITLE+=" - $SCRIPT_NAME"
CHECKLIST_GUIDE="Navigate with the [ARROW] keys and (de)select with the [SPACE] key. \
Confirm by pressing [ENTER]. Cancel by pressing [ESC]."
MENU_GUIDE="Navigate with the [ARROW] keys and confirm by pressing [ENTER]. Cancel by pressing [ESC]."
############ Functions
@ -95,6 +102,115 @@ input_box_flow() {
echo "$RESULT"
}
identify_os() {
if [ -f /etc/os-release ]
then
# freedesktop.org and systemd
# shellcheck source=/dev/null
source /etc/os-release
OS=$NAME
VER=$VERSION_ID
UPSTREAM_ID=${ID_LIKE,,}
# Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian'
if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ]
then
UPSTREAM_ID="$(echo "${ID_LIKE,,}" | sed s/\"//g | cut -d' ' -f1)"
fi
elif type lsb_release >/dev/null 2>&1
then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]
then
# For some versions of Debian/Ubuntu without lsb_release command
# shellcheck source=/dev/null
source /etc/os-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]
then
# Older Debian, Ubuntu, etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSE-release ]
then
# Older SuSE, etc.
OS=SuSE
VER=$(cat /etc/SuSE-release)
elif [ -f /etc/redhat-release ]
then
# Older Red Hat, CentOS, etc.
OS=RedHat
VER=$(cat /etc/redhat-release)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
}
install_linux_package() {
# Install based on OS
# osInfo[/etc/redhat-release]=yum
# osInfo[/etc/arch-release]=pacman
# osInfo[/etc/gentoo-release]=emerge
# osInfo[/etc/SuSE-release]=zypp
# osInfo[/etc/debian_version]=apt-get
# osInfo[/etc/alpine-release]=apk
if [ -x "$(command -v apt-get)" ]
then
sudo apt-get install "${1}" -y
elif [ -x "$(command -v apk)" ]
then
sudo apk add --no-cache "${1}"
elif [ -x "$(command -v dnf)" ]
then
sudo dnf install "${1}"
elif [ -x "$(command -v zypper)" ]
then
sudo zypper install "${1}"
elif [ -x "$(command -v pacman)" ]
then
sudo pacman -S install "${1}"
elif [ -x "$(command -v yum)" ]
then
sudo yum install "${1}"
elif [ -x "$(command -v emerge)" ]
then
sudo emerge -av "${1}"
else
echo "FAILED TO INSTALL ${1}! Package manager not found: Your OS is currently unsupported."
fi
}
purge_linux_package() {
if [ -x "$(command -v apt-get)" ]
then
sudo apt-get purge --autoremove -y "${1}"
elif [ -x "$(command -v apk)" ]
then
sudo apk del "${1}"
elif [ -x "$(command -v dnf)" ]
then
sudo dnf purge "${1}"
elif [ -x "$(command -v zypper)" ]
then
sudo zypper remove "${1}"
elif [ -x "$(command -v pacman)" ]
then
sudo pacman -Rs "${1}"
elif [ -x "$(command -v yum)" ]
then
sudo yum remove "${1}"
elif [ -x "$(command -v emerge)" ]
then
sudo emerge -Cv "${1}"
else
echo "FAILED TO REMOVE ${1}! Package manager not found: Your OS is currently unsupported."
fi
}
## bash colors
# Reset

240
uninstall.sh Normal file
View File

@ -0,0 +1,240 @@
#!/bin/bash
##################################################################################################################
if [[ "$EUID" -ne 0 ]]
then
echo "Sorry, you are not root. You now have two options:"
echo
echo "1. Use SUDO directly:"
echo " a) :~$ sudo bash install.sh"
echo
echo "2. Become ROOT and then type your command:"
echo " a) :~$ sudo -i"
echo " b) :~# bash install.sh"
echo
echo "More information can be found here: https://unix.stackexchange.com/a/3064"
exit 1
fi
# Download the lib file
if ! curl -fSL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh -o lib.sh
then
echo "Failed to download the lib.sh file. Please try again"
exit 1
fi
# shellcheck disable=2034,2059,2164
true
SCRIPT_NAME="Uninstall Script"
# shellcheck source=lib.sh
source lib.sh
# Output debugging info if $DEBUG set
if [ "$DEBUG" = "true" ]
then
identify_os
print_text_in_color "$ICyan" "OS: $OS"
print_text_in_color "$ICyan" "VER: $VER"
print_text_in_color "$ICyan" "UPSTREAM_ID: $UPSTREAM_ID"
exit 0
fi
# Switch for Certbot
if [ -d /etc/letsencrypt ]
then
CERTBOT_SWITCH=ON
else
CERTBOT_SWITCH=OFF
fi
# Uninstall Rustdesk Menu
choice=$(whiptail --title "$TITLE" --checklist \
"What do you want to uninstall?
$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"curl" "(Removes curl:// linux package)" OFF \
"nginxconf" "(Removes Rustdesk Nginx config)" OFF \
"nginxall" "(Removes *everything* releated to Nginx)" ON \
"wget" "(Removes wget linux package)" ON \
"unzip" "(Removes unzip linux package)" ON \
"whiptail" "(Removes whiptail linux package)" ON \
"dnsutils" "(Removes dnsutils linux package)" ON \
"bind-utils" "(Removes bind-utils linux package)" ON \
"bind" "(Removes bind linux package)" ON \
"UFW" "(Removes UFW linux package plus rules)" ON \
"Rustdesk LOGs" "(Removes RustDesk log dir)" ON \
"Rustdesk Server" "(Removes Rustdesk server + services)" ON \
"Certbot" "(Removes Certbot package plus Let's Encrypt)" "$CERTBOT_SWITCH" 3>&1 1>&2 2>&3)
case "$choice" in
*"curl"*)
REMOVE_CURL="yes"
;;&
*"nginxconf"*)
REMOVE_NGINX_CONF="yes"
;;&
*"nginxall"*)
REMOVE_NGINX_ALL="yes"
;;&
*"wget"*)
REMOVE_WGET="yes"
;;&
*"unzip"*)
REMOVE_UNZIP="yes"
;;&
*"whiptail"*)
REMOVE_WHIPTAIL="yes"
;;&
*"dnsutils"*)
REMOVE_DNSUTILS="yes"
;;&
*"bind-utils"*)
REMOVE_BIND_UTILS="yes"
;;&
*"bind"*)
REMOVE_BIND="yes"
;;&
*"UFW"*)
REMOVE_UFW="yes"
;;&
*"Rustdesk LOGs"*)
REMOVE_RUSTDESK_LOG="yes"
;;&
*"Rustdesk SERVER"*)
REMOVE_RUSTDESK_SERVER="yes"
;;&
*"Certbot"*)
REMOVE_CERTBOT="yes"
;;&
*)
;;
esac
msg_box "WARNING WARNING WARNING
This script will remove EVERYTHING that was you chose in the previous selection.
You can choose to opt out after you hit OK."
if ! yesno_box_no "Are you REALLY sure you want to continue with the uninstallation?"
then
exit 0
fi
if [ -n "$UFW" ]
then
# Deleting UFW rules
ufw delete allow 21115:21119/tcp
# ufw delete 22/tcp # If connected to a remote VPS, this deletion will make the connection go down
ufw delete allow 21116/udp
if [ -f "/etc/nginx/sites-available/rustdesk.conf" ]
then
ufw delete allow 80/tcp
ufw delete allow 443/tcp
else
ufw delete allow 21114/tcp
fi
ufw disable
ufw reload
fi
# Rustdesk Server
if [ -n "$REMOVE_RUSTDESK_SERVER" ]
then
# Rustdesk installation dir
print_text_in_color "$IGreen" "Removing RustDesk Server..."
rm -rf "$RUSTDESK_INSTALL_DIR"
rm -rf /usr/bin/hbbr
rm -rf /usr/bin/hbbr
# systemctl services
# HBBS
systemctl disable rustdesk-hbbs.service
systemctl stop rustdesk-hbbs.service
rm -f "/etc/systemd/system/rustdesk-hbbs.service"
# HBBR
systemctl disable rustdesk-hbbr.service
systemctl stop rustdesk-hbbr.service
rm -f "/etc/systemd/system/rustdesk-hbbr.service"
# daemon-reload
systemctl daemon-reload
fi
# Rustdesk LOG
if [ -n "$REMOVE_RUSTDESK_LOG" ]
then
# Rustdesk LOG dir
rm -rf "$RUSTDESK_LOG_DIR"
fi
# Certbot
if [ -n "$REMOVE_CERTBOT" ]
then
if snap list | grep -q certbot > /dev/null
then
purge_linux_package snap
snap remove certbot
else
purge_linux_package python3-certbot-nginx -y
fi
# Also remove the actual certs
rm -rf /etc/letsencrypt
fi
# Nginx
if [ -n "$REMOVE_NGINX_CONF" ]
then
rm -f "/etc/nginx/sites-available/rustdesk.conf"
rm -f "/etc/nginx/sites-enabled/rustdesk.conf"
service nginx restart
elif [ -n "$REMOVE_NGINX_ALL" ]
then
purge_linux_package nginx
rm -rf "/etc/nginx"
fi
# The rest
if [ -n "$REMOVE_CURL" ]
then
purge_linux_package curl
fi
if [ -n "$REMOVE_WGET" ]
then
purge_linux_package wget
fi
if [ -n "$REMOVE_UNZIP" ]
then
purge_linux_package unzip
fi
if [ -n "$REMOVE_DNSUTILS" ]
then
purge_linux_package dnsutils
fi
if [ -n "$REMOVE_BIND_UTILS" ]
then
purge_linux_package bind-utils
fi
if [ -n "$REMOVE_BIND" ]
then
purge_linux_package bind
fi
if [ -n "$REMOVE_UFW" ]
then
purge_linux_package ufw
fi
msg_box "Uninstallation complete!
Please hit OK to remove the last file."
if [ -n "$REMOVE_WHIPTAIL" ]
then
purge_linux_package whiptail
fi
rm -f lib.sh