Merge pull request #4 from philclifford/suggestions

rework to script
This commit is contained in:
dinger1986 2022-08-12 15:48:46 +01:00 committed by GitHub
commit d9c5f06e9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 239 additions and 47 deletions

View File

@ -4,6 +4,81 @@
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)
# identify OS
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /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
. /etc/lsb-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
# output ebugging info if $DEBUG set
if [ "$DEBUG" = "true" ]; then
echo "OS: $OS"
echo "VER: $VER"
echo "UPSTREAM_ID: $UPSTREAM_ID"
exit 0
fi
# Setup prereqs for server
# common named prereqs
PREREQ="curl wget unzip tar"
PREREQDEB="dnsutils"
PREREQRPM="bind-utils"
echo "Installing prerequisites"
if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then
sudo apt-get update
sudo apt-get install -y ${PREREQ} ${PREREQDEB} # git
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ] ; then
# opensuse 15.4 fails to run the relay service and hangs waiting for it
# needs more work before it can be enabled
# || [ "${UPSTREAM_ID}" = "suse" ]
sudo yum update -y
sudo yum install -y ${PREREQ} ${PREREQRPM} # git
else
echo "Unsupported OS"
# here you could ask the user for permission to try and install anyway
# if they say yes, then do the install
# if they say no, exit the script
exit 1
fi
# Choice for DNS or IP # Choice for DNS or IP
PS3='Choose your preferred option, IP or DNS/Domain:' PS3='Choose your preferred option, IP or DNS/Domain:'
WAN=("IP" "DNS/Domain") WAN=("IP" "DNS/Domain")
@ -17,25 +92,42 @@ 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 wanip
#check wanip is valid domain
if ! [[ $wanip =~ ^[a-zA-Z0-9]+([a-zA-Z0-9.-]*[a-zA-Z0-9]+)?$ ]]; then
echo -e "${RED}Invalid domain/dns address${NC}"
exit 1
fi
break break
;; ;;
*) echo "invalid option $REPLY";; *) echo "invalid option $REPLY";;
esac esac
done done
# Setup prereqs for server
if [[ $(which yum) ]]; then
sudo yum install unzip -y # #/*
sudo yum install bind-utils -y # Alternatively since case is faster than if then else
sudo yum install tar -y # case ${IDLIKE} in
elif [[ $(which apt) ]]; then # ubuntu|debian)
sudo apt-get update # # Debian/Ubuntu/etc.
sudo apt-get install unzip -y # sudo apt-get update
sudo apt-get install dnsutils -y # sudo apt-get install -y curl wget unzip dnsutils tar # git
sudo apt-get install tar -y # ;;
else # centos|fedora|redhat) #|amazon)
echo "Unknown Platform, the install might fail" # # CentOS/RedHat/Fedora/Amazon/etc.
fi # sudo yum update -y
# sudo yum install -y curl wget unzip bind-utils tar # git
# ;;
# *)
# echo "Unsupported OS"
# echo "Unknown Platform, the install might fail"
# # here you could ask the user for permission to try and install anyway
# # if they say yes, then do the install
# # if they say no, exit the script
# exit 1
# ;;
# esac
# */
# Make Folder /opt/rustdesk/ # Make Folder /opt/rustdesk/
if [ ! -d "/opt/rustdesk" ]; then if [ ! -d "/opt/rustdesk" ]; then
@ -43,11 +135,11 @@ if [ ! -d "/opt/rustdesk" ]; then
sudo mkdir -p /opt/rustdesk/ sudo mkdir -p /opt/rustdesk/
fi fi
sudo chown "${uname}" -R /opt/rustdesk sudo chown "${uname}" -R /opt/rustdesk
cd /opt/rustdesk/ cd /opt/rustdesk/ || exit 1
#Download latest version of Rustdesk #Download latest version of Rustdesk
RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }') RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }')
sudo wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-x64.zip" wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-x64.zip"
unzip rustdesk-server-linux-x64.zip unzip rustdesk-server-linux-x64.zip
# Make Folder /var/log/rustdesk/ # Make Folder /var/log/rustdesk/
@ -113,17 +205,17 @@ while ! [[ $CHECK_RUSTDESK_READY ]]; do
sleep 3 sleep 3
done done
pubname=$(find /opt/rustdesk -name *.pub) pubname=$(find /opt/rustdesk -name "*.pub")
key=$(cat "${pubname}") key=$(cat "${pubname}")
sudo rm rustdesk-server-linux-x64.zip rm rustdesk-server-linux-x64.zip
# 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 sudo sed -i "s|wanipreg|${wanip}|g" WindowsAgentAIOInstall.ps1
sudo sed -i "s|keyreg|${key}|g" WindowsAgentAIOInstall.ps1 sudo 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 sudo sed -i "s|wanipreg|${wanip}|g" linuxclientinstall.sh
sudo sed -i "s|keyreg|${key}|g" linuxclientinstall.sh sudo sed -i "s|keyreg|${key}|g" linuxclientinstall.sh
@ -138,7 +230,7 @@ fi
sudo chown "${uname}" -R /opt/gohttp sudo 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) }')
sudo wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz" wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz"
tar -xf gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz tar -xf gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz
# Copy Rustdesk install scripts to folder # Copy Rustdesk install scripts to folder
@ -152,7 +244,7 @@ if [ ! -d "/var/log/gohttp" ]; then
fi fi
sudo chown "${uname}" -R /var/log/gohttp/ sudo chown "${uname}" -R /var/log/gohttp/
sudo rm gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz rm gohttpserver_"${GOHTTPLATEST}"_linux_amd64.tar.gz
# Setup Systemd to launch Go HTTP Server # Setup Systemd to launch Go HTTP Server
gohttpserver="$(cat << EOF gohttpserver="$(cat << EOF

View File

@ -3,18 +3,62 @@
uname=$(whoami) uname=$(whoami)
admintoken=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c8) admintoken=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c8)
# Install Rustdesk
if [[ $(which yum) ]]; then # identify OS
wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.rpm if [ -f /etc/os-release ]; then
sudo yum localinstall ./rustdesk-1.1.9.rpm # freedesktop.org and systemd
elif [[ $(which apt) ]]; then . /etc/os-release
wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.deb OS=$NAME
sudo apt install -fy ./rustdesk-1.1.9.deb VER=$VERSION_ID
IDLIKE=$ID_LIKE
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
. /etc/lsb-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 else
echo "Unknown Platform, the install will fail" # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
exit OS=$(uname -s)
VER=$(uname -r)
fi fi
# Install Rustdesk
case ${OS,,} in
# or case ${IDLIKE,,} in .. to support derivatives
ubuntu|debian)
# Debian/Ubuntu/etc.
wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.deb
sudo apt install -fy ./rustdesk-1.1.9.deb
;;
fedora|centos|redhat|amazon)
# Red Hat, CentOS, etc.
wget https://github.com/rustdesk/rustdesk/releases/download/1.1.9/rustdesk-1.1.9.rpm
sudo yum localinstall ./rustdesk-1.1.9.rpm
# sudo dnf install -y ./rustdesk-1.1.9.rpm
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
rustdesk --password ${admintoken} rustdesk --password ${admintoken}
pkill -f "rustdesk" pkill -f "rustdesk"
@ -50,12 +94,12 @@ EOF
)" )"
echo "${rustdesktoml2b}" | sudo tee /root/.config/rustdesk/RustDesk2.toml > /dev/null echo "${rustdesktoml2b}" | sudo tee /root/.config/rustdesk/RustDesk2.toml > /dev/null
chown ${uname}:${uname} /home/${uname}/.config/rustdesk/RustDesk2.toml chown ${uname}:${uname} /home/${uname}/.config/rustdesk/RustDesk2.toml
systemctl restart rustdesk systemctl restart rustdesk
echo "ID & Password for Rustdesk $(uname} are:" echo "ID & Password for Rustdesk ${uname} are:"
grep -w id /home/${uname}/.config/rustdesk/RustDesk.toml grep -w id /home/${uname}/.config/rustdesk/RustDesk.toml
grep -w password /home/${uname}/.config/rustdesk/RustDesk.toml grep -w password /home/${uname}/.config/rustdesk/RustDesk.toml

View File

@ -1,23 +1,80 @@
#!/bin/bash #!/bin/bash
# Get Username # Get Username
uname=$(whoami) uname=$(whoami) # not used btw .. yet
sudo systemctl stop gohttpserver.service sudo systemctl stop gohttpserver.service
sudo systemctl stop rustdesksignal.service sudo systemctl stop rustdesksignal.service
sudo systemctl stop rustdeskrelay.service sudo systemctl stop rustdeskrelay.service
# Setup prereqs for server # identify OS
if [[ $(which yum) ]]; then if [ -f /etc/os-release ]; then
sudo yum install unzip -y # freedesktop.org and systemd
sudo yum install bind-utils -y . /etc/os-release
elif [[ $(which apt) ]]; then OS=$NAME
sudo apt-get update VER=$VERSION_ID
sudo apt-get install unzip -y UPSTREAM_ID=${ID_LIKE,,}
sudo apt-get install dnsutils -y # 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
. /etc/lsb-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 else
echo "Unknown Platform, the install might fail" # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
# output ebugging info if $DEBUG set
if [ "$DEBUG" = "true" ]; then
echo "OS: $OS"
echo "VER: $VER"
echo "UPSTREAM_ID: $UPSTREAM_ID"
exit 0
fi
# Setup prereqs for server
# common named prereqs
PREREQ="curl wget unzip tar"
echo "Installing prerequisites"
if [ "${ID}" = "debian" ] || [ "$OS" = "Ubuntu" ] || [ "$OS" = "Debian" ] || [ "${UPSTREAM_ID}" = "ubuntu" ] || [ "${UPSTREAM_ID}" = "debian" ]; then
PREREQ+=" dnsutils"
sudo apt-get update
sudo apt-get install -y "${PREREQ}" # git
elif [ "$OS" = "CentOS" ] || [ "$OS" = "RedHat" ] || [ "${UPSTREAM_ID}" = "rhel" ]; then
PREREQ+=" bind-utils"
sudo yum update -y
sudo yum install -y "${PREREQ}" # git
else
echo "Unsupported OS"
# here you could ask the user for permission to try and install anyway
# if they say yes, then do the install
# if they say no, exit the script
exit 1
fi fi
cd /opt/rustdesk/ cd /opt/rustdesk/
@ -26,7 +83,7 @@ cd /opt/rustdesk/
rm hbbs rm hbbs
rm hbbs rm hbbs
RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }') RDLATEST=$(curl https://api.github.com/repos/rustdesk/rustdesk-server/releases/latest -s | grep "tag_name"| awk '{print substr($2, 2, length($2)-3) }')
sudo wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-x64.zip" wget "https://github.com/rustdesk/rustdesk-server/releases/download/${RDLATEST}/rustdesk-server-linux-x64.zip"
unzip rustdesk-server-linux-x64.zip unzip rustdesk-server-linux-x64.zip
sudo systemctl start rustdesksignal.service sudo systemctl start rustdesksignal.service
@ -38,16 +95,15 @@ while ! [[ $CHECK_RUSTDESK_READY ]]; do
sleep 3 sleep 3
done done
sudo rm rustdesk-server-linux-x64.zip rm rustdesk-server-linux-x64.zip
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) }')
sudo wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz" wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz"
tar -xf gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz tar -xf gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz
sudo rm gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz rm gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz
sudo systemctl start gohttpserver.service sudo systemctl start gohttpserver.service
echo -e "Updates are complete" echo -e "Updates are complete"