packet.sh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. set -e
  3. if ros version >/dev/null 2>&1; then
  4. exit 0
  5. fi
  6. apt-get install -y jq curl
  7. mkdir -p /boot/ros
  8. URL_BASE=https://releases.rancher.com/os/latest
  9. curl -L $URL_BASE/vmlinuz > /boot/ros/vmlinuz
  10. curl -L $URL_BASE/initrd > /boot/ros/initrd
  11. eval $(curl -sL https://metadata.packet.net/metadata | jq -r '.network.addresses[] | select(.address_family == 4 and .public) | "ADDRESS=\(.address)/\(.cidr)\nGATEWAY=\(.gateway)"')
  12. eval $(curl -sL https://metadata.packet.net/metadata | jq -r '.network.interfaces[0] | "MAC=\(.mac)"')
  13. cat > /etc/default/grub << "EOF"
  14. # If you change this file, run 'update-grub' afterwards to update
  15. # /boot/grub/grub.cfg.
  16. # For full documentation of the options in this file, see:
  17. # info -f grub -n 'Simple configuration'
  18. GRUB_DEFAULT=ROS
  19. GRUB_HIDDEN_TIMEOUT=15
  20. GRUB_HIDDEN_TIMEOUT_QUIET=false
  21. GRUB_TIMEOUT=10
  22. GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
  23. GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS1,115200n8"
  24. GRUB_CMDLINE_LINUX=""
  25. # Uncomment to enable BadRAM filtering, modify to suit your needs
  26. # This works with Linux (no patch required) and with any kernel that obtains
  27. # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
  28. #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
  29. # Uncomment to disable graphical terminal (grub-pc only)
  30. GRUB_TERMINAL=console
  31. # The resolution used on graphical terminal
  32. # note that you can use only modes which your graphic card supports via VBE
  33. # you can see them in real GRUB with the command `vbeinfo'
  34. #GRUB_GFXMODE=640x480
  35. # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
  36. #GRUB_DISABLE_LINUX_UUID=true
  37. # Uncomment to disable generation of recovery mode menu entries
  38. #GRUB_DISABLE_RECOVERY="true"
  39. # Uncomment to get a beep at grub start
  40. #GRUB_INIT_TUNE="480 440 1"
  41. GRUB_TERMINAL=serial
  42. GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=1 --word=8 --parity=no --stop=1"
  43. EOF
  44. cat > /etc/grub.d/50ros << EOF
  45. #!/bin/sh
  46. exec tail -n +3 \$0
  47. # This file provides an easy way to add custom menu entries. Simply type the
  48. # menu entries you want to add after this comment. Be careful not to change
  49. # the 'exec tail' line above.
  50. menuentry 'ROS' {
  51. recordfail
  52. load_video
  53. insmod gzio
  54. insmod part_msdos
  55. insmod part_msdos
  56. insmod diskfilter
  57. insmod mdraid1x
  58. insmod ext2
  59. linux /ros/vmlinuz rancher.state.mdadm_scan rancher.state.directory=ros rancher.network.interfaces.bond0.address=$ADDRESS rancher.network.interfaces.bond0.gateway=$GATEWAY rancher.network.interfaces.mac:${MAC}.bond=bond0 rancher.cloud_init.datasources=[packet] rancher.rm_usr console=tty0 console=ttyS1,115200n8
  60. initrd /ros/initrd
  61. }
  62. menuentry 'ROS Debug' {
  63. recordfail
  64. load_video
  65. insmod gzio
  66. insmod part_msdos
  67. insmod part_msdos
  68. insmod diskfilter
  69. insmod mdraid1x
  70. insmod ext2
  71. linux /ros/vmlinuz rancher.state.mdadm_scan rancher.state.directory=ros rancher.network.interfaces.bond0.address=$ADDRESS rancher.network.interfaces.bond0.gateway=$GATEWAY rancher.network.interfaces.mac:${MAC}.bond=bond0 rancher.cloud_init.datasources=[packet] rancher.rm_usr rancher.network.interfaces.eth*.dhcp=false console=tty0 console=ttyS1,115200n8 rancher.debug rancher.log
  72. initrd /ros/initrd
  73. }
  74. EOF
  75. chmod +x /etc/grub.d/50ros
  76. update-grub2
  77. tune2fs -L RANCHER_STATE $(df -h / | sed 1d | awk '{print $1}')
  78. reboot