diff --git a/Makefile b/Makefile index c4013f7..272d261 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,7 @@ install: install-dirs install-locales $(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py $(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(sbindir)/usbinstall $(INSTALL_SCRIPT) src/rootfsinstall.sh $(DESTDIR)$(sbindir)/rootfsinstall + $(INSTALL_SCRIPT) src/mmcinstall.sh $(DESTDIR)$(sbindir)/mmcinstall $(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/ $(INSTALL_DATA) src/org.openmamba.usbinstall.policy $(DESTDIR)$(polkitdir)/org.openmamba.usbinstall.policy $(INSTALL_DATA) src/org.openmamba.usbinstall.conf $(DESTDIR)$(dbussystemdir)/org.openmamba.usbinstall.conf diff --git a/src/mmcinstall.sh b/src/mmcinstall.sh new file mode 100755 index 0000000..13cf174 --- /dev/null +++ b/src/mmcinstall.sh @@ -0,0 +1,58 @@ +#!/bin/bash +echo "mmcinstall - Copy system partition to internal mmc device" +echo "Copyright (C) 2013 by Silvan Calarco " +echo +SOURCEPART=`cat /proc/cmdline | sed "s|root=\([^[:space:]]*\).*|\1|"` +[ "$SOURCEPART" ] || { + echo "ERROR: unable to detect root device; aborting." + exit 1 +} + +cnt=0 +grep mmcblk0p /proc/partitions | while read line; do + set -- $line + cnt=$((cnt + 1)) + size=$(($3 / 1024)) + echo "$cnt) $4 ($size MB)" +done + +echo +while [ ! "$ans" ]; do + echo -n "Please select target partition: " + read ans +done + +if [ "$ans" ]; then + set -- `grep mmcblk0p /proc/partitions | tail -n +$ans | head -n 1` + DESTPART="/dev/$4" +fi + +[ -e $DESTPART ] || { + echo "Error: destination device $DESTPART missing; aborting." + exit 1 +} + +echo +echo -e -n "Ok to copy system from $SOURCEPART to $DESTPART?\nWARNING: all data on $DESTPART will be lost!\nPlease enter 'Y' to proceed: " +read ans + +[ "$ans" = "Y" ] || exit 1 + +echo "Formatting $DESTPART" +mkfs.ext4 -L project $DESTPART || { + echo "Error formatting $DESTPART; aborting." + exit 1 +} + +echo -n "Copying $SOURCEPART filesystem to $DESTPART..." +mkdir -p /mnt/project-source +mount $SOURCEPART /mnt/project-source +mkdir -p /mnt/project +mount $DESTPART /mnt/project +cp -a /mnt/project-source/* /mnt/project/ +umount $DESTPART +umount $SOURCEPART +rmdir /mnt/project-source +rmdir /mnt/project +echo +echo "Done."