2

I'm trying to display message on TWRP 3.2.3-0 recovery screen using a .sh file. i was thinking using echo command to make that.

my update-script is like this

ifelse(is_mounted("/system"), unmount("/system"));
ifelse(is_mounted("/data"), unmount("/data"));
ui_print("-- Mount partitions...");
run_program("/sbin/busybox", "mount", "/system");
run_program("/sbin/busybox", "mount", "/data");
package_extract_dir("test", "/tmp");
set_perm(0, 0, 0755, "/tmp/test.sh");
ui_print("run test.sh");
run_program("/tmp/test.sh");
ui_print("END OF PROCESS");
unmount("/data");
unmount("/system");

and my sh file is

#!/sbin/sh

if [ ! -e "/efs/imei/mps_code.dat" ]; then
    mount /efs
fi  
csc_id=`cat /efs/imei/mps_code.dat`
echo "$csc_id" > /tmp/csc_id.prop   
echo "Your active csc is $csc_id"

echo works because i see it in recovery log but displays nothing on recovery screen

Is there a way to activate echo or an other command to display message on recovery screen using sh file?

1

This piece of code is extracted from the ZIP package of SuperSU. It's working correctly on all devices I've ever had (displaying text to the TWRP terminal)

OUTFD=1
readlink /proc/$$/fd/$OUTFD 2>/dev/null | grep /tmp >/dev/null
if [ "$?" -eq "0" ]; then
  # rerouted to log file, we don't want our ui_print commands going there
  OUTFD=0

  # we are probably running in embedded mode, see if we can find the right fd
  # we know the fd is a pipe and that the parent updater may have been started as
  # 'update-binary 3 fd zipfile'
  for FD in `ls /proc/$$/fd`; do
    readlink /proc/$$/fd/$FD 2>/dev/null | grep pipe >/dev/null
    if [ "$?" -eq "0" ]; then
      ps | grep " 3 $FD " | grep -v grep >/dev/null
      if [ "$?" -eq "0" ]; then
        OUTFD=$FD
        break
      fi
    fi
  done
fi

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

To display message, use ui_print_always "some message" instead of echo.

2
  • thanks for your answer but it doesn't work for me. recovery log is /tmp/test.sh: line 32: can't create /proc/self/fd/: Is a directory. do you use this code in sh file and sheban is #!/sbin/sh ?
    – kramer
    Mar 9 '19 at 12:14
  • @kramer You need to set OUTFD=1 beforehand.
    – iBug
    Mar 9 '19 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.