Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / deploy / functions / patch-iso.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 exit_handler() {
13     rm -Rf $tmpnewdir
14     fusermount -u $tmporigdir 2>/dev/null
15     test -d $tmporigdir && rmdir $tmporigdir
16 }
17
18 trap exit_handler exit
19
20 error_exit() {
21   echo "$@"
22   exit 1
23 }
24
25 if [ $# -ne 8 ]; then
26     error_exit "Input argument error"
27 fi
28
29 top=$(cd `dirname $0`; pwd)
30 origiso=$(cd `dirname $1`; echo `pwd`/`basename $1`)
31 newiso=$(cd `dirname $2`; echo `pwd`/`basename $2`)
32 tmpdir=$3
33 fuelIp=$4
34 fuelNetmask=$5
35 fuelGateway=$6
36 fuelHostname=$7
37 fuelDns=$8
38
39 tmporigdir=${tmpdir}/origiso
40 tmpnewdir=${tmpdir}/newiso
41
42 test -f $origiso || error_exit "Could not find origiso $origiso"
43 test -d $tmpdir || error_exit "Could not find tmpdir $tmpdir"
44
45
46 if [ "`whoami`" != "root" ]; then
47   error_exit "You need be root to run this script"
48 fi
49
50 echo "Copying..."
51 rm -Rf $tmpnewdir || error_exit "Failed deleting old ISO copy dir"
52 mkdir -p $tmporigdir $tmpnewdir
53 fuseiso $origiso $tmporigdir || error_exit "Failed to FUSE mount ISO"
54 cd $tmporigdir
55 find . | cpio -pd $tmpnewdir || error_exit "Failed to copy FUSE ISO with cpio"
56 cd $tmpnewdir
57 fusermount -u $tmporigdir || error_exit "Failed to FUSE unmount ISO"
58 rmdir $tmporigdir || error_exit "Failed to delete original FUSE ISO directory"
59 chmod -R 755 $tmpnewdir || error_exit "Failed to set protection on new ISO dir"
60
61 echo "Patching..."
62 cd $tmpnewdir
63 # Patch ISO to make it suitable for automatic deployment
64 cat $top/ks.cfg.patch | patch -p0 || error_exit "Failed patching ks.cfg"
65 rm -rf .rr_moved
66
67 # Add dynamic Fuel content
68 echo "isolinux.cfg before: `grep netmask isolinux/isolinux.cfg`"
69 sed -i "s/ ip=[^ ]*/ ip=$fuelIp/" isolinux/isolinux.cfg
70 sed -i "s/ gw=[^ ]*/ gw=$fuelGateway/" isolinux/isolinux.cfg
71 sed -i "s/ dns1=[^ ]*/ dns1=$fuelDns/" isolinux/isolinux.cfg
72 sed -i "s/ netmask=[^ ]*/ netmask=$fuelNetmask/" isolinux/isolinux.cfg
73 sed -i "s/ hostname=[^ ]*/ hostname=$fuelHostname/" isolinux/isolinux.cfg
74 sed -i "s/ showmenu=[^ ]*/ showmenu=yes/" isolinux/isolinux.cfg
75 echo "isolinux.cfg after: `grep netmask isolinux/isolinux.cfg`"
76
77 rm -vf $newiso
78 echo "Creating iso $newiso"
79 mkisofs -quiet -r  \
80   -J -R -b isolinux/isolinux.bin \
81   -no-emul-boot \
82   -boot-load-size 4 -boot-info-table \
83   --hide-rr-moved \
84   -x "lost+found" -o $newiso . || error_exit "Failed making iso"
85