fix a bunch or errors

1. Better EOF
2. Shellchecked the code
This commit is contained in:
Daniel Hansson 2023-10-02 12:57:33 +02:00 committed by GitHub
parent f60fcb61e6
commit 4a70bb3540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,21 +11,22 @@
# Get username # Get username
usern=$(whoami) usern=$(whoami)
admintoken=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c16) admintoken=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c16)
export admintoken
ARCH=$(uname -m) ARCH=$(uname -m)
# Identify OS # Identify OS
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
# freedesktop.org and systemd # freedesktop.org and systemd
. /etc/os-release # shellcheck source=/dev/null
source /etc/os-release
OS=$NAME OS=$NAME
VER=$VERSION_ID VER=$VERSION_ID
UPSTREAM_ID=${ID_LIKE,,} UPSTREAM_ID=${ID_LIKE,,}
# Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian' # Fallback to ID_LIKE if ID was not 'ubuntu' or 'debian'
if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ]; then if [ "${UPSTREAM_ID}" != "debian" ] && [ "${UPSTREAM_ID}" != "ubuntu" ]; then
UPSTREAM_ID="$(echo ${ID_LIKE,,} | sed s/\"//g | cut -d' ' -f1)" UPSTREAM_ID="$(echo "${ID_LIKE,,}" | sed s/\"//g | cut -d' ' -f1)"
fi fi
elif type lsb_release >/dev/null 2>&1; then elif type lsb_release >/dev/null 2>&1; then
@ -34,7 +35,8 @@ elif type lsb_release >/dev/null 2>&1; then
VER=$(lsb_release -sr) VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command # For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release # shellcheck source=/dev/null
source /etc/os-release
OS=$DISTRIB_ID OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then elif [ -f /etc/debian_version ]; then
@ -66,24 +68,24 @@ fi
# Setup prereqs for server # Setup prereqs for server
# Common named prereqs # Common named prereqs
PREREQ="curl wget unzip tar" PREREQ=(curl wget unzip tar)
PREREQDEB="dnsutils ufw" PREREQDEB=(dnsutils ufw)
PREREQRPM="bind-utils" PREREQRPM=(bind-utils)
PREREQARCH="bind" PREREQARCH=(bind)
echo "Installing prerequisites" echo "Installing prerequisites"
if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then
sudo apt-get update sudo apt-get update
sudo apt-get install -y ${PREREQ} ${PREREQDEB} # git sudo apt-get install -y "${PREREQ[@]}" "${PREREQDEB[@]}" # git
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] ; then elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] || [ "${OS}" = "Almalinux" ] || [ "${UPSTREAM_ID}" = "Rocky*" ] ; then
# openSUSE 15.4 fails to run the relay service and hangs waiting for it # openSUSE 15.4 fails to run the relay service and hangs waiting for it
# Needs more work before it can be enabled # Needs more work before it can be enabled
# || [ "${UPSTREAM_ID}" = "suse" ] # || [ "${UPSTREAM_ID}" = "suse" ]
sudo yum update -y sudo yum update -y
sudo yum install -y ${PREREQ} ${PREREQRPM} # git sudo yum install -y "${PREREQ[@]}" "${PREREQRPM[@]}" # git
elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ]; then elif [ "${ID}" = "arch" ] || [ "${UPSTREAM_ID}" = "arch" ]; then
sudo pacman -Syu sudo pacman -Syu
sudo pacman -S ${PREREQ} ${PREREQARCH} sudo pacman -S "${PREREQ[@]}" "${PREREQARCH[@]}"
else else
echo "Unsupported OS" echo "Unsupported OS"
# Here you could ask the user for permission to try and install anyway # Here you could ask the user for permission to try and install anyway
@ -113,7 +115,7 @@ RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server-pro/releas
echo "Installing RustDesk Server" echo "Installing RustDesk Server"
if [ "${ARCH}" = "x86_64" ] ; then if [ "${ARCH}" = "x86_64" ] ; then
wget https://github.com/rustdesk/rustdesk-server-pro/releases/download/${RDLATEST}/rustdesk-server-linux-amd64.tar.gz wget https://github.com/rustdesk/rustdesk-server-pro/releases/download/"${RDLATEST}"/rustdesk-server-linux-amd64.tar.gz
tar -xf rustdesk-server-linux-amd64.tar.gz tar -xf rustdesk-server-linux-amd64.tar.gz
mv amd64/static /var/lib/rustdesk-server/ mv amd64/static /var/lib/rustdesk-server/
sudo mv amd64/hbbr /usr/bin/ sudo mv amd64/hbbr /usr/bin/
@ -150,7 +152,11 @@ fi
sudo chown "${usern}" -R /var/log/rustdesk-server/ sudo chown "${usern}" -R /var/log/rustdesk-server/
# Setup systemd to launch hbbs # Setup systemd to launch hbbs
rustdeskhbbs="$(cat << EOF if [ ! -f "/etc/systemd/system/rustdesk-hbbs.service" ]
then
rm -f "/etc/systemd/system/rustdesk-hbbs.service"
rm -f "/etc/systemd/system/rustdesk-hbbs.service"
cat << HBBS_RUSTDESK_SERVICE > "/etc/systemd/system/rustdesk-hbbs.service"
[Unit] [Unit]
Description=RustDesk Signal Server Description=RustDesk Signal Server
[Service] [Service]
@ -167,15 +173,18 @@ StandardError=append:/var/log/rustdesk-server/hbbs.error
RestartSec=10 RestartSec=10
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF HBBS_RUSTDESK_SERVICE
)" fi
echo "${rustdeskhbbs}" | sudo tee /etc/systemd/system/rustdesk-hbbs.service > /dev/null
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable rustdesk-hbbs.service sudo systemctl enable rustdesk-hbbs.service
sudo systemctl start rustdesk-hbbs.service sudo systemctl start rustdesk-hbbs.service
# Setup systemd to launch hbbr # Setup systemd to launch hbbr
rustdeskhbbr="$(cat << EOF if [ ! -f "/etc/systemd/system/rustdesk-hbbr.service" ]
then
rm -f "/etc/systemd/system/rustdesk-hbbr.service"
rm -f "/etc/systemd/system/rustdesk-hbbr.service"
cat << HBBR_RUSTDESK_SERVICE > "/etc/systemd/system/rustdesk-hbbr.service"
[Unit] [Unit]
Description=RustDesk Relay Server Description=RustDesk Relay Server
[Service] [Service]
@ -192,9 +201,8 @@ StandardError=append:/var/log/rustdesk-server/hbbr.error
RestartSec=10 RestartSec=10
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF HBBR_RUSTDESK_SERVICE
)" fi
echo "${rustdeskhbbr}" | sudo tee /etc/systemd/system/rustdesk-hbbr.service > /dev/null
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable rustdesk-hbbr.service sudo systemctl enable rustdesk-hbbr.service
sudo systemctl start rustdesk-hbbr.service sudo systemctl start rustdesk-hbbr.service
@ -235,7 +243,7 @@ break
"DNS/Domain") "DNS/Domain")
echo -ne "Enter your preferred domain/DNS address ${NC}: " echo -ne "Enter your preferred domain/DNS address ${NC}: "
read wanip read -r wanip
# Check wanip is valid domain # Check wanip is valid domain
if ! [[ $wanip =~ ^[a-zA-Z0-9]+([a-zA-Z0-9.-]*[a-zA-Z0-9]+)?$ ]]; then if ! [[ $wanip =~ ^[a-zA-Z0-9]+([a-zA-Z0-9.-]*[a-zA-Z0-9]+)?$ ]]; then
echo -e "${RED}Invalid domain/DNS address${NC}" echo -e "${RED}Invalid domain/DNS address${NC}"
@ -264,22 +272,24 @@ else
exit 1 exit 1
fi fi
rustdesknginx="$( if [ ! -f "/etc/nginx/sites-available/rustdesk.conf" ]
cat <<EOF then
rm -f "/etc/nginx/sites-available/rustdesk.conf"
rm -f "/etc/nginx/sites-enabled/rustdesk.conf"
cat << NGINX_RUSTDESK_CONF > "/etc/nginx/sites-available/rustdesk.conf"
server { server {
server_name ${wanip}; server_name ${wanip};
location / { location / {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:21114/; proxy_pass http://127.0.0.1:21114/;
}
} }
} NGINX_RUSTDESK_CONF
EOF fi
)"
echo "${rustdesknginx}" | sudo tee /etc/nginx/sites-available/rustdesk.conf >/dev/null
sudo rm /etc/nginx/sites-available/default sudo rm -f /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/rustdesk.conf /etc/nginx/sites-enabled/rustdesk.conf sudo ln -s /etc/nginx/sites-available/rustdesk.conf /etc/nginx/sites-enabled/rustdesk.conf
@ -288,7 +298,7 @@ sudo ufw allow 443/tcp
sudo ufw enable && ufw reload sudo ufw enable && ufw reload
sudo certbot --nginx -d ${wanip} sudo certbot --nginx --cert-name "${wanip}" --key-type ecdsa --renew-by-default --no-eff-email --agree-tos --server https://acme-v02.api.letsencrypt.org/directory -d "${wanip}"
break break
;; ;;