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