image_patcher.sh.pre 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "fakemurk_lib.sh.pre"
  2. : "this is essentially just wax for fakemurk"
  3. SCRIPT_DIR=$(dirname "$0")
  4. configure_binaries(){
  5. if [ -f /sbin/ssd_util.sh ]; then
  6. SSD_UTIL=/sbin/ssd_util.sh
  7. elif [ -f /usr/share/vboot/bin/ssd_util.sh ]; then
  8. SSD_UTIL=/usr/share/vboot/bin/ssd_util.sh
  9. elif [ -f "${SCRIPT_DIR}/lib/ssd_util.sh" ]; then
  10. SSD_UTIL="${SCRIPT_DIR}/lib/ssd_util.sh"
  11. else
  12. echo "ERROR: Cannot find the required ssd_util script. Please make sure you're executing this script inside the directory it resides in"
  13. exit 1
  14. fi
  15. }
  16. drop_boot_populator() {
  17. base64 -d <<-EOF | bunzip2 -dc >"$ROOT/sbin/crossystem_boot_populator.sh"
  18. #include "crossystem_boot_populator.sh.b64"
  19. EOF
  20. chmod 777 "$ROOT/sbin/crossystem_boot_populator.sh"
  21. }
  22. drop_image_patcher(){
  23. local path=$ROOT/sbin/image_patcher.sh
  24. # trust me
  25. echo "$(< $0)"> $path
  26. chmod 777 $path
  27. }
  28. patch_root() {
  29. disable_autoupdates
  30. drop_cr50_update
  31. drop_pollen
  32. drop_startup_patch
  33. echo "dropping boot populator"
  34. drop_boot_populator
  35. echo "installing mush shell"
  36. drop_mush
  37. echo "dropping fakemurk daemon"
  38. drop_daemon
  39. echo "staging populator"
  40. >$ROOT/population_required
  41. >$ROOT/reco_patched
  42. echo "preparing ausystem"
  43. drop_ssd_util
  44. drop_image_patcher
  45. }
  46. main() {
  47. traps
  48. ascii_info
  49. configure_binaries
  50. echo $SSD_UTIL
  51. if [ -z $1 ] || [ ! -f $1 ]; then
  52. echo "\"$1\" is not a real file!!! You need to pass the path to the recovery image"
  53. exit
  54. fi
  55. local bin=$1
  56. echo "Creating loop device"
  57. local loop=$(losetup -f)
  58. losetup -P "$loop" "$bin"
  59. echo "Disabling kernel verity"
  60. $SSD_UTIL --debug --remove_rootfs_verification -i ${loop} --partitions 4
  61. echo "Enabling RW mount"
  62. $SSD_UTIL --debug --remove_rootfs_verification --no_resign_kernel -i ${loop} --partitions 2
  63. # for good measure
  64. sync
  65. echo "Mounting target"
  66. mkdir /tmp/mnt || :
  67. mount "${loop}p3" /tmp/mnt
  68. ROOT=/tmp/mnt
  69. patch_root
  70. sleep 2
  71. sync
  72. echo "done. have fun"
  73. umount "$ROOT"
  74. sync
  75. losetup -D "$loop"
  76. sync
  77. sleep 2
  78. rm -rf /tmp/mnt
  79. leave
  80. }
  81. if [ "$0" = "$BASH_SOURCE" ]; then
  82. stty sane
  83. if [ "$EUID" -ne 0 ]; then
  84. echo "Please run as root"
  85. exit
  86. fi
  87. main "$@"
  88. fi