added unattended installation options

This commit is contained in:
carefreepineapple 2023-09-19 15:56:08 -04:00
parent e1a9a2f8dc
commit d4da69dd84

View File

@ -1,5 +1,38 @@
#!/bin/bash #!/bin/bash
# Get user options
while getopts i:-: option; do
case "${option}" in
-)
case "${OPTARG}" in
help)
help="true";;
resolveip)
resolveip="true";;
resolvedns)
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
resolvedns=${val};;
install-http)
http="true";;
skip-http)
http="false";;
esac;;
i) resolveip="true";;
esac
done
function displayhelp() {
if [[ ! -z $help ]]; then
echo 'usage: install.sh --resolveip --resolvedns "fqdn"'
echo "options:"
echo "--resolveip Use IP for server name. Cannot use in combination with --resolvedns or -d"
echo '--resolvedns "fqdn" Use FQDN for server name. Cannot use in combination with --resolveip or -i'
echo "--install-http Install http server to host installation scripts. Cannot use in combination with --skip-http or -n"
echo "--skip-http Skip installation of http server. Cannot use in combination with --install-http or -h"
exit 0
fi
}
displayhelp
# 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)
@ -93,28 +126,41 @@ else
fi fi
# Choice for DNS or IP # Choice for DNS or IP
PS3='Choose your preferred option, IP or DNS/Domain:' if [[ -z "$resolveip" && -z "$resolvedns" ]]; then
WAN=("IP" "DNS/Domain") PS3='Choose your preferred option, IP or DNS/Domain:'
select WANOPT in "${WAN[@]}"; do WAN=("IP" "DNS/Domain")
case $WANOPT in select WANOPT in "${WAN[@]}"; do
"IP") case $WANOPT in
wanip=$(dig @resolver4.opendns.com myip.opendns.com +short) "IP")
break wanip=$(dig @resolver4.opendns.com myip.opendns.com +short)
;; 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 #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}"
exit 1
fi
break
;;
*) echo "invalid option $REPLY";;
esac
done
elif [[ ! -z "$resolveip" && ! -z "$resolvedns" ]]; then
echo -e "\nERROR: You cannot use both --resolveip & --resolvedns options simultaneously"
exit 1 exit 1
elif [[ ! -z "$resolveip" && -z "$resolvedns" ]]; then
wanip=$(dig @resolver4.opendns.com myip.opendns.com +short)
elif [[ -z "$resolveip" && ! -z "$resolvedns" ]]; then
wanip="$resolvedns"
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
fi fi
break
;;
*) echo "invalid option $REPLY";;
esac
done
# Make Folder /opt/rustdesk/ # Make Folder /opt/rustdesk/
if [ ! -d "/opt/rustdesk" ]; then if [ ! -d "/opt/rustdesk" ]; then
@ -225,70 +271,63 @@ rm rustdesk-server-linux-arm64v8.zip
rm -rf arm64v8 rm -rf arm64v8
fi fi
function setuphttp () {
# Create windows install script
wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/WindowsAgentAIOInstall.ps1
sudo sed -i "s|wanipreg|${wanip}|g" WindowsAgentAIOInstall.ps1
sudo sed -i "s|keyreg|${key}|g" WindowsAgentAIOInstall.ps1
# Choice for Extras installed # Create linux install script
PS3='Please choose if you want to download configs and install HTTP server:' wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/linuxclientinstall.sh
EXTRA=("Yes" "No") sudo sed -i "s|wanipreg|${wanip}|g" linuxclientinstall.sh
select EXTRAOPT in "${EXTRA[@]}"; do sudo sed -i "s|keyreg|${key}|g" linuxclientinstall.sh
case $EXTRAOPT in
"Yes")
# Create windows install script # Download and install gohttpserver
wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/WindowsAgentAIOInstall.ps1 # Make Folder /opt/gohttp/
sudo sed -i "s|wanipreg|${wanip}|g" WindowsAgentAIOInstall.ps1 if [ ! -d "/opt/gohttp" ]; then
sudo sed -i "s|keyreg|${key}|g" WindowsAgentAIOInstall.ps1 echo "Creating /opt/gohttp"
sudo mkdir -p /opt/gohttp/
sudo mkdir -p /opt/gohttp/public
fi
sudo chown "${uname}" -R /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) }')
# Create linux install script echo "Installing Go HTTP Server"
wget https://raw.githubusercontent.com/dinger1986/rustdeskinstall/master/linuxclientinstall.sh if [ "${ARCH}" = "x86_64" ] ; then
sudo sed -i "s|wanipreg|${wanip}|g" linuxclientinstall.sh wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz"
sudo sed -i "s|keyreg|${key}|g" linuxclientinstall.sh tar -xf gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz
elif [ "${ARCH}" = "aarch64" ] ; then
wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_arm64.tar.gz"
tar -xf gohttpserver_${GOHTTPLATEST}_linux_arm64.tar.gz
elif [ "${ARCH}" = "armv7l" ] ; then
echo "Go HTTP Server not supported on 32bit ARM devices"
echo -e "Your IP/DNS Address is ${wanip}"
echo -e "Your public key is ${key}"
exit 1
fi
# Download and install gohttpserver # Copy Rustdesk install scripts to folder
# Make Folder /opt/gohttp/ mv /opt/rustdesk/WindowsAgentAIOInstall.ps1 /opt/gohttp/public/
if [ ! -d "/opt/gohttp" ]; then mv /opt/rustdesk/linuxclientinstall.sh /opt/gohttp/public/
echo "Creating /opt/gohttp"
sudo mkdir -p /opt/gohttp/
sudo mkdir -p /opt/gohttp/public
fi
sudo chown "${uname}" -R /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) }')
echo "Installing Go HTTP Server" # Make gohttp log folders
if [ "${ARCH}" = "x86_64" ] ; then if [ ! -d "/var/log/gohttp" ]; then
wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz" echo "Creating /var/log/gohttp"
tar -xf gohttpserver_${GOHTTPLATEST}_linux_amd64.tar.gz sudo mkdir -p /var/log/gohttp/
elif [ "${ARCH}" = "aarch64" ] ; then fi
wget "https://github.com/codeskyblue/gohttpserver/releases/download/${GOHTTPLATEST}/gohttpserver_${GOHTTPLATEST}_linux_arm64.tar.gz" sudo chown "${uname}" -R /var/log/gohttp/
tar -xf gohttpserver_${GOHTTPLATEST}_linux_arm64.tar.gz
elif [ "${ARCH}" = "armv7l" ] ; then
echo "Go HTTP Server not supported on 32bit ARM devices"
echo -e "Your IP/DNS Address is ${wanip}"
echo -e "Your public key is ${key}"
exit 1
fi
# Copy Rustdesk install scripts to folder echo "Tidying up Go HTTP Server Install"
mv /opt/rustdesk/WindowsAgentAIOInstall.ps1 /opt/gohttp/public/ if [ "${ARCH}" = "x86_64" ] ; then
mv /opt/rustdesk/linuxclientinstall.sh /opt/gohttp/public/ rm gohttpserver_"${GOHTTPLATEST}"_linux_amd64.tar.gz
elif [ "${ARCH}" = "armv7l" ] || [ "${ARCH}" = "aarch64" ]; then
# Make gohttp log folders rm gohttpserver_"${GOHTTPLATEST}"_linux_arm64.tar.gz
if [ ! -d "/var/log/gohttp" ]; then fi
echo "Creating /var/log/gohttp"
sudo mkdir -p /var/log/gohttp/
fi
sudo chown "${uname}" -R /var/log/gohttp/
echo "Tidying up Go HTTP Server Install"
if [ "${ARCH}" = "x86_64" ] ; then
rm gohttpserver_"${GOHTTPLATEST}"_linux_amd64.tar.gz
elif [ "${ARCH}" = "armv7l" ] || [ "${ARCH}" = "aarch64" ]; then
rm gohttpserver_"${GOHTTPLATEST}"_linux_arm64.tar.gz
fi
# Setup Systemd to launch Go HTTP Server # Setup Systemd to launch Go HTTP Server
gohttpserver="$(cat << EOF gohttpserver="$(cat << EOF
[Unit] [Unit]
Description=Go HTTP Server Description=Go HTTP Server
[Service] [Service]
@ -307,46 +346,64 @@ 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}" | sudo tee /etc/systemd/system/gohttpserver.service > /dev/null
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable gohttpserver.service sudo systemctl enable gohttpserver.service
sudo systemctl start gohttpserver.service sudo systemctl start gohttpserver.service
echo -e "Your IP/DNS Address is ${wanip}" echo -e "Your IP/DNS Address is ${wanip}"
echo -e "Your public key is ${key}" echo -e "Your public key is ${key}"
echo -e "Install Rustdesk on your machines and change your public key and IP/DNS name to the above" echo -e "Install Rustdesk on your machines and change your public key and IP/DNS name to the above"
echo -e "You can access your install scripts for clients by going to http://${wanip}:8000" echo -e "You can access your install scripts for clients by going to http://${wanip}:8000"
echo -e "Username is admin and password is ${admintoken}" echo -e "Username is admin and password is ${admintoken}"
if [[ -z "$http" ]]; then
echo "Press any key to finish install"
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
exit ;
else
echo "waiting for the keypress"
fi
done
break
fi
}
echo "Press any key to finish install" # Choice for Extras installed
while [ true ] ; do if [[ -z "$http" ]]; then
read -t 3 -n 1 PS3='Please choose if you want to download configs and install HTTP server:'
if [ $? = 0 ] ; then EXTRA=("Yes" "No")
exit ; select EXTRAOPT in "${EXTRA[@]}"; do
else case $EXTRAOPT in
echo "waiting for the keypress" "Yes")
setuphttp
break
;;
"No")
echo -e "Your IP/DNS Address is ${wanip}"
echo -e "Your public key is ${key}"
echo -e "Install Rustdesk on your machines and change your public key and IP/DNS name to the above"
echo "Press any key to finish install"
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
exit ;
else
echo "waiting for the keypress"
fi
done
break
;;
*) echo "invalid option $REPLY";;
esac
done
elif [ "$http" = "true" ]; then
setuphttp
elif [ "$http" = "false" ]; then
echo -e "Your IP/DNS Address is ${wanip}"
echo -e "Your public key is ${key}"
echo -e "Install Rustdesk on your machines and change your public key and IP/DNS name to the above"
fi fi
done
break
;;
"No")
echo -e "Your IP/DNS Address is ${wanip}"
echo -e "Your public key is ${key}"
echo -e "Install Rustdesk on your machines and change your public key and IP/DNS name to the above"
echo "Press any key to finish install"
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
exit ;
else
echo "waiting for the keypress"
fi
done
break
;;
*) echo "invalid option $REPLY";;
esac
done