Last active
August 29, 2015 14:01
-
-
Save kakwa/1b94160cf3aee754253e to your computer and use it in GitHub Desktop.
small script to create an iso "dd-able" to an usb key from an existing iso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
MOUNT="false" | |
ISOHDPFX="M+2QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJAz7fqO1bwAfPv8ZjHbZjHJZlNmUQZXjt2O\nxVK+AHy/AAa5AAHzpepLBgAAUrRBu6pVMckw9vnNE3IWgftVqnUQg+EBdAtmxwbxBrRC6xXrAFpR\ntAjNE4PhP1tRD7bGQFD34VNSULsAfLkEAGahsAfoRAAPgoAAZkCAxwLi8maBPkB8+8B4cHUJ+rzs\ne+pEfAAA6IMAaXNvbGludXguYmluIG1pc3Npbmcgb3IgY29ycnVwdC4NCmZgZjHSZgMG+HtmExb8\ne2ZSZlAGU2oBahCJ5mb3Nuh7wOQGiOGIxZL2Nu57iMYI4UG4AQKKFvJ7zRONZBBmYcPoHgBPcGVy\nYXRpbmcgc3lzdGVtIGxvYWQgZXJyb3IuDQperLQOij5iBLMHzRA8CnXxzRj06/0AAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | |
help(){ | |
echo "usage: `basename $0` -i <input iso> -o <output iso> [-m]" | |
echo "" | |
echo "Recreate a 'dd able' iso from an existing iso:" | |
echo "" | |
echo " -i <input iso>: path to the input iso" | |
echo " -o <output iso>: path to the output iso" | |
echo " -m: use mount instead of 7z to extract iso," | |
echo " more reliable, but requires root permission" | |
echo "" | |
exit 1 | |
} | |
check_cmd(){ | |
cmd=$1 | |
type $cmd >/dev/null 2>&1 | |
ret=$? | |
if [ $ret -ne 0 ] | |
then | |
echo "you need $cmd to be installed" | |
exit 1 | |
fi | |
} | |
clean(){ | |
if [ -d "$TMPDIR" ] | |
then | |
rm -rf "$TMPDIR" | |
fi | |
if [ -d "$TMPDIR" ] | |
then | |
rm -rf "$TMPDIRMOUNT" | |
fi | |
} | |
while getopts ":hi:o:m" opt; do | |
case $opt in | |
h) | |
help | |
;; | |
i) | |
IN="$OPTARG" | |
;; | |
o) | |
OUT="$OPTARG" | |
;; | |
m) | |
MOUNT="true" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
help | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
help | |
exit 1 | |
;; | |
esac | |
done | |
if [ -z "$IN" ] || [ -z "$OUT" ] | |
then | |
echo "-i and -o are mandatory" | |
echo "" | |
help | |
exit 1 | |
fi | |
check_cmd xorriso | |
if [ "$MOUNT" = "true" ] | |
then | |
if ! [ "`whoami`" = "root" ] | |
then | |
echo "with '-m' flag, `basename $0` must be launched as root" | |
exit 1 | |
fi | |
else | |
check_cmd 7z | |
fi | |
trap clean HUP INT TERM | |
TMPDIR=`mktemp -d` | |
TMPDIRMOUNT=`mktemp -d` | |
if [ "$MOUNT" = "true" ] | |
then | |
mount $IN $TMPDIRMOUNT | |
cp -rp $TMPDIRMOUNT/* ${TMPDIR} | |
umount $TMPDIRMOUNT | |
else | |
7z x -tiso $IN -o${TMPDIR} | |
find ${TMPDIR}/ -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \; | |
fi | |
printf $ISOHDPFX | base64 -d >${TMPDIR}/isohdpfx.bin | |
BOOT_CAT=`find ${TMPDIR}/ -name 'boot.cat' |sed "s%${TMPDIR}/*%%"` | |
ISOLINUX_BIN=`find ${TMPDIR}/ -name 'isolinux.bin' |sed "s%${TMPDIR}/*%%"` | |
xorriso -as mkisofs \ | |
-iso-level 3 \ | |
-full-iso9660-filenames \ | |
-volid "CustomISO" \ | |
-preparer "prepared by rebuild-iso" \ | |
-eltorito-boot $ISOLINUX_BIN \ | |
-eltorito-catalog $BOOT_CAT \ | |
-isohybrid-mbr $TMPDIR/isohdpfx.bin \ | |
-no-emul-boot -boot-load-size 4 -boot-info-table \ | |
-output "$OUT" \ | |
"$TMPDIR/" | |
clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment