ui_print(" ");
show_progress(0.3, 2);
ui_print(" - extracting installation files");
package_extract_dir("setup","/tmp");
set_perm_recursive(0, 0, 0777, 0777, "/tmp/arter97");

run_program("/tmp/arter97/script/getprop.sh");
if file_getprop("/tmp/arter97/hardware.prop", "hardware") == "err"
  then
  ui_print(" ");
  ui_print(" - error in determining device variant");
  ui_print(" - try again in another recovery");
  ui_print(" ");
endif;
assert(	file_getprop("/tmp/arter97/hardware.prop", "hardware") == "smdk4x12"	||
	file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHW-M440S"	||
	file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHV-E210S"	||
	file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHV-E210K"	||
	file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHV-E210L"	);

ui_print(" - mounting system partition");
run_program("/sbin/mount", "/system");
ui_print(" - mounting data partition");
run_program("/sbin/mount", "/data");

ui_print(" - deleting old kernel modules");
run_program("/sbin/busybox", "rm", "-r", "/system/lib/modules");
ui_print(" - installing new kernel modules");
run_program("/sbin/busybox", "mkdir", "/system/lib/modules");
run_program("/sbin/busybox", "chown", "0.0", "/system/lib/modules");
run_program("/sbin/busybox", "chmod", "755", "/system/lib/modules");
symlink("/lib/modules/dhd.ko", "/system/lib/modules/dhd.ko");
ui_print(" - installing mali r3p2 drivers");
ui_print("              hostapd hotspot fix");
ui_print("              aTweaks");
ui_print("              aSwitch");
delete("/system/bin/hostapd");
delete("/system/xbin/hostapd");
delete("/system/app/aTweaks.apk");
delete("/data/app/com.arter97.atweaks.app.apk");
delete("/data/app/com.arter97.atweaks.app-1.apk");
delete("/data/app/com.arter97.atweaks.app-2.apk");
delete("/data/app/com.arter97.atweaks.app-3.apk");
delete("/data/app/com.arter97.atweaks.app-4.apk");
delete("/data/app/com.arter97.atweaks.app-5.apk");
delete("/data/app/com.arter97.atweaks.app-6.apk");
delete("/data/app/com.arter97.atweaks.app-7.apk");
delete("/data/app/com.arter97.atweaks.app-8.apk");
delete("/data/app/com.arter97.atweaks.app-9.apk");
delete("/system/app/aSwitch.apk");
delete("/data/app/com.arter97.aswitch.apk");
delete("/data/app/com.arter97.aswitch-1.apk");
delete("/data/app/com.arter97.aswitch-2.apk");
delete("/data/app/com.arter97.aswitch-3.apk");
delete("/data/app/com.arter97.aswitch-4.apk");
delete("/data/app/com.arter97.aswitch-5.apk");
delete("/data/app/com.arter97.aswitch-6.apk");
delete("/data/app/com.arter97.aswitch-7.apk");
delete("/data/app/com.arter97.aswitch-8.apk");
delete("/data/app/com.arter97.aswitch-9.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-1.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-2.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-3.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-4.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-5.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-6.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-7.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-8.apk");
delete("/data/arter97_secondrom/data/app/com.arter97.aswitch-9.apk");
package_extract_dir("system", "/system");
set_perm_recursive(0, 0, 0755, 0644, "/system/lib/egl");
set_perm(0, 0, 0644, "/system/lib/libMali.so");
set_perm(0, 0, 0644, "/system/lib/libUMP.so");
set_perm(0, 0, 0775, "/system/bin/hostapd");
set_perm(0, 0, 0644, "/system/app/aTweaks.apk");
set_perm(0, 0, 0644, "/system/app/aSwitch.apk");
run_program("/sbin/busybox", "cp", "-p", "/system/app/aSwitch.apk", "/data/arter97_secondrom/system/app/aSwitch.apk");
run_program("/sbin/busybox", "cp", "-p", "/system/app/aTweaks.apk", "/data/arter97_secondrom/system/app/aTweaks.apk");
ui_print(" - resetting aTweaks");
ui_print("             aSwitch");
run_program("/sbin/busybox", "rm", "-r", "/data/.arter97");
run_program("/sbin/busybox", "rm", "-r", "/data/arter97_secondrom/data/.arter97");
package_extract_file("img.tar.xz", "/tmp/img.tar.xz");
show_progress(0.6, 4);
if file_getprop("/tmp/arter97/hardware.prop", "hardware") == "smdk4x12"
  then
  ui_print(" - flashing GT-I9300 boot.img");
  run_program("/tmp/arter97/script/img.sh", "i9300.img");
endif;
if file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHW-M440S"
  then
  ui_print(" - flashing SHW-M440S boot.img");
  run_program("/tmp/arter97/script/img.sh", "m440s.img");
endif;
if file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHV-E210S"
  then
  ui_print(" - flashing SHV-E210S boot.img");
  run_program("/tmp/arter97/script/img.sh", "e210s.img");
endif;
if file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHV-E210K"
  then
  ui_print(" - flashing SHV-E210K boot.img");
  run_program("/tmp/arter97/script/img.sh", "e210k.img");
endif;
if file_getprop("/tmp/arter97/hardware.prop", "hardware") == "SHV-E210L"
  then
  ui_print(" - flashing SHV-E210L boot.img");
  run_program("/tmp/arter97/script/img.sh", "e210l.img");
endif;
show_progress(0.4, 1);
ui_print(" - tuning file systems");
run_program("/sbin/fstrim", "-v", "/system");
run_program("/sbin/fstrim", "-v", "/data");
run_program("/sbin/fstrim", "-v", "/cache");

ui_print(" - unmounting partition /data");
unmount("/data");

ui_print(" - unmounting partition /system");
unmount("/system");

ui_print(" - removing installation files");
delete_recursive(/tmp/arter97);
run_program("/sbin/busybox", "sync");

ui_print(" ");
ui_print("finished");
