NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#!/bin/bash

# Exits on first failed command
set -e

# Errors on undefined variable
set -u

XVA_URL=http://xoa.io/xva

# Welcome message
printf "n👋 33[1mWelcome to the XOA auto-deploy script!33[0mnn"

if ! which xe 2> /dev/null >&2
then
echo
echo '🔴 Sorry, the "xe" command is required for this auto-deploy.'
echo
echo '🚀 Please, make sure you are running this script on a XCP-ng host.'
echo
exit 1
fi

# Basic check: are we on a XS/CH/XCP-ng host?
if grep -Fxq "XenServer|Citrix Hypervisor|XCP-ng" /etc/issue
then
printf "n🔴 Sorry, it seems you are not on a XenServer or XCP-ng host.nn"
printf "n🚀 33[1mThis script is meant to be deployed on XenServer or XCP-ng only.33[0mnn"
exit 1
fi

# Initial choice on network settings: fixed IP or DHCP? (default)

printf "⚙️ STEP 1: XOA configuration nn"
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
printf "nYour XOA will be started using DHCPn"
fi

printf 'n'

# Default or custom NTP servers
read -p 'Custom NTP servers (separated by spaces)? [] ' ntp
printf 'n'

# SSH account

printf "xoa SSH account:n"
read -srp "Password? (disabled if empty) " xoaPassword
printf 'nn'

if [ -n "$xoaPassword" ]
then
printf "xoa account will be enablednn"
else
printf "xoa account is disabled, to enable it later see https://xen-orchestra.com/docs/troubleshooting.html#set-or-recover-xoa-vm-passwordnn"
fi

# Downloading and importing the VM

printf "📥 STEP 2: XOA Downloadnn"
printf "Importing XOA VM: this might take a while..."
if ! {
if [ $# -ge 1 ]
then
# import from file
uuid=$(xe vm-import filename="$1" 2>&1)
else
# import from URL
if ! uuid=$(xe vm-import url="$XVA_URL" 2>&1)
then
# if it fails (likely due to XS < 7.0 but maybe HTTP proxy)
# use the curl
uuid=$(curl "$XVA_URL" | xe vm-import filename=/dev/stdin 2>&1)
fi
fi
}
then
printf "nnAuto deploy failed. Please contact us on https://vates.tech/contact for assistance.nError:nn %snn" "$uuid"
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

# If custom NTP servers are provided, fill the xenstore
if [ -n "$ntp" ]
then
xe vm-param-set uuid="$uuid" xenstore-data:vm-data/ntp="$ntp"
fi

if [ -n "$xoaPassword" ]
then
xe vm-param-set uuid="$uuid" xenstore-data:vm-data/system-account-xoa-password="$xoaPassword"
fi

# By default, the deploy script will make sure we boot XOA with a VIF on the mgmt network

networkUuid=$(xe pif-list params=network-uuid minimal=true management=true | cut -d , -f 1)
vifUuid=$(xe vm-vif-list uuid="$uuid" params=uuid minimal=true)

# Warning: vif-move only works from XenServer 7.1 and higher
xe vif-move uuid="$vifUuid" network-uuid="$networkUuid"

# Starting the VM
printf "nn🏁 STEP 3: Starting XOAnn"

printf "Booting XOA VM...n"
xe vm-start uuid="$uuid"
sleep 2

# Waiting for the VM IP from Xen tools for 60 secs

printf "Waiting for your XOA to be ready...n"

# list VM IP addresses and returns the first non link local addresses
#
# IPv6 addresses are enclosed in brackets for use in URL
get_hostname() {
local address addresses i n

IFS=';' read -r -a addresses <<<"$(xe vm-param-get uuid="$uuid" param-name=networks)"

# Bash < 4.4 reports unbound variable if array is empty
set +u
n=${#addresses[@]}
set -u
if [ $n -eq 0 ]
then
return 1
fi

# Remove prefixes and dedup
readarray -t addresses <<<"$(printf '%sn' "${addresses[@]#*': '}" | sort -u)"

for i in "${!addresses[@]}"
do
address=${addresses[$i]}
case "$address" in
fe80:*) # ignore link local address
unset "addresses[$i]"
continue
;;
*:*)
address="[$address]"
;;
esac
addresses[$i]=$address
done

set +u
n=${#addresses[@]}
set -u
if [ $n -eq 0 ]
then
return 1
fi

printf 'n33[1m'
if [ "$ip" = dhcp ]
then
printf "🟢 Your XOA is ready at:n"
for address in "${addresses[@]}"
do
printf " https://%s/n" "$address"
done
else
# 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
printf "🟢 Your XOA is ready at https://%s/n" "$ip"

# clean the xenstore data
xe vm-param-remove uuid="$uuid" param-name=xenstore-data param-key=vm-data/dns param-key=vm-data/ip param-key=vm-data/netmask param-key=vm-data/gateway &> /dev/null
fi
printf '33[0m'
}

wait=0
limit=60
while {
! get_hostname &&
[ "$wait" -lt "$limit" ]
}
do
let wait=wait+1
sleep 1
done

if [ $wait -eq $limit ]
then
printf "n🟠 33[1mYour XOA booted but we couldn't fetch its IP address33[0mn"
fi

printf "nDefault UI credentials: [email protected]/adminn"
printf "nVM UUID: %snn" "$uuid"
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.