#!/sbin/sh
ui_print() {
	if [ "$OUT_FD" ]; then
		if [ "$1" ]; then
			echo "ui_print $1" > "$OUT_FD"
		else
			echo "ui_print  " > "$OUT_FD"
		fi
	else
		echo "$1"
	fi
}

# set to a fraction (where 1.0 = 100%)
set_progress() {
	echo "set_progress $1" > "$OUT_FD"
}

# find the recovery text output pipe (it's always the last one found)
for l in /proc/self/fd/*; do 
	# set the last pipe: target
	if readlink $l | grep -Fqe 'pipe:'; then
		OUT_FD=$l
	fi
done

ui_print " [#] Dirty flash fix for RevengeOS, Mi A1"
ui_print " [i] Working..."
set_progress 0.5
rm -rf /data/system/package_cache
ui_print " [i] Done!"
set_progress 1.0
ui_print " [i] You can now safely reboot."