From 8697370c8789ad38eba0fd9b76bcb9cb30e34c36 Mon Sep 17 00:00:00 2001 From: xf0r3m Date: Thu, 4 Jan 2024 07:43:09 +0100 Subject: [PATCH] =?utf8?q?tools/sbin/immudex-create-media=20-=20usuni?= =?utf8?q?=C4=99cie=20polece=C5=84=20sudo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tools/sbin/immudex-create-media | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 tools/sbin/immudex-create-media diff --git a/tools/sbin/immudex-create-media b/tools/sbin/immudex-create-media new file mode 100755 index 0000000..94402d3 --- /dev/null +++ b/tools/sbin/immudex-create-media @@ -0,0 +1,104 @@ +#!/bin/bash + +GREEN="\e[32m"; +YELLOW="\e[33m"; +ENDCOLOR="\e[0m"; + +function help() { + echo "immudex-create-media - script used for write iso image to usb drive(mainly)"; + echo "@ 2023 morketsmerke.org"; + echo "Options:"; + echo " --i386-efi - creating 32-bit EFI usb drive with iso image"; + echo " (comapatible with immudex only iso images)"; + echo " --nuke - write 0 to 1st megabyte of disk"; + echo "Usage:"; + echo " $ create_media [--i386-efi] [--nuke] [iso_image]"; +} + +if [ "$1" ] && [ "$1" = "--i386-efi" ]; then target="i386-efi"; shift; fi +if [ "$1" ] && [ "$1" = "--nuke" ]; then target="nuke"; shift; fi +if [ "$1" ] && echo $1 | grep -Eq '/dev/(sd[a-z]|vd[a-z]|mmcblk[0-9])'; then + disk=$1; shift; +else + help; + exit 1; +fi +if [ ! "$target" ] || [ "$target" != "nuke" ]; then + if [ "$1" ] && file $1 | grep -q 'ISO 9660'; then + iso=$1; + else + help; + exit 1; + fi +fi + +if [ "$target" = "i386-efi" ]; then + echo -n "Writing zeros to 1st megabyte on disk..."; + dd if=/dev/zero bs=1M of=$disk count=1 > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Creating MS-DOS partitionig scheme on disk..."; + parted $disk mklabel msdos > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Creating FAT-32 partition..."; + parted $disk mkpart primary fat32 1 100%Free > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Creating VFAT filesystem on partition..."; + mkfs.vfat ${disk}1 > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Creating /mnt/usb directory..."; + mkdir /mnt/usb > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; + else echo -e "[${YELLOW}Directory exist!${ENDCOLOR}]"; fi + + echo -n "Mounting VFAT partition on /mnt/usb..."; + mount ${disk}1 /mnt/usb > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Instalation GRUB on disk..."; + grub-install --target=i386-efi --efi-directory=/mnt/usb --boot-directory=/mnt/usb/boot --bootloader-id=boot --removable > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Creating /mnt/iso directory..."; + mkdir /mnt/iso > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; + else echo -e "[${YELLOW}Directory exist!${ENDCOLOR}]"; fi + + echo -n "Mounting iso file on /mnt/iso..."; + mount $iso /mnt/iso > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Copying grub config files to the disk..."; + cp /mnt/iso/boot/grub/font.pf2 /mnt/usb/boot/grub > /dev/null 2>&1; + cp /mnt/iso/boot/grub/grub.cfg /mnt/usb/boot/grub > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Copying immudex files to the disk..."; + cp -r /mnt/iso/live /mnt/usb > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Creating empty DEBIAN file..."; + touch /mnt/usb/DEBIAN > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Umounting all mounted filesystems..."; + umount /mnt/* > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + +elif [ "$target" = "nuke" ]; then + echo -n "Writing zeros to 1st megabyte on disk..."; + dd if=/dev/zero bs=1M of=$disk count=1 > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + +else + echo -n "Writing zeros to 1st megabyte on disk..."; + dd if=/dev/zero bs=1M of=$disk count=1 > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi + + echo -n "Writing iso image to the disk..." + dd if=$iso bs=1M of=$disk > /dev/null 2>&1; + if [ $? -eq 0 ]; then echo -e "[${GREEN}OK${ENDCOLOR}]"; fi +fi -- 2.39.5