#!/sbin/sh

OUTFD=$2
ZIP=$3

ui_print() {
  echo -n -e "ui_print $1\n" > /proc/self/fd/$OUTFD
  echo -n -e "ui_print\n" > /proc/self/fd/$OUTFD
}

cd /tmp
rm -rf arter97
mkdir arter97
cd arter97
unzip -o "$ZIP"

ui_print " ";
ui_print " - mounting system partition"
mount /system
if [ ! -e /system/system/bin/vold ]; then
  ui_print "Failed to mount system partition!"
  exit 1
fi

ui_print " - installing new /system/system/bin/vold"
if [ ! -e /system/system/bin/vold.bak ]; then
  cp /system/system/bin/vold /system/system/bin/vold.bak
fi
cp vold /system/system/bin/vold
chmod 755 /system/system/bin/vold
chown root:shell /system/system/bin/vold
chcon u:object_r:vold_exec:s0 /system/system/bin/vold

ui_print " "
ui_print "finished"
rm -rf /tmp/arter97
sync
