Code: Select all
#!/bin/sh
IMAGE="EGATE.IMG"
offset=$(($(sfdisk -d $IMAGE|awk '/start=/{print $4}'|head -n1|sed 's/,//')*512))
uuid=$(dd if=$IMAGE skip=$((0x27+$offset)) bs=1 count=4 2>/dev/null|hexdump -e '"%X"'|sed 's/\(....\)/\1-/')
LOOP="/dev/loop0"
OPTIONS="umask=000,shortname=mixed,quiet,utf8"
DIR=/tmp/target
mkdir -p $DIR
losetup -d $LOOP
losetup $LOOP $IMAGE
umount $DIR
mount -o loop,offset=$offset,$OPIONS $IMAGE $DIR
mkdir -p $DIR/boot/grub
cat > $DIR/boot/grub/menu.lst <<EOT
timeout 0
title Test
kernel /ce_bz
EOT
cp -v /usr/lib/grub/x86_64-pc/stage1 $DIR/boot/grub
cp -v /usr/lib/grub/x86_64-pc/stage2 $DIR/boot/grub
grub --device-map=/dev/null --batch <<EOT
device (hd0) $LOOP
root (hd0,0)
setup --stage2=$DIR/boot/grub/stage2 (hd0)
EOT
cat > $DIR/splash.idx <<EOT
root=UUID=$uuid
EOT
umount $DIR
losetup -d $LOOP
But I get the following error when I try to run the script:
Code: Select all
~/Desktop$ ./inject
bash: ./inject: /bin/sh^M: bad interpreter: No such file or directory
What am I doing wrong? Also please take a look at the script and point out any errors in it. Thanks!