#!/system/bin/sh

while getopts ":ch" opt; do
  case $opt in
    c)
      clearScreen=true
      ;;
    h)
      help=true
      ;;
    \?)
      echo "Unknown option $OPTARG"
      exit 1
  esac
done

if [ -n "$help" ] || [ $# -eq 0 ]; then
  echo Runs a script even if it is not executable.
  echo Usage
  echo 'runscript [script]'
  echo -h show this help message.
  exit 0
fi

#cd into the dir the script is in
dir=$(realpath $@)
dir=${dir%/*}/

cd $dir

#Create a copy of the script and make it executable
mkdir -p $TEMP/runscript
copy=${TEMP}/runscript/${1##*/}
cp "$@" $copy
chmod +rwx $copy

#Clear the screen and run the copy
if [ -n "$clearScreen" ]; then
  clear
fi

exec $copy

