Advertisement
wilmans2m

Untitled

Apr 16th, 2016
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. #!/sbin/sh
  2. # Init.d enabler by ALEXNDR
  3.  
  4. OUTFD=/proc/self/fd/$2
  5.  
  6. ui_print() {
  7. echo -n -e "ui_print $1\n" >> $OUTFD
  8. echo -n -e "ui_print\n" >> $OUTFD
  9. }
  10.  
  11. set_perm() {
  12. chown $1.$2 $4
  13. chown $1:$2 $4
  14. chmod $3 $4
  15. if [ -z "$5" ] ; then
  16. chcon u:object_r:system_file:s0 $4
  17. else
  18. chcon u:object_r:$5:s0 $4
  19. fi
  20. }
  21.  
  22. resolve_link() {
  23. if [ -z "$1" ] || [ ! -e $1 ] ; then return 1 ; fi
  24. local VAR=$1
  25. while [ -h "$VAR" ] ; do
  26. VAR=$(readlink $VAR)
  27. done
  28. echo $VAR
  29. }
  30.  
  31. is_mounted() {
  32. if [ -z "$2" ] ; then
  33. cat /proc/mounts | grep $1 >/dev/null
  34. else
  35. cat /proc/mounts | grep $1 | grep "$2," >/dev/null
  36. fi
  37. return $?
  38. }
  39.  
  40. ui_print " "
  41. ui_print "=========================================="
  42. ui_print "Init.d enabler by ALEXNDR (_alexndr @ XDA)"
  43. ui_print "=========================================="
  44. ui_print " "
  45.  
  46. SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/app$")) ||
  47. SYSTEM=$(resolve_link $(find /dev/block/platform -type l | grep -i -m 1 "/system$"))
  48.  
  49. if (! is_mounted /system) ; then mount -o rw /system ; fi
  50. if (! is_mounted /system rw) ; then mount -o rw,remount /system ; fi
  51. if (! is_mounted /system rw) ; then mount -t ext4 -o rw $SYSTEM /system ; fi
  52. if (! is_mounted /system rw) ; then mount -t f2fs -o rw $SYSTEM /system ; fi
  53. if (! is_mounted /system rw) ; then
  54. ui_print "Failed! Can't mount /system rw, aborting!"
  55. ui_print " "
  56. exit 1
  57. fi
  58.  
  59. SYSLIB=/system/lib
  60. cat /system/build.prop | grep "ro.product.cpu.abilist=" | grep "64" >/dev/null && SYSLIB=/system/lib64
  61. cat /system/build.prop | grep "ro.product.cpu.abi=" | grep "64" >/dev/null && SYSLIB=/system/lib64
  62.  
  63. # These files are prefered to trigger init.d scripts (in following order, if exists):
  64. # /system/etc/init.*.post_boot.sh
  65. # /system/etc/*.post_boot.sh
  66. # /system/etc/init.*.boot.sh
  67. # /system/etc/*.boot.sh
  68. #
  69. # /system/bin/debuggerd is used if there is no suitable *.sh file in /system/etc
  70.  
  71. BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.post_boot\.sh$") ||
  72. BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.post_boot\.sh$") ||
  73. BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "/init\..*\.boot\.sh$") ||
  74. BOOTFILE=$(ls /system/etc/*.sh 2>/dev/null | grep -m 1 "\.boot\.sh$") ||
  75. BOOTFILE=/system/bin/debuggerd
  76.  
  77. BOOTCON=$(ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
  78. if [ -z "$BOOTCON" ] ; then
  79. BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toolbox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
  80. fi
  81. if [ -z "$BOOTCON" ] ; then
  82. BOOTCON=$(LD_LIBRARY_PATH=$SYSLIB /system/bin/toybox ls -Z $BOOTFILE 2>/dev/null | grep "u:object_r" | cut -d: -f3)
  83. fi
  84. if [ -z "$BOOTCON" ] ; then
  85. BOOTCON=system_file
  86. fi
  87.  
  88. cat $BOOTFILE | grep "^exit 0" >/dev/null && EXIT=true || EXIT=false
  89.  
  90. if [ -z "$(cat $BOOTFILE | grep "Init\.d")" ] ; then
  91. if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
  92. if [ ! -f /system/bin/debuggerd_real ] ; then
  93. mv -f $BOOTFILE /system/bin/debuggerd_real
  94. echo "#!/system/bin/sh" > $BOOTFILE
  95. else
  96. sed -i '/debuggerd_real/d' $BOOTFILE
  97. fi
  98. else
  99. mv -f $BOOTFILE "$BOOTFILE.bak"
  100. cp -pf "$BOOTFILE.bak" $BOOTFILE
  101. if ($EXIT) ; then sed -i '/^exit 0/d' $BOOTFILE ; fi
  102. echo "" >> $BOOTFILE
  103. fi
  104. echo "# Init.d support" >> $BOOTFILE
  105. echo 'SU="$(ls /su/bin/su 2>/dev/null || ls /system/xbin/su) -c"' >> $BOOTFILE
  106. echo 'mount -o rw,remount /system && SU="" || eval "$SU mount -o rw,remount /system"' >> $BOOTFILE
  107. echo 'eval "$SU chmod 777 /system/etc/init.d"' >> $BOOTFILE
  108. echo 'eval "$SU chmod 777 /system/etc/init.d/*"' >> $BOOTFILE
  109. echo 'eval "$SU mount -o ro,remount /system"' >> $BOOTFILE
  110. echo 'ls /system/etc/init.d/* 2>/dev/null | while read xfile ; do eval "$SU /system/bin/sh $xfile" ; done' >> $BOOTFILE
  111. if [ "$BOOTFILE" = "/system/bin/debuggerd" ] ; then
  112. echo '/system/bin/debuggerd_real $@' >> $BOOTFILE
  113. set_perm 0 2000 755 $BOOTFILE $BOOTCON
  114. else
  115. if ($EXIT) ; then echo "exit 0" >> $BOOTFILE ; fi
  116. chcon u:object_r:$BOOTCON:s0 $BOOTFILE
  117. fi
  118. mkdir -p /system/etc/init.d
  119. echo "#!/system/bin/sh" > /system/etc/init.d/00test
  120. echo "# Init.d test" >> /system/etc/init.d/00test
  121. echo 'echo "Init.d is working !!!" > /data/initd_test.log' >> /system/etc/init.d/00test
  122. echo 'echo "excecuted on $(date +"%d-%m-%Y %r")" >> /data/initd_test.log' >> /system/etc/init.d/00test
  123. echo "#!/system/bin/sh" > /system/etc/init.d/99SuperSUDaemon
  124. echo "/system/xbin/daemonsu --auto-daemon &" >> /system/etc/init.d/99SuperSUDaemon
  125. set_perm 0 0 777 /system/etc/init.d
  126. set_perm 0 0 777 "/system/etc/init.d/*"
  127. ui_print "Init.d has been successfully enabled"
  128. ui_print "using following file run at boot:"
  129. ui_print " "
  130. ui_print "$BOOTFILE"
  131. ui_print " "
  132. ui_print "Check result in /data/initd_test.log file"
  133. ui_print " "
  134. else
  135. ui_print "Init.d is enabled already, aborting!"
  136. ui_print " " # exit is not necessary
  137. fi
  138.  
  139. umount /system
  140.  
  141. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement