Merge pull request #43 from amyipdev/master

install.sh: quality-of-life improvements
This commit is contained in:
dinger1986
2023-07-20 09:30:32 +01:00
committed by GitHub

View File

@@ -1,5 +1,15 @@
#!/bin/bash #!/bin/bash
# If any command fails, fail out
set -e
# Many things here need root access, so verify user is root
# If not, fail out and give an explanation
if [ $(id -u) -ne 0 ]; then
echo "error: must be root (use sudo)"
exit 1
fi
# Get Username # Get Username
uname=$(whoami) uname=$(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)
@@ -67,23 +77,30 @@ 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 apt-get update
sudo apt-get install -y ${PREREQ} ${PREREQDEB} # git apt-get install -y ${PREREQ} ${PREREQDEB} # git
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] ; then elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] ; 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 yum update -y
sudo yum install -y ${PREREQ} ${PREREQRPM} # git 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 # give them the option to continue
# if they say yes, then do the install echo -n "Would you like to continue? Dependencies may not be satisfied... [y/n] "
# if they say no, exit the script read continue_no_dependencies
exit 1 if [ $continue_no_dependencies == "y" ]; then
echo "Continuing..."
elif [ $continue_no_dependencies != "n" ]; then
echo "Invalid answer, exiting."
exit 1
else
exit 1
fi
fi fi
# Choice for DNS or IP # Choice for DNS or IP
@@ -113,9 +130,9 @@ done
# Make Folder /opt/rustdesk/ # Make Folder /opt/rustdesk/
if [ ! -d "/opt/rustdesk" ]; then if [ ! -d "/opt/rustdesk" ]; then
echo "Creating /opt/rustdesk" echo "Creating /opt/rustdesk"
sudo mkdir -p /opt/rustdesk/ mkdir -p /opt/rustdesk/
fi fi
sudo chown "${uname}" -R /opt/rustdesk chown "${uname}" -R /opt/rustdesk
cd /opt/rustdesk/ || exit 1 cd /opt/rustdesk/ || exit 1
@@ -144,9 +161,9 @@ chmod +x /opt/rustdesk/hbbr
# Make Folder /var/log/rustdesk/ # Make Folder /var/log/rustdesk/
if [ ! -d "/var/log/rustdesk" ]; then if [ ! -d "/var/log/rustdesk" ]; then
echo "Creating /var/log/rustdesk" echo "Creating /var/log/rustdesk"
sudo mkdir -p /var/log/rustdesk/ mkdir -p /var/log/rustdesk/
fi fi
sudo chown "${uname}" -R /var/log/rustdesk/ chown "${uname}" -R /var/log/rustdesk/
# Setup Systemd to launch hbbs # Setup Systemd to launch hbbs
rustdesksignal="$(cat << EOF rustdesksignal="$(cat << EOF
@@ -168,10 +185,10 @@ RestartSec=10
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
)" )"
echo "${rustdesksignal}" | sudo tee /etc/systemd/system/rustdesksignal.service > /dev/null echo "${rustdesksignal}" | tee /etc/systemd/system/rustdesksignal.service > /dev/null
sudo systemctl daemon-reload systemctl daemon-reload
sudo systemctl enable rustdesksignal.service systemctl enable rustdesksignal.service
sudo systemctl start rustdesksignal.service systemctl start rustdesksignal.service
# Setup Systemd to launch hbbr # Setup Systemd to launch hbbr
rustdeskrelay="$(cat << EOF rustdeskrelay="$(cat << EOF
@@ -193,13 +210,13 @@ RestartSec=10
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
)" )"
echo "${rustdeskrelay}" | sudo tee /etc/systemd/system/rustdeskrelay.service > /dev/null echo "${rustdeskrelay}" | tee /etc/systemd/system/rustdeskrelay.service > /dev/null
sudo systemctl daemon-reload systemctl daemon-reload
sudo systemctl enable rustdeskrelay.service systemctl enable rustdeskrelay.service
sudo systemctl start rustdeskrelay.service systemctl start rustdeskrelay.service
while ! [[ $CHECK_RUSTDESK_READY ]]; do while ! [[ $CHECK_RUSTDESK_READY ]]; do
CHECK_RUSTDESK_READY=$(sudo systemctl status rustdeskrelay.service | grep "Active: active (running)") CHECK_RUSTDESK_READY=$(systemctl status rustdeskrelay.service | grep "Active: active (running)")
echo -ne "Rustdesk Relay not ready yet...${NC}\n" echo -ne "Rustdesk Relay not ready yet...${NC}\n"
sleep 3 sleep 3
done done
@@ -229,22 +246,22 @@ case $EXTRAOPT in
# Create windows install script # Create windows install script
wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/WindowsAgentAIOInstall.ps1 wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/WindowsAgentAIOInstall.ps1
sudo sed -i "s|wanipreg|${wanip}|g" WindowsAgentAIOInstall.ps1 sed -i "s|wanipreg|${wanip}|g" WindowsAgentAIOInstall.ps1
sudo sed -i "s|keyreg|${key}|g" WindowsAgentAIOInstall.ps1 sed -i "s|keyreg|${key}|g" WindowsAgentAIOInstall.ps1
# Create linux install script # Create linux install script
wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/linuxclientinstall.sh wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/linuxclientinstall.sh
sudo sed -i "s|wanipreg|${wanip}|g" linuxclientinstall.sh sed -i "s|wanipreg|${wanip}|g" linuxclientinstall.sh
sudo sed -i "s|keyreg|${key}|g" linuxclientinstall.sh sed -i "s|keyreg|${key}|g" linuxclientinstall.sh
# Download and install gohttpserver # Download and install gohttpserver
# Make Folder /opt/gohttp/ # Make Folder /opt/gohttp/
if [ ! -d "/opt/gohttp" ]; then if [ ! -d "/opt/gohttp" ]; then
echo "Creating /opt/gohttp" echo "Creating /opt/gohttp"
sudo mkdir -p /opt/gohttp/ mkdir -p /opt/gohttp/
sudo mkdir -p /opt/gohttp/public mkdir -p /opt/gohttp/public
fi fi
sudo chown "${uname}" -R /opt/gohttp chown "${uname}" -R /opt/gohttp
cd /opt/gohttp cd /opt/gohttp
GOHTTPLATEST=$(curl https://api.github.com/repos/codeskyblue/gohttpserver/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }') GOHTTPLATEST=$(curl https://api.github.com/repos/codeskyblue/gohttpserver/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }')
@@ -269,9 +286,9 @@ mv /opt/rustdesk/linuxclientinstall.sh /opt/gohttp/public/
# Make gohttp log folders # Make gohttp log folders
if [ ! -d "/var/log/gohttp" ]; then if [ ! -d "/var/log/gohttp" ]; then
echo "Creating /var/log/gohttp" echo "Creating /var/log/gohttp"
sudo mkdir -p /var/log/gohttp/ mkdir -p /var/log/gohttp/
fi fi
sudo chown "${uname}" -R /var/log/gohttp/ chown "${uname}" -R /var/log/gohttp/
echo "Tidying up Go HTTP Server Install" echo "Tidying up Go HTTP Server Install"
if [ "${ARCH}" = "x86_64" ] ; then if [ "${ARCH}" = "x86_64" ] ; then
@@ -301,10 +318,10 @@ RestartSec=10
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
)" )"
echo "${gohttpserver}" | sudo tee /etc/systemd/system/gohttpserver.service > /dev/null echo "${gohttpserver}" | tee /etc/systemd/system/gohttpserver.service > /dev/null
sudo systemctl daemon-reload systemctl daemon-reload
sudo systemctl enable gohttpserver.service systemctl enable gohttpserver.service
sudo systemctl start gohttpserver.service systemctl start gohttpserver.service
echo -e "Your IP/DNS Address is ${wanip}" echo -e "Your IP/DNS Address is ${wanip}"