2016-04-25 15:50:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
[ $(CreoleGet hapy_init_master) == non ] && exit 0
|
|
|
|
|
2016-09-23 14:08:39 +02:00
|
|
|
function error()
|
|
|
|
{
|
|
|
|
MSG=${1}
|
|
|
|
echo "[ERROR][${MSG}]"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_user_home()
|
|
|
|
{
|
|
|
|
HOMEDIR=$(getent passwd ${1} | cut -d ':' -f 6)
|
|
|
|
echo ${HOMEDIR}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_one_auth()
|
|
|
|
{
|
|
|
|
CMD="cat"
|
|
|
|
HOME=$(get_user_home oneadmin)
|
|
|
|
FILE="${HOME}/.one/one_auth"
|
|
|
|
${CMD} ${FILE}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runOneCmd()
|
|
|
|
{
|
|
|
|
local cmd=${1}
|
|
|
|
local opt=${2}
|
|
|
|
local auth=$(get_one_auth)
|
|
|
|
|
|
|
|
$cmd ${opt} --user ${auth%:*} --password ${auth#*:}
|
|
|
|
return ${?}
|
|
|
|
}
|
|
|
|
|
2016-04-25 15:50:15 +02:00
|
|
|
DISKSIZE=$(CreoleGet hapy_init_master_disk_size)
|
|
|
|
DISKNAME="DSK-${DISKSIZE}-Go"
|
|
|
|
DISKDESC="Disque vide de ${DISKSIZE} Go"
|
|
|
|
|
|
|
|
VERSIONISO=$(CreoleGet hapy_init_master_iso_version)
|
|
|
|
MAJORVERSION=${VERSIONISO:0:3}
|
|
|
|
ISONAME="ISO-Eole-${VERSIONISO}-amd64"
|
|
|
|
ISODESC="Image ISO EOLE Stable ${VERSIONISO} 64 bits"
|
2016-09-23 14:08:39 +02:00
|
|
|
ISOURL="http://eole.ac-dijon.fr/pub/iso/EOLE-${MAJORVERSION}/${VERSIONISO}/eole-${VERSIONISO}-alternate-amd64.iso"
|
2016-04-25 15:50:15 +02:00
|
|
|
|
|
|
|
TMPLNAME="InstallEole-${VERSIONISO}-amd64"
|
|
|
|
TMPLDESC="Modèle de VM permettant d'installer un module EOLE ${VERSIONISO} 64 bits (non persistente)"
|
|
|
|
|
2016-04-25 16:17:09 +02:00
|
|
|
#echo "########### suppr ${DISKNAME} ###############"
|
|
|
|
#oneimage delete ${DISKNAME}
|
|
|
|
#echo
|
|
|
|
#echo "########### suppr ${ISONAME} ###################"
|
|
|
|
#oneimage delete ${ISONAME}
|
|
|
|
#echo
|
|
|
|
#echo "########### suppr ${TMPLNAME} ###################"
|
|
|
|
#onetemplate delete ${TMPLNAME}
|
|
|
|
#echo
|
2016-04-25 15:50:15 +02:00
|
|
|
|
|
|
|
#*****************************************************
|
|
|
|
# DISQUE VIDE
|
|
|
|
#*****************************************************
|
2016-09-23 14:08:39 +02:00
|
|
|
if ! runOneCmd "oneimage" "show ${DISKNAME}" &>/dev/null
|
2016-04-25 15:50:15 +02:00
|
|
|
then
|
|
|
|
echo "***** Création de ${DISKNAME} *****"
|
2016-09-23 14:08:39 +02:00
|
|
|
|
|
|
|
## Attention oneimage create --datastore ne fonctionne pas dans runOneCmd ...
|
|
|
|
auth=$(get_one_auth)
|
|
|
|
oneimage create --datastore $(CreoleGet one_ds_image_name) \
|
|
|
|
--name ${DISKNAME} --type DATABLOCK --description "${DISKDESC}" \
|
|
|
|
--size $((${DISKSIZE}*1024)) --prefix vd --driver qcow2 --user ${auth%:*} --password ${auth#*:}
|
|
|
|
|
|
|
|
runOneCmd "oneimage" "chtype ${DISKNAME} OS"
|
2016-04-25 15:50:15 +02:00
|
|
|
else
|
|
|
|
echo "***** ${DISKNAME} existe déjà *****"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|
|
|
|
#*****************************************************
|
|
|
|
# Image ISO EOLE Latest Stable
|
|
|
|
#*****************************************************
|
2016-09-23 14:08:39 +02:00
|
|
|
if ! runOneCmd "oneimage" "show ${ISONAME}" &>/dev/null
|
2016-04-25 15:50:15 +02:00
|
|
|
then
|
2016-10-14 10:17:26 +02:00
|
|
|
echo -ne "***** Création de l'image ${ISONAME} *****\n\n"
|
2016-04-25 15:50:15 +02:00
|
|
|
|
|
|
|
FILE=$(mktemp)
|
|
|
|
cat > ${FILE} <<EOF
|
|
|
|
NAME="${ISONAME}"
|
|
|
|
TYPE="CDROM"
|
|
|
|
DESCRIPTION="${ISODESC}"
|
|
|
|
DEV_PREFIX="hd"
|
2016-10-14 10:17:26 +02:00
|
|
|
PATH="${ISOURL}"
|
2016-04-25 15:50:15 +02:00
|
|
|
PERSISTENT="No"
|
|
|
|
EOF
|
2016-09-23 14:08:39 +02:00
|
|
|
runOneCmd "oneimage" "create -d $(CreoleGet one_ds_iso_name) ${FILE}"
|
2016-04-25 15:50:15 +02:00
|
|
|
/bin/rm -f ${FILE}
|
2016-10-14 10:17:26 +02:00
|
|
|
|
|
|
|
spin='-\|/'
|
|
|
|
i=0
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
imgState=$(runOneCmd "oneimage" "show ${ISONAME}" | awk '{if ($1 == "STATE") {print $3}}')
|
|
|
|
if [[ ${imgState} == "lock" ]]
|
|
|
|
then
|
|
|
|
i=$(( (i+1) %4 ))
|
|
|
|
printf "\rInitialisation en cours, merci de patienter [${spin:$i:1}] "
|
|
|
|
sleep 2
|
|
|
|
else
|
|
|
|
printf "\r Création terminée, l'image a le statut : ${imgState}\n"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2016-04-25 15:50:15 +02:00
|
|
|
rm -f "/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
|
|
|
|
else
|
|
|
|
echo "***** ${ISONAME} existe déjà *****"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
|
|
#*****************************************************
|
|
|
|
# Template EOLEBASE
|
|
|
|
#*****************************************************
|
|
|
|
if ! onetemplate show "${TMPLNAME}" &>/dev/null
|
|
|
|
then
|
|
|
|
echo "***** Création de ${TMPLNAME} *****"
|
|
|
|
FILE=$(mktemp)
|
|
|
|
cat > ${FILE} <<EOF
|
|
|
|
NAME="${TMPLNAME}"
|
|
|
|
DESCRIPTION="${TMPLDESC}"
|
|
|
|
INPUT=[BUS="usb",TYPE="tablet"]
|
|
|
|
CPU="0.2"
|
|
|
|
DISK=[DEV_PREFIX="vd",IMAGE_UNAME="oneadmin",IMAGE="${DISKNAME}",DRIVER="qcow2"]
|
|
|
|
DISK=[DEV_PREFIX="hd",IMAGE_UNAME="oneadmin",IMAGE="${ISONAME}",DRIVER="raw"]
|
2016-12-23 13:33:58 +01:00
|
|
|
FEATURES=[ACPI="yes",PAE="no"]
|
2016-04-25 15:50:15 +02:00
|
|
|
VCPU="1"
|
|
|
|
GRAPHICS=[LISTEN="0.0.0.0",TYPE="vnc",KEYMAP="fr"]
|
2016-09-08 11:28:09 +02:00
|
|
|
OS = [ ARCH = "x86_64", BOOT = "disk0,disk1" ]
|
2016-04-25 15:50:15 +02:00
|
|
|
MEMORY="1024"
|
|
|
|
EOF
|
2016-09-08 11:28:09 +02:00
|
|
|
|
|
|
|
|
2016-04-25 15:50:15 +02:00
|
|
|
#NIC=[MODEL="virtio",NETWORK="CR_eole"]
|
2016-09-23 14:08:39 +02:00
|
|
|
runOneCmd "onetemplate" "create ${FILE}"
|
2016-04-25 15:50:15 +02:00
|
|
|
|
|
|
|
/bin/rm -f ${FILE}
|
|
|
|
else
|
|
|
|
echo "***** ${TMPLNAME} existe déjà *****"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
exit 0
|
|
|
|
|