Added cloner 3 install scripts
[bootimage-initfs.git] / etc / cloner3 / installer.sh
1 #!/bin/ash
2
3 . /etc/library.sh
4 . /etc/cloner3/include.sh
5 . /etc/cloner3/cloner_server.sh
6 . /tmp/cmdline.dat
7
8 # TODO
9 #  * Further testing of GRUB / LILO bootloader
10
11 header "Starting the installation process"
12
13 # --------------
14 #  Perform a multicast install
15 # --------------
16 if [ "${_multicast}" = "1" ]
17 then
18
19         msg "Starting multicast receiver, server will initiate transfer"
20         server_log "Starting multicast receiver, server will initiate transfer" "${_node}"
21         /usr/bin/udp-receiver --nokbd --pipe 'tar -xvf - -C /cloner/mnt'
22
23         if [ "$?" = "0" ]
24         then
25                 ok_msg
26         else
27                 fail_msg
28                 clone_fatal_error "Failed to untar multicasted image"
29         fi
30
31 # --------------
32 #  A CD-DVD based install
33 # --------------
34 elif [ "${_srcpath}" != "" ]
35 then
36         msg "Starting the unpacking from CD/DVD-ROM"
37
38         # change to our install directory
39         cd /cloner/mnt >> /tmp/stdout.log 2>>/tmp/stderr.log
40
41         if [ -e /cloner/setup/disk_size ]
42         then
43                 . /cloner/setup/disk_size
44         else
45                 fatal_error "No disk size specified on setup directory"
46         fi
47
48         afio -i -Z -v -s $DISK_SIZE -H /etc/cloner2/switch_cd.sh \
49                 /mnt/media/${_image}.afio
50
51         if [ "$?" != 0 ]
52         then
53                 fail_msg
54                 fatal_error "Failed to extract filesystem from CD/DVD drive"
55         fi
56
57         # revert back to our old directory
58         cd - >> /tmp/stdout.log 2>>/tmp/stderr.log
59
60 # --------------
61 #  A standard network RSYNC based install
62 # --------------
63 else
64
65         #msg "The installation process can take a while, check ${ANSI_RED}[ALT-F4]${ANSI_DONE} to view progress"
66
67         msg -n "Syncing data from ${ANSI_BLUE}${_server}${ANSI_DONE} image ${ANSI_BLUE}${_image}${ANSI_DONE}"
68         server_log "Syncing data from ${_server} image ${_image}" "${_node}"
69         /usr/bin/rsync -avz --numeric-ids \
70                 ${_server}::${CLONER_IMAGE_PATH}/${_image}/data/  /cloner/mnt/
71         if [ "$?" = "0" ]
72         then
73                 ok_msg
74         else
75                 fail_msg
76                 clone_fatal_error "Failed to sync filesystem data from server!"
77         fi
78         
79 fi
80         
81 # remake an directories we excluded from our rsync process
82 sort -k1 /cloner/setup/makedirectories \
83         > /cloner/setup/makedirectories.sorted 2>> /tmp/stderr.log
84
85 header "Making missing directories"
86 while read line
87 do
88
89         DIR=`echo $line | awk '{print $1}'`
90         DIR_MODE=`echo $line | awk '{print $2}'`
91         DIR_UID=`echo $line | awk '{print $3}'`
92         DIR_GID=`echo $line | awk '{print $4}'`
93
94         if [ "${DIR}" != "" ]
95         then
96                 msg -n "Making directory ${ANSI_BLUE}${DIR}${ANSI_DONE}"
97                 mkdir -p /cloner/mnt/${DIR} >> /tmp/stdout.log \
98                         2>> /tmp/stderr.log
99
100                 chmod ${DIR_MODE} /cloner/mnt/${DIR} >> \
101                         /tmp/stdout.log 2>> /tmp/stderr.log
102         
103                 chown ${DIR_UID}:${DIR_GID} /cloner/mnt/${DIR} \
104                         >> /tmp/stdout.log 2>> /tmp/stderr.log
105         
106                 if [ "$?" = "0" ]
107                 then
108                         ok_msg
109                 else
110                         fail_msg
111                 fi
112         fi
113
114 done < /cloner/setup/makedirectories.sorted
115         
116 if [ "${_node}" != "" ]
117 then
118
119         if [ "${_srcpath}" != "" ]
120         then
121                 header "Installing node specific data"
122                 msg -n "Syning node ${ANSI_BLUE}${_node}${ANSI_DONE} data from /mnt/media"
123                 rsync -avzc -I --numeric-ids --exclude /.valid \
124                         /cloner/setup/node/ /cloner/mnt \
125                         >> /tmp/stdout.log 2>> /tmp/stderr.log
126
127                 if [ "$?" = "0" ]
128                 then
129                         ok_msg
130                 else
131                         fail_msg
132                         fatal_error "Failed to sync node data from CD/DVD"
133                 fi
134         else
135                 header "Installing node specific data"
136                 server_log "Syncing node ${_node} data from ${_server}" "${_node}"
137                 msg -n "Syning node ${ANSI_BLUE}${_node}${ANSI_DONE} data from ${_server}"
138
139                 rsync -avzc --numeric-ids --exclude /.valid \
140                         ${_server}::${CLONER_IMAGE_PATH}/${_image}/nodes/${_node}/ \
141                         /cloner/mnt >> /tmp/stdout.log 2>> /tmp/stderr.log
142                 if [ "$?" = "0" ]
143                 then
144                         ok_msg
145                 else
146                         fail_msg
147                         #clone_fatal_error "Failed to sync node data from server!"
148                 fi
149                 
150                 header "Getting node netconfig settings"
151                 msg -n "Getting data from ${_server} for ${_node}"
152                 server_get_netcfg "${_node}"
153                 ok_msg
154         fi
155 fi
156
157 header "Installing bootloader"
158 while read line
159 do
160         BL_DEVICE=`echo $line | awk '{print $1}'`
161         BL_TYPE=`echo $line | awk '{print $2}'`
162
163         if [ "${BL_TYPE}" = "grub" ]
164         then
165                 msg -n "Installing grub bootloader on ${ANSI_BLUE}${BL_DEVICE}${ANSI_DONE}"
166                 server_log "Installing grub on ${BL_DEVICE}" "${_node}"
167
168                 GRUB_PATH=""
169                 if [ -x /cloner/mnt/sbin/grub-install ]
170                 then
171                         GRUB_PATH="/sbin/grub-install"
172                 elif  [ -x /cloner/mnt/usr/sbin/grub-install ]
173                 then
174                         GRUB_PATH="/usr/sbin/grub-install"
175                 elif [ -x /cloner/mnt/sbin/grub2-install ]
176                 then
177                         GRUB_PATH="/sbin/grub2-install"
178                 elif  [ -x /cloner/mnt/usr/sbin/grub2-install ]
179                 then
180                         GRUB_PATH="/usr/sbin/grub2-install"
181                 else
182                         clone_fatal_error "Can't find the grub-install binary on mounted filesystem, no bootloader installed"
183                 fi
184
185                 chroot /cloner/mnt ${GRUB_PATH} --no-floppy ${BL_DEVICE} \
186                         >> /tmp/stdout.log 2>> /tmp/stderr.log
187                 if [ "$?" = "0" ]
188                 then
189                         ok_msg
190                 else
191                         fail_msg
192                         msg -n "Trying alternative grub installation "
193                         server_log "Trying alternative grub install" "${_node}"
194                         echo "root (hd0,0)" > /cloner/mnt/grub.txt
195                         echo "setup (hd0)" >> /cloner/mnt/grub.txt
196
197                         chroot /cloner/mnt ""/sbin/grub --device-map=/boot/grub/device.map --no-floppy --batch < /cloner/mnt/grub.txt"" \ 
198                                 >> /tmp/stdout.log 2>> /tmp/stderr.log
199                         if [ "$?" = "0" ]
200                         then
201                                 ok_msg
202                         else
203                                 fail_msg
204                                 clone_fatal_error "Failed to install grub bootloader"
205                         fi
206                 fi
207         elif [ "${BL_TYPE}" = "lilo" ]
208         then
209                 msg -n "Installing lilo bootloader on ${ANSI_BLUE}${BL_DEVICE}${ANSI_DONE}"
210                 server_log "Installing lilo on ${BL_DEVICE}" "${_node}"
211                 chroot /cloner/mnt /sbin/lilo >> /tmp/stdout.log 2>> /tmp/stderr.log
212                 if [ "$?" = "0" ]
213                 then
214                         ok_msg
215                 else
216                         fail_msg
217                         clone_fatal_error "Failed to install grub bootloader"
218                 fi
219         fi
220
221 done < /cloner/setup/bootloader
222
223 # we want to sort our filesystems via the mntpoint field so we can unmount them in
224 # the reverse order
225 sort -r -k2 /cloner/setup/filesystems \
226         > /cloner/setup/filesystems.revsorted 2>> /tmp/stderr.log
227
228 header "Unmounting filesystems"
229 server_log "Unmounting filesystems" "${_node}"
230 while read line
231 do
232         FS_DEVICE=`echo $line | awk '{print $1}'`
233         FS_MNTPOINT=`echo $line | awk '{print $2}'`
234         FS_TYPE=`echo $line | awk '{print $3}'`
235         FS_LABEL=`echo $line | awk '{print $4}'`
236
237         case "${FS_TYPE}"
238         in
239                 swap)
240                         msg -n "Turning off swap partitions"
241                         swapoff ${FS_DEVICE} >> /tmp/stdout.log 2>> /tmp/stderr.log
242                         ok_or_fail $?
243                         ;;
244                 *)
245                         msg -n "Unmounting ${FS_DEVICE} -> ${FS_MNTPOINT}"
246                         umount /cloner/mnt${FS_MNTPOINT} >> /tmp/stdout.log 2>> /tmp/stderr.log
247                         ok_or_fail $?
248                         ;;
249         esac
250 done < /cloner/setup/filesystems.revsorted
251