chromeos_startup.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. rm -f /fakemurk_startup_log
  3. rm -r /fakemurk_startup_err
  4. rm -f /fakemurk-log
  5. touch /startup_log
  6. chmod 775 /startup_log
  7. exec 3>&1 1>>/startup_log 2>&1
  8. run_plugin() {
  9. bash "$1"
  10. }
  11. runjob() {
  12. clear
  13. trap 'kill -2 $! >/dev/null 2>&1' INT
  14. (
  15. # shellcheck disable=SC2068
  16. $@
  17. )
  18. trap '' INT
  19. clear
  20. }
  21. . /usr/share/misc/chromeos-common.sh
  22. DST=/dev/$(get_largest_nvme_namespace)
  23. if [ -z $DST ]; then
  24. DST=/dev/mmcblk0
  25. fi
  26. # we stage sshd and mkfs as a one time operation in startup instead of in the bootstrap script
  27. # this is because ssh-keygen was introduced somewhere around R80, where many shims are still stuck on R73
  28. # filesystem unfuck can only be done before stateful is mounted, which is perfectly fine in a shim but not if you run it while booted
  29. # because mkfs is mean and refuses to let us format
  30. # note that this will lead to confusing behaviour, since it will appear as if it crashed as a result of fakemurk
  31. # startup plugins are also launched here, for low-level control over the system
  32. # /path/to/example_plugin.sh
  33. # funny boot messages
  34. # multi-liners
  35. cat <<EOF >/usr/share/chromeos-assets/text/boot_messages/en/block_devmode_virtual.txt
  36. Oh fuck - ChromeOS is trying to kill itself.
  37. ChromeOS detected developer mode and is trying to disable it to
  38. comply with FWMP. This is most likely a bug and should be reported to
  39. the murkmod GitHub Issues page.
  40. EOF
  41. cat <<EOF >/usr/share/chromeos-assets/text/boot_messages/en/self_repair.txt
  42. oops UwU i did a little fucky wucky and your system is trying to
  43. repair itself~ sorry OwO
  44. EOF
  45. # single-liners
  46. echo "i sure hope you did that on purpose (powerwashing system)" >/usr/share/chromeos-assets/text/boot_messages/en/power_wash.txt
  47. crossystem.old block_devmode=0 # prevent chromeos from comitting suicide
  48. if [ ! -f /sshd_staged ]; then
  49. # thanks rory! <3
  50. echo "Staging sshd..."
  51. mkdir -p /ssh/root
  52. chmod -R 777 /ssh/root
  53. echo "Generating ssh keypair..."
  54. ssh-keygen -f /ssh/root/key -N '' -t rsa >/dev/null
  55. cp /ssh/root/key /rootkey
  56. chmod 600 /ssh/root
  57. chmod 644 /rootkey
  58. echo "Creating config..."
  59. cat >/ssh/config <<-EOF
  60. AuthorizedKeysFile /ssh/%u/key.pub
  61. StrictModes no
  62. HostKey /ssh/root/key
  63. Port 1337
  64. EOF
  65. touch /sshd_staged
  66. echo "Staged sshd."
  67. fi
  68. if [ -f /population_required ]; then
  69. echo "Populating crossystem..."
  70. /sbin/crossystem_boot_populator.sh
  71. echo "Done. Setting check_enrollment..."
  72. vpd -i RW_VPD -s check_enrollment=1
  73. echo "Removing flag..."
  74. rm -f /population_required
  75. fi
  76. echo "Launching sshd..."
  77. /usr/sbin/sshd -f /ssh/config &
  78. if [ -f /logkeys/active ]; then
  79. echo "Found logkeys flag, launching..."
  80. /usr/bin/logkeys -s -m /logkeys/keymap.map -o /mnt/stateful_partition/keylog
  81. fi
  82. if [ ! -f /stateful_unfucked ]; then
  83. echo "Unfucking stateful..."
  84. yes | mkfs.ext4 "${DST}p1"
  85. touch /stateful_unfucked
  86. echo "Done, rebooting..."
  87. reboot
  88. else
  89. echo "Stateful already unfucked, doing temp stateful mount..."
  90. stateful_dev=${DST}p1
  91. first_mount_dir=$(mktemp -d)
  92. mount "$stateful_dev" "$first_mount_dir"
  93. echo "Mounted stateful on $first_mount_dir, looking for startup plugins..."
  94. plugin_dir="$first_mount_dir/murkmod/plugins"
  95. temp_dir=$(mktemp -d)
  96. cp -r "$plugin_dir"/* "$temp_dir"
  97. echo "Copied files to $temp_dir, unmounting and cleaning up..."
  98. umount "$stateful_dev"
  99. rmdir "$first_mount_dir"
  100. echo "Finding startup plugins..."
  101. for file in "$temp_dir"/*.sh; do
  102. if grep -q "startup_plugin" "$file"; then
  103. echo "Starting plugin $file..."
  104. runjob run_plugin $file
  105. fi
  106. done
  107. echo "Plugins run. Handing over to real startup..."
  108. if [ ! -f /new-startup ]; then
  109. exec /sbin/chromeos_startup.sh.old
  110. else
  111. exec /sbin/chromeos_startup.old
  112. fi
  113. fi