Updated cloner3 to support installing images from a disk partition with an ext4 LABEL=
[bootimage-initfs.git] / etc / cloner3 / get_setup.sh
1 #!/bin/ash
2
3 . /etc/cloner3/cloner_server.sh
4 . /etc/library.sh
5 . /etc/cloner3/include.sh
6 . /tmp/hardware.dat
7
8 write_client_conf () {
9         # Takes $SERVER, $IMAGE and $NODE as arguments and makes 
10         # /etc/cloner-client.conf
11         mkdir -p /cloner/setup/node/etc
12         if [ "${1}x" != "x" ]; then
13                 echo "SERVER=${1}" >> /cloner/setup/node/etc/cloner-client.conf
14         fi
15         if [ "${2}x" != "x" ]; then
16                 echo "IMAGE=${2}" >> /cloner/setup/node/etc/cloner-client.conf
17         fi
18         if [ "${3}x" != "x" ]; then
19                 echo "NODE=${3}" >> /cloner/setup/node/etc/cloner-client.conf
20         fi
21                 
22 }
23
24 if [ "${_srcpath}" != "" ]
25 then
26         header "Copying setup information from ${_srcpath}"
27 elif [ "${_srclabel}" != ""]
28         header "Using setup from LABEL=${_srclabel}"
29 else
30         if [ "${_server}" = "" ]
31         then
32                 clone_fatal_error "The server must be specified on the command line"
33                 exit
34         fi
35         header "Getting setup information from cloner server (${_server})"
36 fi
37
38 if [ "${_image}" = "" ]
39 then
40         # user has not specified the cloner image from the command line
41
42         USE_SETTINGS=""
43
44         MACLIST=""
45         I=0
46         while [ "${I}" -lt "${NIC_COUNT}" ]
47         do
48                 MACADDR=`eval "echo \\\${NIC_${I}_HWADDR}"`
49                 ADDR=`echo ${MACADDR} | sed 's/://g'`
50                 
51                 MACLIST="${MACLIST}${ADDR}|"
52                 I=`expr ${I} + 1`
53         done
54         RESULT=`server_get_image ${MACLIST}`
55         
56         CODE=`echo ${RESULT} | cut -d"|" -f1`   
57         IMAGE=`echo ${RESULT} | cut -d"|" -f2`  
58         NODE=`echo ${RESULT} | cut -d"|" -f3`   
59         
60         
61         if [ "${CODE}" = "ERR" ]
62         then
63                 clone_fatal_error "Failed to get image for ${MACLIST}"
64         elif [ "${CODE}" != "OK" ]
65         then
66                 clone_fatal_error "Failed to connect to server"
67         fi
68         if [ "${CODE}" = "OK" ]
69         then
70                 msg "Using settings image=${ANSI_BLUE}${IMAGE}${ANSI_DONE} node=${ANSI_BLUE}${NODE}${ANSI_DONE}"
71
72                 replace_setting "_image" "${IMAGE}"
73                 replace_setting "_node" "${NODE}"
74         fi
75         
76 fi
77
78 if [ "${_image}" = "" ]
79 then
80         clone_fatal_error "No image was specified or downloaded from the server"
81 fi
82         
83 # if we are installing from a disk or CD-ROM
84
85 if [ "${_srcpath}" != "" ]
86 then
87         msg -n "Copying setup data for image ${_image}"
88         rsync -v /mnt/media/setup/* /cloner/setup \
89                 >> /tmp/stdout.log 2>> /tmp/stderr.log
90         if [ "$?" = 0 ]
91         then
92                 ok_msg
93         else
94                 fail_msg
95         
96                 clone_fatal_error "Can't get setup information from /mnt/media/setup"
97         fi
98
99         if [ "${_node}" != "" ]
100         then
101                 msg -n "Copying node specific data for image=${_image} node=${_node}"
102                 cp -av /mnt/media/setup/nodes/${_node}/* /cloner/setup/node \
103                         >> /tmp/stdout.log 2>> /tmp/stderr.log
104                 if [ "$?" = 0 ]
105                 then
106                         ok_msg
107                 else
108                         fail_msg
109                         clone_fatal_error "Can't get node specific information from /mnt/media"
110                 fi
111         fi
112
113 elif [ "${_srclabel}" != "" ]
114 then
115
116         msg -n "Copying setup data for image ${_image} from LABEL=${_srclabel}"
117         rsync -v /mnt/media/${_image}/* /cloner/setup \
118                 >> /tmp/stdout.log 2>> /tmp/stderr.log
119         if [ "$?" = 0 ]
120         then
121                 ok_msg
122         else
123                 fail_msg
124         
125                 clone_fatal_error "Can't get setup information from /mnt/media/${_image}"
126         fi
127
128         if [ "${_node}" != "" ]
129         then
130                 msg -n "Copying node specific data for image=${_image} node=${_node}"
131                 cp -av /mnt/media/${_image}/nodes/${_node}/* /cloner/setup/node \
132                         >> /tmp/stdout.log 2>> /tmp/stderr.log
133                 if [ "$?" = 0 ]
134                 then
135                         ok_msg
136                 else
137                         fail_msg
138                         clone_fatal_error "Can't get node specific information from /mnt/media"
139                 fi
140         fi
141
142 # we are installing from the network
143 else
144         msg -n "Downloading setup data for image ${_image}"
145         server_log "Downloading setup data for image ${_image}" "${_node}"
146         
147         rsync -v ${_server}::${CLONER_IMAGE_PATH}/${_image}/* /cloner/setup \
148                 >> /tmp/stdout.log 2>> /tmp/stderr.log
149         if [ "$?" = 0 ]
150         then
151                 ok_msg
152         else
153                 fail_msg
154         
155                 clone_fatal_error "Can't get setup information from ${_server}::${CLONER_IMAGE_PATH}/${_image}"
156         fi
157
158         if [ "${_node}" != "" ]
159         then
160                 msg -n "Downloading node specific data for image=${_image} node=${_node}"
161                 server_log "Downloading node specific data for image=${_image} node=${_node}" "${_node}"
162                 rsync -av ${_server}::${CLONER_IMAGE_PATH}/${_image}/nodes/${_node}/ \
163                         /cloner/setup/node >> /tmp/stdout.log 2>> /tmp/stderr.log
164         
165                 if [ "$?" = 0 ]
166                 then
167                         ok_msg
168                 else
169                         fail_msg
170         
171                         #fatal_error "Can't get node specific information from ${_server}::${CLONER_IMAGE_PATH}/${_image}/nodes/${_node}"
172                 fi
173                 msg -n "Writing /etc/cloner-client.conf"
174                 write_client_conf ${_server} ${_image} ${_node}
175                 if [ "$?" = 0 ]
176                 then
177                         ok_msg
178                 else
179                         fail_msg
180         
181                         clone_fatal_error "Could not write /cloner/setup/etc/cloner-client.conf"
182                 fi
183         fi
184 fi