late-command.sh.tmpl 3.9 KB

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