summaryrefslogtreecommitdiffstats
path: root/fuel/prototypes/auto-deploy/deploy/functions/patch-iso.sh
blob: d27dcdf2dd9678c5560de0e19a6dd104419a3678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
# jonas.bjurel@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

exit_handler() {
    rm -Rf $tmpnewdir
    fusermount -u $tmporigdir 2>/dev/null
    test -d $tmporigdir && rmdir $tmporigdir
}

trap exit_handler exit

error_exit() {
  echo "$@"
  exit 1
}

if [ $# -ne 8 ]; then
    error_exit "Input argument error"
fi

top=$(cd `dirname $0`; pwd)
origiso=$(cd `dirname $1`; echo `pwd`/`basename $1`)
newiso=$(cd `dirname $2`; echo `pwd`/`basename $2`)
tmpdir=$3
fuelIp=$4
fuelNetmask=$5
fuelGateway=$6
fuelHostname=$7
fuelDns=$8

tmporigdir=${tmpdir}/origiso
tmpnewdir=${tmpdir}/newiso

test -f $origiso || error_exit "Could not find origiso $origiso"
test -d $tmpdir || error_exit "Could not find tmpdir $tmpdir"


if [ "`whoami`" != "root" ]; then
  error_exit "You need be root to run this script"
fi

echo "Copying..."
rm -Rf $tmpnewdir || error_exit "Failed deleting old ISO copy dir"
mkdir -p $tmporigdir $tmpnewdir
fuseiso $origiso $tmporigdir || error_exit "Failed to FUSE mount ISO"
cd $tmporigdir
find . | cpio -pd $tmpnewdir || error_exit "Failed to copy FUSE ISO with cpio"
cd $tmpnewdir
fusermount -u $tmporigdir || error_exit "Failed to FUSE unmount ISO"
rmdir $tmporigdir || error_exit "Failed to delete original FUSE ISO directory"
chmod -R 755 $tmpnewdir || error_exit "Failed to set protection on new ISO dir"

echo "Patching..."
cd $tmpnewdir
# Patch ISO to make it suitable for automatic deployment
cat $top/ks.cfg.patch | patch -p0 || error_exit "Failed patching ks.cfg"
rm -rf .rr_moved

# Add dynamic Fuel content
echo "isolinux.cfg before: `grep netmask isolinux/isolinux.cfg`"
sed -i "s/ ip=[^ ]*/ ip=$fuelIp/" isolinux/isolinux.cfg
sed -i "s/ gw=[^ ]*/ gw=$fuelGateway/" isolinux/isolinux.cfg
sed -i "s/ dns1=[^ ]*/ dns1=$fuelDns/" isolinux/isolinux.cfg
sed -i "s/ netmask=[^ ]*/ netmask=$fuelNetmask/" isolinux/isolinux.cfg
sed -i "s/ hostname=[^ ]*/ hostname=$fuelHostname/" isolinux/isolinux.cfg
sed -i "s/ showmenu=[^ ]*/ showmenu=yes/" isolinux/isolinux.cfg
echo "isolinux.cfg after: `grep netmask isolinux/isolinux.cfg`"

rm -vf $newiso
echo "Creating iso $newiso"
mkisofs -quiet -r  \
  -J -R -b isolinux/isolinux.bin \
  -no-emul-boot \
  -boot-load-size 4 -boot-info-table \
  --hide-rr-moved \
  -x "lost+found" -o $newiso . || error_exit "Failed making iso"