#!/system/xbin/bash
# Make /system partition read-only or read-write

Ro="\e[0;32mREAD ONLY\e[0m"
Rw="\e[0;31mREAD/WRITE\e[0m"

function checkStatus {
    Status="$(mount | grep system)"
    echo "Current status of /system mount:"
    if [[ $Status == *rw,* ]]; then
    	echo -e "$Rw"
    elif [[ $Status == *ro,* ]]; then
        echo -e "$Ro"
    else
        echo "Error..."
    fi
    echo ""
}

case "$1" in
  ro)
    echo -e "Setting /system to $Ro"
    busybox mount -o ro,remount /system
    echo ""
    checkStatus
    ;;
  rw)
    echo -e "Setting /system to $Rw"
    busybox mount -o rw,remount /system
    echo ""
    checkStatus
    ;;
  status)
    echo ""
    checkStatus
    ;;
  *)
    echo "Valid input format:"
    echo "     remount [ro|rw|status]"
    echo -e "              ro       = $Ro (default)"
    echo -e "              rw       = $Rw (to make modifications)"
    echo "              status   = current mount mode"
    echo ""
    checkStatus
    exit 1
esac

