assert(getprop("ro.product.device") == "rk2928" || getprop("ro.product.device") == "rk2928sdk");
ui_print("");
ui_print("***********************************************");
ui_print("* CWM-based Recovery for RK2928               *");
ui_print("* http://androtab.info/clockworkmod/rockchip/ *");
ui_print("***********************************************");
ui_print("");
package_extract_file("flash_image", "/tmp/dump_image");
set_perm(0, 0, 0755, "/tmp/dump_image");
if is_mounted("/mnt/sdcard") then
  run_program("/tmp/dump_image", "recovery", "/mnt/sdcard/dumped_recovery.img");
  package_extract_file("misc-boot-recovery.img", "/tmp/misc.img");
  write_raw_image("/tmp/misc.img", "misc");
  delete("/tmp/misc.img");
else
  if is_mounted("/mnt/external_sd") then
    run_program("/tmp/dump_image", "recovery", "/mnt/external_sd/dumped_recovery.img");
    package_extract_file("misc-boot-recovery.img", "/tmp/misc.img");
    write_raw_image("/tmp/misc.img", "misc");
    delete("/tmp/misc.img");
  endif;
endif;
delete("/tmp/dump_image");
if is_mounted("/system") then
  unmount("/system");
endif;
package_extract_file("flash_image", "/tmp/test");
set_perm(0, 0, 0755, "/tmp/test");
mount("ext4", "MTD", "system", "/system");
if run_program("/tmp/test", "-e", "/system/etc/install-recovery.sh") == 0 then
  set_perm(0, 0, 0644, "/system/etc/install-recovery.sh");
  ui_print("/system/etc/install-recovery.sh is disabled");
endif;
unmount("/system");
delete("/tmp/test");
package_extract_file("recovery.img", "/tmp/recovery.img");
if write_raw_image("/tmp/recovery.img", "recovery") then
  ui_print("CWM-based Recovery for RK2928 is installed");
endif;
delete("/tmp/recovery.img");
