diff --git a/lib.sh b/lib.sh index b416c3a..b157cf5 100644 --- a/lib.sh +++ b/lib.sh @@ -8,7 +8,8 @@ true RUSTDESK_INSTALL_DIR=/var/lib/rustdesk-server RUSTDESK_LOG_DIR=/var/log/rustdesk-server - +ARCH=$(uname -m) +TITLE="RustDesk Linux installer" WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org) ############ Functions @@ -66,6 +67,96 @@ 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 ", also works for BSD, etc. + OS=$(uname -s) + VER=$(uname -r) +fi +} + +purge_linux_package() { + # Identify which OS it is + if [ -z "${ID}" ] || [ -z "$OS" ] || [ -z "${UPSTREAM_ID}" ] + then + identify_os + fi + # Purge based on OS + if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] + then + apt-get purge "${1}" -y + apt-get autoremove -y + elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + then + yum purge "${1}" -y + elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + then + pacman -S purge "${1}" + fi +} + +install_linux_package() { + # Identify which OS it is + if [ -z "${ID}" ] || [ -z "$OS" ] || [ -z "${UPSTREAM_ID}" ] + then + identify_os + fi + + # Install based on OS + if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ] + then + apt-get install "${1}" -y + elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] + then + yum install "${1}" -y + elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ] + then + pacman -S install "${1}" + fi +} + + ## bash colors # Reset