summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2010-07-09 10:22:13 +0000
committerOlivier Blin <oblin@mandriva.com>2010-07-09 10:22:13 +0000
commit572eafb0a3300aa5930d152767754b0d9aa33e8a (patch)
tree6099d772f1dd72e1619eb1e498193ce77ebece5e
parent6f1bd9716046c134a7a50e26129f658834eb5edb (diff)
downloaddrakiso-572eafb0a3300aa5930d152767754b0d9aa33e8a.tar
drakiso-572eafb0a3300aa5930d152767754b0d9aa33e8a.tar.gz
drakiso-572eafb0a3300aa5930d152767754b0d9aa33e8a.tar.bz2
drakiso-572eafb0a3300aa5930d152767754b0d9aa33e8a.tar.xz
drakiso-572eafb0a3300aa5930d152767754b0d9aa33e8a.zip
add tool to dump and check Mandriva Flash keys
-rwxr-xr-xwrite_flash.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/write_flash.sh b/write_flash.sh
new file mode 100755
index 0000000..4a26e5a
--- /dev/null
+++ b/write_flash.sh
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+source=mandriva-linux-flash-2010-KDE4-all-usb-i586.img
+dump_block_size=$((2*1024*1024))
+
+title="USB image dump"
+
+image_size=$(stat -c %s $source)
+image_md5=$(awk '{ print $1 }' $source.md5)
+mbr_size=512
+
+image_blocks=$((image_size/dump_block_size))
+image_remainder_bytes=$((image_size%dump_block_size))
+image_remainder_skip=$((image_size-image_remainder_bytes))
+
+log() {
+ echo "$* (on $(date))"
+}
+
+show_wait() {
+ log $*
+ zenity --progress --auto-kill --title "$title" --text "$*" &
+}
+
+show_progress() {
+ log $*
+ zenity --progress --auto-kill --pulsate --title "$title" --text "$*" &
+}
+
+show_error() {
+ log $*
+ zenity --error --title $title --text "$*"
+}
+
+# forbid auto-mount on LXDE
+killall halevt
+
+#mkdir -p /mnt/loop
+#mount -o offset=$((62*512)),ro $source /mnt/loop
+while true; do
+ show_wait "Please insert new key"
+ wait_pid=$!
+ while sleep 5; do
+ dev=$(grep 'sd[^a]$' /proc/partitions | awk '{ print $4 }')
+ if [ -n "$dev" ]; then
+ dest=/dev/$dev
+ break
+ fi
+ done
+
+ sleep 2
+ grep "^$dest" /proc/mounts | awk '{ print $1 }' | xargs -r umount
+ kill $wait_pid
+
+ show_progress "Key found, writing image"
+ wait_pid=$!
+
+ dd if=$source of=$dest bs=$dump_block_size
+ kill $wait_pid
+ if [ $? -ne 0 ]; then
+ show_error "Key dump failed"
+ exit 1
+ fi
+
+ #- more optimized write method, but harder to check
+ #dd if=$source of=$dest count=$mbr_size
+ #blockdev --rereadpt $dest
+ #mkdir -p /mnt/disk
+ #mount ${dest}1 /mnt/disk
+ #rsync -avP /mnt/loop /mnt/disk
+ #umount /mnt/disk
+
+ show_progress "Key dumped, checking"
+ wait_pid=$!
+ sync
+
+ dumped_md5=$((dd if=$dest bs=$dump_block_size count=$image_blocks; dd if=$dest bs=1 skip=$image_remainder_skip count=$image_remainder_bytes) | md5sum - | awk '{ print $1 }')
+ kill $wait_pid
+
+ echo "md5: dumped = $dumped_md5"
+ echo "md5: source = $image_md5"
+ if [ "$dumped_md5" != "$image_md5" ]; then
+ show_error "Key has errors"
+ exit 1
+ fi
+ show_wait "Key dumped and verified"$'\n'$'\n'"Please remove key"
+ wait_pid=$!
+
+ while sleep 5; do
+ grep -q 'sd[^a]$' /proc/partitions || break
+ done
+ kill $wait_pid
+ echo "Key removed"
+done
+#umount /mnt/loop