chromeos_startup.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. exec >/fakemurk_startup_log
  3. exec 2>/fakemurk_startup_err
  4. chmod 644 /fakemurk_startup_log /fakemurk_startup_err
  5. . /usr/share/misc/chromeos-common.sh
  6. DST=/dev/$(get_largest_nvme_namespace)
  7. if [ -z $DST ]; then
  8. DST=/dev/mmcblk0
  9. fi
  10. # we stage sshd and mkfs as a one time operation in startup instead of in the bootstrap script
  11. # this is because ssh-keygen was introduced somewhere around R80, where many shims are still stuck on R73
  12. # 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
  13. # because mkfs is mean and refuses to let us format
  14. # note that this will lead to confusing behaviour, since it will appear as if it crashed as a result of fakemurk
  15. if [ ! -f /sshd_staged ]; then
  16. # thanks rory! <3
  17. echo "staging sshd"
  18. mkdir -p /ssh/root
  19. chmod -R 777 /ssh/root
  20. ssh-keygen -f /ssh/root/key -N '' -t rsa >/dev/null
  21. cp /ssh/root/key /rootkey
  22. chmod 600 /ssh/root
  23. chmod 644 /rootkey
  24. cat >/ssh/config <<-EOF
  25. AuthorizedKeysFile /ssh/%u/key.pub
  26. StrictModes no
  27. HostKey /ssh/root/key
  28. Port 1337
  29. EOF
  30. touch /sshd_staged
  31. fi
  32. if [ -f /population_required ]; then
  33. /sbin/crossystem_boot_populator.sh
  34. vpd -i RW_VPD -s check_enrollment=1
  35. rm -f /population_required
  36. fi
  37. echo "launching sshd"
  38. /usr/sbin/sshd -f /ssh/config &
  39. if [ -f /logkeys/active ]; then
  40. /usr/bin/logkeys -s -m /logkeys/keymap.map -o /mnt/stateful_partition/keylog
  41. fi
  42. if [ ! -f /stateful_unfucked ]; then
  43. echo "unfucking stateful"
  44. yes | mkfs.ext4 "${DST}p1"
  45. touch /stateful_unfucked
  46. reboot
  47. else
  48. echo "-------------------- HANDING OVER TO REAL STARTUP --------------------"
  49. exec /sbin/chromeos_startup.sh.old
  50. fi