By kramer


2019-03-09 08:22:55 8 Comments

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 comments

@iBug 2019-03-09 11:33:53

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.

@kramer 2019-03-09 12:14:42

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 ?

@iBug 2019-03-09 12:41:38

@kramer You need to set OUTFD=1 beforehand.

Related Questions

Sponsored Content

1 Answered Questions

0 Answered Questions

Missing internal SD card in /dev/block, phone won't start

1 Answered Questions

0 Answered Questions

1 Answered Questions

0 Answered Questions

TWRP - Redirect script stdout to recovery output

0 Answered Questions

Make TWRP recovery permanent

1 Answered Questions

1 Answered Questions

TWRP Recovery stuck at splash screen

0 Answered Questions

A few Questions about Recovery

Sponsored Content