ui_print(" ");
ui_print(" - extracting installation files");
package_extract_dir("setup","/tmp");
set_perm_recursive(0, 0, 0777, 0777, "/tmp/arter97");
set_progress(0.1);

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");
symlink("/lib/modules", "/system/lib/modules");
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");
package_extract_file("img.tar.xz", "/tmp/img.tar.xz");
set_progress(0.3);
if getprop("ro.hardware") == "smdk4x12"
  then
  ui_print(" - flashing GT-I9300 boot.img");
  run_program("/tmp/arter97/script/img.sh", "i9300.img");
  write_raw_image("/tmp/boot.img", "/dev/block/mmcblk0p5");
  delete("/tmp/boot.img");
endif;
if getprop("ro.hardware") == "SHW-M440S"
  then
  ui_print(" - flashing SHW-M440S boot.img");
  run_program("/tmp/arter97/script/img.sh", "m440s.img");
  write_raw_image("/tmp/boot.img", "/dev/block/mmcblk0p5");
  delete("/tmp/boot.img");
  ui_print(" - installing Wi-Fi murata fix");
  run_program("/tmp/arter97/script/sub-scripts/wififix");
  ui_print("");
  ui_print(" - If you experience Wi-Fi issues,");
  ui_print(" - remove /system/etc/init.d/wififix");
  ui_print("");
endif;
if getprop("ro.hardware") == "SHV-E210S"
  then
  ui_print(" - flashing SHV-E210S boot.img");
  run_program("/tmp/arter97/script/img.sh", "e210s.img");
  write_raw_image("/tmp/boot.img", "/dev/block/mmcblk0p5");
  delete("/tmp/boot.img");
endif;
if getprop("ro.hardware") == "SHV-E210K"
  then
  ui_print(" - flashing SHV-E210K boot.img");
  run_program("/tmp/arter97/script/img.sh", "e210k.img");
  write_raw_image("/tmp/boot.img", "/dev/block/mmcblk0p5");
  delete("/tmp/boot.img");
endif;
if getprop("ro.hardware") == "SHV-E210L"
  then
  ui_print(" - flashing SHV-E210L boot.img");
  run_program("/tmp/arter97/script/img.sh", "e210l.img");
  write_raw_image("/tmp/boot.img", "/dev/block/mmcblk0p5");
  delete("/tmp/boot.img");
endif;
set_progress(0.4);
ui_print(" - tuning file systems");
if getprop("ro.hardware") == "SHV-E210L"
  then
  run_program("/sbin/tune2fs", "-o", "journal_data_writeback", "/dev/block/mmcblk0p9");
  run_program("/sbin/tune2fs", "-o", "journal_data_writeback", "/dev/block/mmcblk0p10");
  run_program("/sbin/tune2fs", "-o", "journal_data_writeback", "/dev/block/mmcblk0p13");
else
  run_program("/sbin/tune2fs", "-o", "journal_data_writeback", "/dev/block/mmcblk0p8");
  run_program("/sbin/tune2fs", "-o", "journal_data_writeback", "/dev/block/mmcblk0p9");
  run_program("/sbin/tune2fs", "-o", "journal_data_writeback", "/dev/block/mmcblk0p12");
endif;
set_progress(0.6);

delete("/system/etc/init.kernel.sh");
run_program("/tmp/arter97/script/install.sh");

set_progress(0.8);

ui_print(" - wiping dalvik-cache");
run_program("/sbin/busybox", "rm", "-r", "/data/dalvik-cache");

set_progress(0.9);

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

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

ui_print(" - removing installation files");
delete_recursive(/tmp/arter97);

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

set_progress(1.0);
