late-command.sh.tmpl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/sh
  2. set -e
  3. export NACL_URL="{{ nacl_url }}"
  4. SCRIPT_DIR="/opt/ffho/sbin"
  5. export PATH="${PATH}:${SCRIPT_DIR}"
  6. apt install python3-netifaces
  7. echo
  8. # Download scripts
  9. echo "Downloading scripts to ${SCRIPT_DIR}... "
  10. for script in register_ssh_keys get_fqdn ffho-first-boot.sh ; do
  11. echo " * ${script} "
  12. rm -f -- "${SCRIPT_DIR}/${script}"
  13. wget -q -P "${SCRIPT_DIR}" "http://noc.ffho.net/provision/${script}"
  14. chmod +x "${SCRIPT_DIR}/${script}"
  15. done
  16. echo "done."
  17. echo ""
  18. # Register SSH keys of this node
  19. echo "Registering SSH keys..."
  20. register_ssh_keys --mac
  21. echo ""
  22. ################################################################################
  23. # Set hostname #
  24. ################################################################################
  25. fqdn="$(${SCRIPT_DIR}/get_fqdn --mac)"
  26. if [ $? != 0 ]; then
  27. echo "Failed to get FQDN, dying of shame." >&2
  28. exit 1
  29. fi
  30. echo "According to NACL we are ${fqdn}, hi there!"
  31. hostname=$(echo $fqdn | cut -d. -f1)
  32. echo -n "Checking hostname... "
  33. if [ "$(hostname -f)" = "${fqdn}" ]; then
  34. echo "OK."
  35. else
  36. echo -n "fixing... "
  37. echo "${hostname}" > /etc/hostname
  38. sed -i -e "s/^127.0.1.1.*/127.0.1.1 ${fqdn} ${hostname}/" /etc/hosts
  39. echo "done."
  40. fi
  41. echo
  42. ################################################################################
  43. # Set up Salt minion #
  44. ################################################################################
  45. echo -n "Configuring Salt minion..."
  46. echo "${fqdn}" > /etc/salt/minion_id
  47. cat << EOF > /etc/salt/minion
  48. #
  49. # Salt minion config (Salt managed)
  50. #
  51. master: {{ salt_master_fqdn }}
  52. master_port: 4506
  53. ipv6: True
  54. # When waiting for a master to accept the minion's public key, salt will
  55. # continuously attempt to reconnect until successful. This is the time, in
  56. # seconds, between those reconnection attempts.
  57. acceptance_wait_time: 10
  58. # If this is nonzero, the time between reconnection attempts will increase by
  59. # acceptance_wait_time seconds per iteration, up to this maximum. If this is
  60. # set to zero, the time between reconnection attempts will stay constant.
  61. acceptance_wait_time_max: 0
  62. # Cache rendered pillar data on the minion. Default is False.
  63. # This may cause 'cachedir'/pillar to contain sensitive data that should be
  64. # protected accordingly.
  65. minion_pillar_cache: False
  66. # Set this option to 'True' to force a 'KeyError' to be raised whenever an
  67. # attempt to retrieve a named value from pillar fails. When this option is set
  68. # to 'False', the failed attempt returns an empty string. Default is 'False'.
  69. pillar_raise_on_missing: True
  70. # The state_verbose and state_output settings can be used to change the way
  71. # state system data is printed to the display. By default all data is printed.
  72. # The state_verbose setting can be set to True or False, when set to False
  73. # all data that has a result of True and no changes will be suppressed.
  74. state_verbose: False
  75. # The state_output_diff setting changes whether or not the output from
  76. # successful states is returned. Useful when even the terse output of these
  77. # states is cluttering the logs. Set it to True to ignore them.
  78. #state_output_diff: False
  79. # The state_output_profile setting changes whether profile information
  80. # will be shown for each state run.
  81. #state_output_profile: True
  82. EOF
  83. echo "done."
  84. echo
  85. ################################################################################
  86. # Set up first boot service #
  87. ################################################################################
  88. wget -q -P /etc/systemd/system/ http://noc.ffho.net/provision/ffho-first-boot.service
  89. rm -f -- /etc/systemd/system/multi-user.target.wants/ffho-first-boot.service
  90. ln -s /etc/systemd/system/ffho-first-boot.service /etc/systemd/system/multi-user.target.wants
  91. # Cool, we're done here
  92. mkdir -p /etc/freifunk
  93. touch /etc/freifunk/late-command-OK