2. ISO InstallDeb Cut Discr

by (c) Luc Didry 2017, WTFPL and |author|| Date: |date| Time: |time|
 1function usage {
 2cat <<EOF
 3Preseed Creator (c) Luc Didry 2017, WTFPL
 4./preseed_creator.sh [options]
 5Options:
 6-i <image.iso>ISO image to preseed. If not provided, the script will download and use the latest Debian amd64 netinst ISO image
 7-o <preseeded_image.iso>output preseeded ISO image. Default to preseed_creator/debian-netinst-latest-preseed.ISO
 8-p <preseed_file.cfg> preseed file. If not provided, the script will put "d-i debian-installer/locale string fr_FR" in the preseed.cfg file
 9-xUse xorriso instead of genisoimage, to create an iso-hybrid
10-ddownload the latest Debian amd64 netinst ISO image in the current folder
11-gdownload the latest Debian stable example preseed file into preseed_example.cfg and exit
12-hprint this help and exit
13EOF
14exit
15}
16
17function download_latest_iso {
18ONLY_DOWNLOAD=$1
19        LOCK="1";
20        INPUT1="debian-netinst-latest.iso"
21INPUT1="${MYPWD}/preseed_creator/${INPUT1}"
22
23        if [[ $ONLY_DOWNLOAD == 1 && -f "$INPUT1" ]]; then
24                echo "file exists."
ONLY_DOWNLOAD = 1;
exit 0;
1        else
rm -Rf ${MYPWD}/preseed_creator
1                LOCK="";
2                echo "file not exists."
3        fi
echo -e «n dli $ONLY_DOWNLOAD $LOCK»
 1if [[ $ONLY_DOWNLOAD == 1 && -n "$LOCK" ]]; then
 2 echo -ne "Getting Debian GPG keys [> ](0%)\r"
 3
 4fi
 5
 6if [[ $ONLY_DOWNLOAD == 1 && -n "$LOCK" ]];
 7then
 8echo -ne 'Getting Debian GPG keys [========> ](25%)\r'
 9else
10echo -ne 'Getting Debian GPG keys [> ](0%)\r'
11        fi
12
13for i in F41D30342F3546695F65C66942468F4009EA8AC3 DF9B9C49EAA9298432589D76DA87E80D6294BE9B 10460DAD76165AD81FBC0CE9988021A964E6EA7D
14do
15gpg --list-keys $i > /dev/null 2>&1
16if [ $? != 0 ]
17then
18gpg --keyserver keyring.debian.org --recv-keys 0x$i > /dev/null 2>&1
19fi
20done
21
22if [[ $ONLY_DOWNLOAD == 1 && -n "$LOCK" ]];
23then
24echo -ne 'Downloading latest Debian amd64 netinst ISO [==============> ](50%)\r'
25else
26echo -ne 'Downloading latest Debian amd64 netinst ISO [===>](10%)\r'
27
28export LATEST=$(wget -q -O - https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/ | grep "netinst.iso" | grep -v "debian-mac" | grep -v "debian-edu" | sed -e 's@.*a href="\([^"]*\)".*@\1@')
29wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/$LATEST -O debian-netinst-latest.iso
30
31wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA512SUMS -O SHA512SUMS
32wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA512SUMS.sign -O SHA512SUMS.sign
33        fi
34
35        if [[ $(wc -c "$INPUT1" | awk '{print $1}') == "0" ]];
36        then
37                echo -e "\r\n file downloaded invaild"
38                exit 1;
39        fi
40
41if [[ $ONLY_DOWNLOAD == 1 && -n "$LOCK" ]];
42then
43echo -ne 'Verifying GPG signature [======================> ](75%)\r'
44else
45echo -ne 'Verifying GPG signature [======> ](20%)\r'
46gpg --verify SHA512SUMS.sign SHA512SUMS > /dev/null 2>&1
47if [ $? -ne 0 ]
48then
49echo "Bad SHA512SUMS GPG signature. Aborting\r\n"
 1                fi
 2fi
 3
 4if [[ $ONLY_DOWNLOAD == 1 && -n "$LOCK" ]];
 5then
 6echo -ne 'Veryfying sha512sum [=============================>](100%)\r'
 7else
 8echo -ne 'Veryfying sha512sum [=========>](30%)\r'
 9        sed -e "s@${LATEST}@debian-netinst-latest.iso@" -i SHA512SUMS
10sha512sum --ignore-missing -c SHA512SUMS > /dev/null 2>&1
11
12if [ $? -ne 0 ]
13then
14echo "Bad ISO checksum. Aborting\r\n"
1fi
2fi
if [ $ONLY_DOWNLOAD == 1 ]
then
fi
 1}
 2
 3INPUT=""
 4PRESEED=""
 5POSTINSTALL=""
 6MYPWD=$(pwd)
 7OUTPUT=""
 8XORRISO=""
 9while getopts ":i:o:p:s:xdgh" opt; do
10case $opt in
11i)
12INPUT=$OPTARG
13;;
14o)
15OUTPUT=$OPTARG
16;;
17p)
18PRESEED=$OPTARG
19;;
20s)
21POSTINSTALL=$OPTARG
22;;
23x)
24XORRISO='yes'
25;;
26d)
27echo "Downloading latest Debian amd64 netinst ISO image\r\n"
28download_latest_iso 1
29;;
30g)
31echo "Downloading latest Debian stable example preseed file into preseed_example.cfg\r\n"
32wget -q http://www.debian.org/releases/stable/example-preseed.txt -O preseed_example.cfg
33echo "Done\r\n"
34exit
35;;
36h)
37usage
38;;
39\?)
40echo "Invalid option: -$OPTARG\r\n" >&2
41usage
42;;
43esac
44done
45
46rm -Rf "${MYPWD}/preseed_creator/irmod"
47rm -Rf "${MYPWD}/preseed_creator/cd"
exit 1;
 1mkdir preseed_creator -p
 2cd preseed_creator
 3
 4if [[ ! -z $POSTINSTALL ]]
 5then
 6if [ ${POSTINSTALL:0:1} != / ]
 7then
 8POSTINSTALL="${MYPWD}/${POSTINSTALL}"
 9fi
10if [[ ! -e $POSTINSTALL ]]
11then
12echo "$POSTINSTALL does not exists. Aborting\r\n"
13exit 1
14fi
15if [[ ! -r $POSTINSTALL ]]
16then
17echo "$POSTINSTALL is not readable. Aborting\r\n"
18exit 1
19fi
20fi
21
22if [[ ! -z $PRESEED ]]
23then
24if [ ${PRESEED:0:1} != / ]
25then
26PRESEED="${MYPWD}/${PRESEED}"
27fi
28if [[ ! -e $PRESEED ]]
29then
30echo "$PRESEED does not exists. Aborting\r\n"
31exit 1
32fi
33if [[ ! -r $PRESEED ]]
34then
35echo "$PRESEED is not readable. Aborting\r\n"
36exit 1
37fi
38fi
39
40if [[ ! -z $OUTPUT ]]
41then
42if [ ${OUTPUT:0:1} != / ]
43then
44OUTPUT="${MYPWD}/${OUTPUT}"
45fi
46else
47OUTPUT="debian-netinst-latest-preseed.iso"
48fi
49
50if [[ -z $INPUT ]]
51then
52echo "No ISO image provided, will download the latest Debian amd64 netinst ISO image\r\n"
53download_latest_iso 1
54
55INPUT="debian-netinst-latest.iso"
56else
57if [ ${INPUT:0:1} != / ]
58then
59INPUT="${MYPWD}/${INPUT}"
60fi
61if [[ ! -e $INPUT ]]
62then
63echo "$INPUT does not exists. Aborting\r\n"
64exit 1
65fi
66if [[ ! -r $INPUT ]]
67then
68echo "$INPUT is not readable. Aborting\r\n"
69exit 1
70fi
71fi
72
73echo -ne 'Mounting ISO image[===========>](40%)\r'
74mkdir loopdir -p
75mount -o loop $INPUT loopdir > /dev/null 2>&1
76if [ $? -ne 0 ]
77then
78echo -e "Error while mounting the ISO image. Aborting $?\r\n"
79umount loopdir
80exit 1
81fi
82
83mkdir cd
84echo -ne 'Extracting ISO image[==============> ](50%)\r'
85rsync -a -H --exclude=TRANS.TBL loopdir/ cd
86echo -ne 'Umounting ISO image [=================>](60%)\r\n'
87umount loopdir
rmdir loopdir
1echo -ne 'Hacking initrd [====================> ](70%)\r\n'
echo -e «ws $INPUT ${INPUT} ${MYPWD} / ${INPUT}rn»
mkdir «$MYPWD/preseed_creator/irmod/install/»
1mkdir irmod -p
2cd irmod
exit 1
Суть проблемы - есть BASH скрипт, работающий из Ubuntu для перепаковки ramdisk (initrd.gz), нужен аналог для Windows
Скрипт использует cpio и gunzip, их версии скомпиленые для Windows (бины, сорцы и доки)
1gzip -d < ../cd/install.amd/initrd.gz | cpio --extract --make-directories --no-absolute-filenames 2>/dev/null
>/dev/null
 1if [ $? -ne 0 ]
 2then
 3echo "Error while getting ../cd/install.amd/initrd.gz content. Aborting"
 4exit 1
 5fi
 6
 7cp -Rf "$MYPWD/install_ext/install/" "$MYPWD/preseed_creator/irmod/install/"
 8if [ $? -ne 0 ]; then
 9 echo "Copy ext files Aborting"
10 exit 1
11fi
12mv -f "$MYPWD/preseed_creator/irmod/install/lib" "$MYPWD/preseed_creator/irmod/lib/"
13if [ $? -ne 0 ]; then
14 echo "rm ext files lib Aborting"
15 exit 1
16fi
17
18echo -ne 'Disable menu graphic installer[=======================>](80%)\r\n'
19sed -i 's/include gtk.cfg//g' ../cd/isolinux/menu.cfg 2>/dev/null
20if [ $? -ne 0 ]
21then
22echo "Error while disabling graphic menu installer in ../cd/isolinux/isolinux.cfg. Aborting"
23exit 1
24fi
mkdir install -p
cp $POSTINSTALL install/postinstall.sh
echo -e «n now {$MYPWD} cp «
ls -la
1
exit 1;
1if [[ -z $PRESEED ]]
2then
1        cp "$MYPWD/preseed.cfg" "$MYPWD/preseed_creator/irmod/preseed.cfg"
2        PRESEED="preseed.cfg"
echo -e «n d-i debian-installer/locale»
1else
2cp $PRESEED preseed.cfg
3fi
4
5
6if [[ ! -f "$PRESEED" ]]; then
7        echo "file pressed.cfg not exists!";
8        exit 1;
9fi
exit 1
1echo -ne 'Packing files in initrd.gz \r\n'
2find . | cpio -H newc --create 2>/dev/null | gzip -9 > ../cd/install.amd/initrd.gz 2>/dev/null
gzip -c -9 find. > ../cd/install.amd/initrd.gz 2>/dev/null
1if [ $? -ne 0 ]
2then
3echo 'Error while putting new content into ../cd/install.amd/initrd.gz. Aborting'
4exit 1
5fi
exit 1;
 1cd ../
 2rm -rf irmod/
 3
 4echo -ne 'Fixing md5sums[========================> ](85%)\r'
 5cd cd
 6
 7
 8md5sum `find -follow -type f 2>/dev/null` > md5sum.txt 2>/dev/null
 9if [ $? -ne 0 ]
10then
11echo -ne 'Error while fixing md5sums. Aborting\r'
exit 1
1fi
exit 1
 1cd ..
 2mkdir "$MYPWD/preseed_creator/cd/install_ext/"
 3if [ $? -ne 0 ]; then
 4 echo -ne 'Do not create install_ext'
 5 exit 1
 6fi
 7
 8cp -Rf "$MYPWD/install_ext/home/" "$MYPWD/preseed_creator/cd/install_ext/"
 9cp -Rf "$MYPWD/install_ext/install/lib/" "$MYPWD/preseed_creator/cd/install_ext/"
10
11if [ $? -ne 0 ]; then
12 echo -ne 'Copy ext files in cd Aborting'
13 exit 1
14fi
15
16cp -Rf "$MYPWD/dep11/" "$MYPWD/preseed_creator/cd/firmware/"
17if [ $? -ne 0 ]; then
18 echo -ne 'Copy ext files dep11 in cd Aborting'
19 exit 1
20fi
21
22echo -ne 'Creating preseeded ISO image[==========================> ](90%)\r'
exit 1;
1if [[ -z $XORRISO ]]
2then
3echo -ne 'Create iso by genisoimage tool\r'
genisoimage -quiet -o $OUTPUT -r -J -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat ./cd > /dev/null 2>&1 -f
 1genisoimage -o $OUTPUT -r -J -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat ./cd > /dev/null 2>&1
 2
 3else
 4echo -ne 'Create iso by xorriso -as mkisofs tool\r'
 5        xorriso -as mkisofs \
 6                -quiet \
 7                -o $OUTPUT \
 8                -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
 9                -c isolinux/boot.cat \
10                -b isolinux/isolinux.bin \
11                -no-emul-boot -boot-load-size 4 -boot-info-table \
12                -eltorito-alt-boot \
13                -e boot/grub/efi.img \
14                -no-emul-boot \
15                -isohybrid-gpt-basdat \
16                ./cd /dev/null 2>$1
17fi
18
19if [ $? -ne 0 ]
20then
21echo "Error while creating the preseeded ISO image. Aborting"
22exit 1
23fi
24
25rm -rf cd
26rm -rf loopdir
27
28echo -ne 'Preseeded ISO image created [==============================](100%)\r'
29echo -e "\nYour preseeded ISO image is located at $OUTPUT"