Browse Source

Ajout de l'utilisation des options --user --password dans le script d'init

ref #17203 @1h
Philippe Caseiro 2 years ago
parent
commit
33209a8fae
1 changed files with 48 additions and 12 deletions
  1. 48
    12
      postservice/99-init-hapy-master

+ 48
- 12
postservice/99-init-hapy-master View File

@@ -2,6 +2,38 @@
2 2
 
3 3
 [ $(CreoleGet hapy_init_master) == non ] && exit 0
4 4
 
5
+function error()
6
+{
7
+    MSG=${1}
8
+    echo "[ERROR][${MSG}]"
9
+    exit 1
10
+}
11
+
12
+function get_user_home()
13
+{
14
+    HOMEDIR=$(getent passwd ${1} | cut -d ':' -f 6)
15
+    echo ${HOMEDIR}
16
+}
17
+
18
+function get_one_auth()
19
+{
20
+    CMD="cat"
21
+    HOME=$(get_user_home oneadmin)
22
+    FILE="${HOME}/.one/one_auth"
23
+    ${CMD} ${FILE}
24
+}
25
+
26
+function runOneCmd()
27
+{
28
+	local cmd=${1}
29
+	local opt=${2}
30
+	local auth=$(get_one_auth)
31
+
32
+	echo "$cmd ${opt} --user ${auth%:*} --password ${auth#*:}"
33
+	$cmd ${opt} --user ${auth%:*} --password ${auth#*:}
34
+	return ${?}
35
+}
36
+
5 37
 DISKSIZE=$(CreoleGet hapy_init_master_disk_size)
6 38
 DISKNAME="DSK-${DISKSIZE}-Go"
7 39
 DISKDESC="Disque vide de ${DISKSIZE} Go"
@@ -10,6 +42,7 @@ VERSIONISO=$(CreoleGet hapy_init_master_iso_version)
10 42
 MAJORVERSION=${VERSIONISO:0:3}
11 43
 ISONAME="ISO-Eole-${VERSIONISO}-amd64"
12 44
 ISODESC="Image ISO EOLE Stable ${VERSIONISO} 64 bits"
45
+ISOURL="http://eole.ac-dijon.fr/pub/iso/EOLE-${MAJORVERSION}/${VERSIONISO}/eole-${VERSIONISO}-alternate-amd64.iso"
13 46
 
14 47
 TMPLNAME="InstallEole-${VERSIONISO}-amd64"
15 48
 TMPLDESC="Modèle de VM permettant d'installer un module EOLE ${VERSIONISO} 64 bits (non persistente)"
@@ -27,11 +60,17 @@ TMPLDESC="Modèle de VM permettant d'installer un module EOLE ${VERSIONISO} 64 b
27 60
 #*****************************************************
28 61
 # DISQUE VIDE
29 62
 #*****************************************************
30
-if ! oneimage show "${DISKNAME}" &>/dev/null
63
+if ! runOneCmd  "oneimage" "show ${DISKNAME}" &>/dev/null
31 64
 then
32 65
     echo "***** Création de ${DISKNAME} *****"
33
-    oneimage create -d $(CreoleGet one_ds_image_name) --name "${DISKNAME}" --type DATABLOCK --description "${DISKDESC}" --size $((${DISKSIZE}*1024)) --prefix vd --driver qcow2
34
-    oneimage chtype "${DISKNAME}" OS
66
+
67
+	## Attention oneimage create --datastore ne fonctionne pas dans runOneCmd ...
68
+	auth=$(get_one_auth)
69
+	oneimage create --datastore $(CreoleGet one_ds_image_name) \
70
+		--name ${DISKNAME} --type DATABLOCK --description "${DISKDESC}" \
71
+		--size $((${DISKSIZE}*1024)) --prefix vd --driver qcow2 --user ${auth%:*} --password ${auth#*:}
72
+
73
+	runOneCmd "oneimage" "chtype ${DISKNAME} OS"
35 74
 else
36 75
     echo "***** ${DISKNAME} existe déjà *****"
37 76
 fi
@@ -40,10 +79,10 @@ echo
40 79
 #*****************************************************
41 80
 # Image ISO EOLE Latest Stable
42 81
 #*****************************************************
43
-if ! oneimage show "${ISONAME}" &>/dev/null
82
+if ! runOneCmd "oneimage" "show ${ISONAME}" &>/dev/null
44 83
 then
45 84
     echo "***** Téléchargement de ${ISONAME} *****"
46
-    wget --output-document "/tmp/eole-${VERSIONISO}-alternate-amd64.iso" "http://eole.ac-dijon.fr/pub/iso/EOLE-${MAJORVERSION}/${VERSIONISO}/eole-${VERSIONISO}-alternate-amd64.iso"
85
+    wget --output-document "/tmp/eole-${VERSIONISO}-alternate-amd64.iso" ${ISOURL}
47 86
     echo "***** Création de ${ISONAME} *****"
48 87
     if [ $? -ne 0 ]; then
49 88
         echo "Erreur lors du téléchargement, Abandon"
@@ -59,15 +98,15 @@ DEV_PREFIX="hd"
59 98
 PATH="/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
60 99
 PERSISTENT="No"
61 100
 EOF
62
-    oneimage create -d $(CreoleGet one_ds_iso_name) ${FILE}
101
+    runOneCmd "oneimage" "create -d $(CreoleGet one_ds_iso_name) ${FILE}"
63 102
     /bin/rm -f ${FILE}
64 103
     for i in `seq 60`
65 104
     do
66 105
         sleep 1
67 106
         #oneimage show ${ISONAME} | grep STATE | grep rdy &>/dev/null && break
68
-        oneimage show ${ISONAME} | grep STATE | grep lock &>/dev/null || break
107
+        runOneCmd "oneimage" "show ${ISONAME}" | grep STATE | grep lock &>/dev/null || break
69 108
         echo -n "Attente : "
70
-        oneimage show ${ISONAME} | grep STATE
109
+        runOneCmd "oneimage" "show ${ISONAME}" | grep STATE
71 110
     done
72 111
     rm -f "/tmp/eole-${VERSIONISO}-alternate-amd64.iso"
73 112
 else
@@ -98,11 +137,8 @@ MEMORY="1024"
98 137
 EOF
99 138
 
100 139
 
101
-
102
-
103
-
104 140
 #NIC=[MODEL="virtio",NETWORK="CR_eole"]
105
-    onetemplate create ${FILE}
141
+    runOneCmd "onetemplate" "create ${FILE}"
106 142
 
107 143
     /bin/rm -f ${FILE}
108 144
 else