2018-04-19 21:33:15 +02:00
#!/bin/bash
2020-07-26 20:29:54 +02:00
XOCE_URL = https://nc.nl.tab.digital/s/5tKYF9AyLjowm3E/download
2019-01-19 17:49:33 +01:00
2018-04-19 21:33:15 +02:00
# Welcome message
printf "\n\033[1mWelcome to the XOCE auto-deploy script!\033[0m\n\n"
if ! which xe 2> /dev/null >& 2
then
echo
echo 'Sorry, the xe command is required for this auto-deploy.'
echo
2020-12-21 21:25:56 +01:00
echo 'Please, make sure you are on a XCP-ng/XenServer host.'
2018-04-19 21:33:15 +02:00
echo
exit 1
fi
# Basic check: are we on a XS host?
if grep -Fxq "XenServer" /etc/issue
then
2020-12-21 21:25:56 +01:00
printf "\nSorry, it seems you are not on a XCP-ng/XenServer host.\n\n"
printf "\n\033[1mThis script is meant to be deployed on XCP-ng or XenServer only.\033[0m\n\n"
2018-04-19 21:33:15 +02:00
exit 1
fi
# Initial choice on network settings: fixed IP or DHCP? (default)
printf "Network settings:\n"
read -p "IP address? [dhcp] " ip
ip = ${ ip :- dhcp }
if [ " $ip " != 'dhcp' ]
then
read -p "Netmask? [255.255.255.0] " netmask
netmask = ${ netmask :- 255 .255.255.0 }
read -p "Gateway? " gateway
read -p "dns? [8.8.8.8] " dns
dns = ${ dns :- 8 .8.8.8 }
else
2020-12-21 21:25:56 +01:00
printf "\nYour XOCE installation will be started using DHCP\n\n"
2018-04-19 21:33:15 +02:00
fi
# Downloading and importing the VM
printf "Importing XOCE VM…\n"
uuid = $( xe vm-import url = " $XOCE_URL " 2> /dev/null)
# If it fails (it means XS < 7.0)
# We'll use the curl
import = $?
if [ $import -ne 0 ]
then
uuid = $( curl " $XOCE_URL " | xe vm-import filename = /dev/stdin 2>& 1)
fi
# If it fails again (for any reason), we stop the script
import = $?
if [ $import -ne 0 ]
then
2020-12-21 21:25:56 +01:00
printf "\n\nAuto deploy failed. Please contact us on https://github.com/Jarli01/xenorchestra_installer/issues for assistance.\nError:\n\n %s\n\n" " $uuid "
2018-04-19 21:33:15 +02:00
exit 0
fi
# If static IP selected, fill the xenstore
if [ " $ip " != 'dhcp' ]
then
xe vm-param-set uuid = $uuid xenstore-data:vm-data/ip= $ip xenstore-data:vm-data/netmask= $netmask xenstore-data:vm-data/gateway= $gateway xenstore-data:vm-data/dns= $dns
fi
# Starting the VM
printf "Booting XOCE VM…\n"
xe vm-start uuid = $uuid
sleep 2
# Waiting for the VM IP from Xen tools for 60 secs
2020-12-21 21:25:56 +01:00
printf "Waiting for XOCE to be ready…\n"
2018-04-19 21:33:15 +02:00
url = $( xe vm-param-get uuid = $uuid param-name= networks param-key= 0/ip 2> /dev/null)
wait = 0
limit = 60
while [ -z " $url " -a " $wait " -lt " $limit " ]
do
let wait = wait+1
sleep 1
url = $( xe vm-param-get uuid = $uuid param-name= networks param-key= 0/ip 2> /dev/null)
done
# End of the process. Display the XOCE URL if possible
# If we use a fixed IP but on a DHCP enabled network
# We don't want to get the first IP displayed by the tools
# But the fixed one
if [ " $ip " != 'dhcp' ]
then
2020-12-21 21:25:56 +01:00
printf "\n\033[1mYour XOCE is ready at https://%s/\033[0m\n" " $ip "
2018-04-19 21:33:15 +02:00
# clean the xenstore data
xe vm-param-remove param-name= xenstore-data param-key= vm-data/dns param-key= vm-data/ip param-key= vm-data/netmask param-key= vm-data/gateway uuid = $uuid
# If we can't fetch the IP from tools
elif [ -z " $url " ]
then
printf "\n\033[1mYour XOCE booted but we couldn't fetch its IP address\033[0m\n"
else
2020-12-21 21:25:56 +01:00
printf "\n\033[1mYour XOCE is ready at https://%s/\033[0m\n" " $url "
2018-04-19 21:33:15 +02:00
fi
printf "\nDefault UI credentials: admin@admin.net/admin\nDefault console credentials: xoce/xoce\n"
printf "\nVM UUID: %s\n\n" " $uuid "