Prototype of automated libvirt installation
[genesis.git] / fuel / prototypes / libvirt / 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 # This is a temporary script - this should be rolled into a separate
13 # build target "make ci-iso" instead!
14
15 exit_handler() {
16   rm -Rf $tmpnewdir
17   fusermount -u $tmporigdir 2>/dev/null
18   test -d $tmporigdir && mdir $tmporigdir
19 }
20
21 trap exit_handler exit
22
23 error_exit() {
24   echo "$@"
25   exit 1
26 }
27
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 tmporigdir=/${tmpdir}/origiso
34 tmpnewdir=/${tmpdir}/newiso
35
36 test -f $origiso || error_exit "Could not find origiso $origiso"
37 test -d $tmpdir || error_exit "Could not find tmpdir $tmpdir"
38
39
40 if [ "`whoami`" != "root" ]; then
41   error_exit "You need be root to run this script"
42 fi
43
44 echo "Copying..."
45 rm -Rf $tmporigdir $tmpnewdir
46 mkdir -p $tmporigdir $tmpnewdir
47 fuseiso $origiso $tmporigdir || error_exit "Failed fuseiso"
48 cd $tmporigdir
49 find . | cpio -pd $tmpnewdir
50 cd $tmpnewdir
51 fusermount -u $tmporigdir
52 rmdir $tmporigdir
53 chmod -R 755 $tmpnewdir
54
55 echo "Patching..."
56 cd $tmpnewdir
57 # Patch ISO to make it suitable for automatic deployment
58 cat $top/ks.cfg.patch | patch -p0 || error_exit "Failed patch 1"
59 cat $top/isolinux.cfg.patch | patch -p0 || error_exit "Failed patch 2"
60 rm -rf .rr_moved
61
62 echo "Creating iso $newiso"
63 mkisofs -quiet -r  \
64   -J -R -b isolinux/isolinux.bin \
65   -no-emul-boot \
66   -boot-load-size 4 -boot-info-table \
67   --hide-rr-moved \
68   -x "lost+found" -o $newiso . || error_exit "Failed making iso"
69