forked from theforeman/foreman-discovery-image
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-livecd-root
executable file
·89 lines (67 loc) · 2.12 KB
/
build-livecd-root
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
86
87
88
89
#!/bin/bash -x
# the portion of building a livecd that needs to be run as root
# run this after running build-livecd
#
# The temp dir in which things happen is by default deleted when this
# script ends, unless an error happens or the KEEP_TMPDIR variable is set
function cleanup() {
if [ -n "$KEEP_TMPDIR" ]; then
echo "Not removing tmpdir $tmpdir"
else
[ -d $tmpdir ] && rm -rf $tmpdir
fi
}
if [ $(id -u) != 0 ]; then
echo "Please run this script as root"
exit 1
fi
which livecd-creator isohybrid livecd-iso-to-pxeboot >/dev/null || ( echo "Command(s) missing, install required tools" && exit 2 )
trap cleanup EXIT
resultdir=$PWD
srcdir=$(readlink -f $(dirname $0))
tmpdir=$(mktemp -d /tmp/build-fdi-XXXXXX)
cd $srcdir
last_tag=${1:-$(git describe --abbrev=0 --tags)}
last_sha=$(git log --pretty=format:'%h' -n 1)
cd $tmpdir
echo Working in directory $tmpdir
echo "* Running livecd-creator"
livecd-creator -v --title="Discovery Image" --compression-type=xz --cache /var/cache/build-fdi --config $srcdir/fdi-image.ks -f fdi -t /tmp
if [ $? -ne 0 ]; then
KEEP_TMPDIR=yes
echo "Error creating livecd"
exit 1
fi
echo "* Filtering ISO with isohybrid"
cp fdi.iso fdi-bootable.iso
isohybrid --partok --uefi fdi-bootable.iso
mv fdi-bootable.iso $srcdir/fdi-bootable-${last_tag#release-}.iso
echo "* Converting to initrd"
livecd-iso-to-pxeboot $tmpdir/fdi.iso
if [ $? -ne 0 ]; then
KEEP_TMPDIR=yes
echo "Error converting to initrd"
exit 1
fi
echo "* Building tarball"
mkdir fdi-image
mv tftpboot/initrd0.img tftpboot/vmlinuz0 fdi-image || KEEP_TMPDIR=yes
cd fdi-image
cat > README <<EOF
This is Foreman discovery image
To get instructions how to use the image head over to
https://github.com/theforeman/foreman_discovery
Image was built from $last_tag ($last_sha)
To verify the kernel and initrd in this tar, run
sha256sum -c SHA256SUM
EOF
sha256sum initrd0.img vmlinuz0 > SHA256SUM
cd ..
tarball=$srcdir/fdi-image-${last_tag#release-}.tar
tar cf $tarball fdi-image/
ls -lh $tarball
chown --reference $srcdir/build-livecd $tarball
echo "* Done"
echo "The image was built:"
du -h $tarball
exit 0