configure-node.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. function cmd()
  3. {
  4. echo "$@" | nc -q1 192.168.1.1 23 > /dev/null
  5. }
  6. hostname=$1
  7. owner=$2
  8. latitude=$3
  9. longitude=$4
  10. [ -z "$hostname" ] && { echo "USAGE: $0 <hostname> <owner> [<latitude> <longitude>]"; exit 1; }
  11. [ -z "$owner" ] && { echo "ERROR: need at least hostname and owner as params"; exit 1; }
  12. #if [ "$IDid" != "ReadTheScript" ]; then
  13. # echo "WORK IN PROGRESS: Dieses Skript ist noch nicht fertig und tut nicht was es soll."
  14. # echo "Die uci-set Kommandos werden scheinbar nicht ausgeführt!"
  15. # exit 42
  16. #fi
  17. mac=`echo "lua -e 'print(require(\"gluon.sysconfig\").primary_mac)'" | nc -q1 192.168.1.1 23 | grep -o '^[0-9a-fA-F\:]\{17\}'`
  18. cmd 'uci set fastd.mesh_vpn.enabled=1'
  19. cmd 'uci set fastd.mesh_vpn.secret=$(fastd --generate-key --machine-readable)'
  20. cmd 'uci commit fastd'
  21. public_key=$(echo '/etc/init.d/fastd show_key mesh_vpn' | nc -q1 192.168.1.1 23 | grep -o "[0-9a-f]\{64\}")
  22. cmd "uci set system.@system[0].hostname=${hostname}"
  23. cmd "uci commit system"
  24. loc_string=""
  25. [ "$latitude" == "0" ] && latitude=""
  26. [ "$longitude" == "0" ] && longitude=""
  27. if [ ! -z "$latitude" -a ! -z "$longitude" ]; then
  28. cmd "uci set gluon-node-info.@location[0].share_location=1"
  29. cmd "uci set gluon-node-info.@location[0].latitude=$latitude"
  30. cmd "uci set gluon-node-info.@location[0].longitude=$longitude"
  31. loc_string="# Location: $latitude $longitude"
  32. else
  33. cmd "uci set gluon-node-info.@location[0].share_location=0"
  34. fi
  35. cmd 'uci commit gluon-node-info'
  36. cmd 'uci set gluon-setup-mode.@setup_mode[0]=setup_mode'
  37. cmd 'uci set gluon-setup-mode.@setup_mode[0].enabled=0'
  38. cmd 'uci set gluon-setup-mode.@setup_mode[0].configured=1'
  39. cmd 'uci commit gluon-setup-mode'
  40. cmd 'uci commit'
  41. cmd "reboot"
  42. echo "# Owner: $owner"
  43. echo "# MAC: $mac"
  44. [ ! -z "$loc_string" ] && echo $loc_string
  45. echo "key \"${public_key/\r/}\";"