diff --git a/.gitignore b/.gitignore index 8a49ae7..b17211c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ staging/ sdcard/ -NookManager.img +NookManager.img* +build.sh?* diff --git a/NookManager/menu/backup b/NookManager/menu/backup index 15d5c00..3bde1fe 100644 --- a/NookManager/menu/backup +++ b/NookManager/menu/backup @@ -3,42 +3,36 @@ MENU=/tmp/sdcache/menu title="Create Backup" header= -button1= +button1="<- Erase empty storage (makes backup faster)" +button2="Format remaining space on SD card ->" button3="<- Back" -button2= -button4= +button4="Create backup ->" footer= key=0 -if [ ! -b /dev/block/mmcblk1p2 ]; then - header="Backups will be stored on this SD card.\nTo proceed, you must format the unused\nspace on this card." - button2="Format remaining space on SD card ->" -else - header="It will take 15-45 minutes to create a backup." - button4="Create backup ->" -fi - until [ "$key" -eq "3" ]; do + if [ ! -b /dev/block/mmcblk1p2 ]; then + header="Backups will be stored on this SD card.\nTo proceed, you must format the unused\nspace on this card." + else + header="It will take 15-45 minutes to create a backup." + fi + $SCRIPT/menu -t "$title" -h "$header" -f "$footer" -1 "$button1" -2 "$button2" -3 "$button3" -4 "$button4" key=$? if [[ "$key" -eq "2" ]]; then $SCRIPT/menu -t "$title" -h "$header" -f "Formatting free space on SD card..." footer=`$SCRIPT/format_unused_sdcard` - header="It will take 15-45 minutes to create a backup." - button2="" - button4="Create backup ->" + + elif [[ "$key" -eq "1" ]]; then + $SCRIPT/menu -t "$title" -h "$header" -f "Erasing empty storage areas..." + footer=`$SCRIPT/shrink_data` elif [[ "$key" -eq "4" ]]; then $SCRIPT/menu -t "$title" -h "$header" -f "Creating backup image...\nBackup started `date +%H:%M:%S`" footer=`$SCRIPT/create_backup` - # If the backup succeeded, hide the create backup button - if [ "$?" -eq "0" ]; then - header="" - button4="" - fi fi done diff --git a/NookManager/menu/mainmenu b/NookManager/menu/mainmenu index 6f7f6e1..c5780f9 100644 --- a/NookManager/menu/mainmenu +++ b/NookManager/menu/mainmenu @@ -11,15 +11,19 @@ key=0 while [ "$key" -ne "3" ]; do POWER=`cat /sys/class/power_supply/bq27510-0/capacity` + CHARGING=`cat /sys/class/power_supply/bq27510-0/status` - if [ "$POWER" -lt "40" ]; then - header="System: $SYSTEM\nBattery Level: $POWER\nPlease charge your battery above 40\nand then restart NookManager." + POWERMSG="$POWER%%" + [ "" != "$CHARGING" ] && POWERMSG="$POWER%% ($CHARGING)" + header="System: $SYSTEM\nBattery Level: $POWERMSG" + + if [ "$POWER" -lt "40" -a \( "$POWER" -lt 20 -o "$CHARGING" != "Charging" \) ]; then + header="$header\nPlease charge your battery above 40%%\n(or 20%% when plugged in to power)\nand then restart NookManager." button1= button3="<- Exit" button2= button4= else - header="System: $SYSTEM\nBattery Level: $POWER" button1="<- Rescue" button3="<- Exit" button2="Root ->" diff --git a/NookManager/scripts/create_backup b/NookManager/scripts/create_backup index 93ccfad..6e91b3e 100644 --- a/NookManager/scripts/create_backup +++ b/NookManager/scripts/create_backup @@ -7,26 +7,8 @@ umount /tmp/backups mkdir -p /tmp/backups mount -t vfat /dev/block/mmcblk1p2 /tmp/backups -$SCRIPT/mount_nook - echo Backup started `date +%H:%M:%S` -# Zero the free space on each of the Nook's partitions -dd if=/dev/zero of=/nook/factory/DELETEME bs=512k -rm /nook/factory/DELETEME - -dd if=/dev/zero of=/nook/system/DELETEME bs=512k -rm /nook/system/DELETEME - -dd if=/dev/zero of=/nook/userdata/DELETEME bs=512k -rm /nook/userdata/DELETEME - -dd if=/dev/zero of=/nook/cache/DELETEME bs=512k -rm /nook/cache/DELETEME - -dd if=/dev/zero of=/nook/data/DELETEME bs=512k -rm /nook/data/DELETEME - sync dd if=/dev/block/mmcblk0 bs=1000k | gzip -1 > /tmp/backups/backup.full.gz @@ -46,7 +28,6 @@ fi sync umount /tmp/backups -$SCRIPT/umount_nook echo "/dev/block/mmcblk1p2" > /sys/devices/platform/usb_mass_storage/lun1/file diff --git a/NookManager/scripts/menu_draw b/NookManager/scripts/menu_draw index df68030..57c8404 100644 --- a/NookManager/scripts/menu_draw +++ b/NookManager/scripts/menu_draw @@ -39,10 +39,10 @@ done -pointsize 45 \ -draw "gravity North text 0,0 '$title'" \ -pointsize 26 \ --draw "gravity West text 0,-100 '$button1' " \ --draw "gravity East text 0,-100 '$button2' " \ --draw "gravity West text 0,120 '$button3' " \ --draw "gravity East text 0,120 '$button4' " \ +-draw "gravity West text 0,-115 '$button1' " \ +-draw "gravity East text 0,-85 '$button2' " \ +-draw "gravity West text 0,105 '$button3' " \ +-draw "gravity East text 0,135 '$button4' " \ -gravity north \ -annotate +0+80 "$header" \ -gravity south \ diff --git a/NookManager/scripts/shrink_data b/NookManager/scripts/shrink_data new file mode 100755 index 0000000..07a3ec0 --- /dev/null +++ b/NookManager/scripts/shrink_data @@ -0,0 +1,28 @@ +SCRIPT=/tmp/sdcache/scripts + +$SCRIPT/mount_nook + +echo Backup started `date +%H:%M:%S` + +# Zero the free space on each of the Nook's partitions +# (described as "Erasing empty storage areas" on-screen) + +dd if=/dev/zero of=/nook/factory/DELETEME bs=512k +rm /nook/factory/DELETEME + +dd if=/dev/zero of=/nook/system/DELETEME bs=512k +rm /nook/system/DELETEME + +dd if=/dev/zero of=/nook/userdata/DELETEME bs=512k +rm /nook/userdata/DELETEME + +dd if=/dev/zero of=/nook/cache/DELETEME bs=512k +rm /nook/cache/DELETEME + +dd if=/dev/zero of=/nook/data/DELETEME bs=512k +rm /nook/data/DELETEME + +sync +$SCRIPT/umount_nook + +exit 0 diff --git a/build.sh b/build.sh index 921fc4f..768e5bd 100755 --- a/build.sh +++ b/build.sh @@ -181,25 +181,28 @@ cp "$BDIR/patched-jars/android.policy.jar" "$OUTDIR/files/system/framework/" cp "$BDIR/patched-jars/services.jar" "$OUTDIR/files/system/framework/" # Create image -dd if=/dev/zero of=NookManager.img bs=1MiB count=64 -losetup /dev/loop0 NookManager.img -parted /dev/loop0 mklabel msdos -parted /dev/loop0 --align=cyl mkpart primary fat32 0 100% -parted /dev/loop0 set 1 boot on -losetup -o 16384 /dev/loop1 /dev/loop0 -mkdosfs -F 32 -n "NookManager" /dev/loop1 +IMAGE_FILE=NookManager.img +dd if=/dev/zero of=$IMAGE_FILE bs=1MiB count=64 +WHOLE_CARD=$(sudo losetup -f) +sudo losetup $WHOLE_CARD $IMAGE_FILE +BOOTFS_DEV=$(sudo losetup -f) +sudo parted $WHOLE_CARD mklabel msdos +sudo parted $WHOLE_CARD --align=minimal mkpart primary fat32 16384B 100% +sudo parted $WHOLE_CARD set 1 boot on +sudo losetup -o 16384 $BOOTFS_DEV $WHOLE_CARD +sudo mkdosfs -F 32 -n "NookManager" $BOOTFS_DEV if [ ! -d "$BDIR/tmpmount" ]; then mkdir "$BDIR/tmpmount" fi -mount -t vfat /dev/loop1 "$BDIR/tmpmount" +sudo mount -t vfat -o uid=$(id -ur) -o gid=$(id -gr) $BOOTFS_DEV "$BDIR/tmpmount" rsync -a "$OUTDIR/" "$BDIR/tmpmount/" sync -umount "$BDIR/tmpmount" +sudo umount "$BDIR/tmpmount" -losetup -d /dev/loop1 +sudo losetup -d $BOOTFS_DEV sync -losetup -d /dev/loop0 +sudo losetup -d $WHOLE_CARD -echo "Build Complete. You can now flash NookManager.img to a SD card." +echo "Build Complete. You can now flash $IMAGE_FILE to an SD card." diff --git a/readme.md b/readme.md index 467455f..15e7684 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,9 @@ You must use a 32-bit Linux system to build this project. +(Bela Lubkin notes: it built fine for me on Ubuntu 12.04 x86_64; not +sure what the issue might be? I do have 32-bit libraries installed for +the benefit of various binary-only apps.) + git clone https://github.com/doozan/NookManager.git cd NookManager