A variety of simple automation scripts and enhancements to Sway and i3.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

73 lines
1.7KB

  1. #!/bin/bash
  2. SERVER_KEY='abcdefghijklmnopqrstuvwxyz0123456789abcdefg=';
  3. SERVER_IP='1.1.1.1';
  4. WG_BLOCK='10.10.0';
  5. if [[ $1 == '' ]]; then
  6. echo "Need last octet as argument"
  7. exit
  8. elif grep -Pq '^[0-9]*$' <<< $(echo $1); then
  9. echo "Good"
  10. else
  11. echo "Argument must be a number representing the last octet"
  12. exit
  13. fi
  14. sudo apt update
  15. if grep -Pq '^arm' <<< $(uname -m); then
  16. sudo apt install -y wireguard wireguard-dkms wireguard-tools raspberrypi-kernel raspberrypi-kernel-headers resolvconf
  17. else
  18. sudo apt install -y wireguard wireguard-tools linux-headers-$(uname -r) resolvconf
  19. fi
  20. if [[ "`which wg 2> /dev/null`" == '' ]]; then
  21. echo "Failed to install wireguard"
  22. exit
  23. fi
  24. wg genkey | sudo tee /etc/wireguard/client_private.key | wg pubkey | sudo tee /etc/wireguard/client_public.key
  25. if [[ "`sudo cat /etc/wireguard/client_public.key 2> /dev/null`" == '' ]]; then
  26. echo "Failed to create keys"
  27. exit
  28. fi
  29. echo "[Interface]
  30. Address = 10.10.0.${1}/24
  31. DNS = 10.10.0.1
  32. PrivateKey = $(sudo cat /etc/wireguard/client_private.key)
  33. [Peer]
  34. PublicKey = $SERVER_KEY
  35. AllowedIPs = 0.0.0.0/0
  36. Endpoint = $SERVER_IP:51820
  37. PersistentKeepalive = 25" > wg0.conf
  38. sudo mv wg0.conf /etc/wireguard/
  39. sudo chown root:root /etc/wireguard/wg0.conf
  40. sudo chmod 600 /etc/wireguard/wg0.conf
  41. sudo systemctl enable wg-quick@wg0
  42. echo "On server run:
  43. sudo systemctl stop wg-quick@wg0
  44. Then append the following to /etc/wireguard/wg0.conf:
  45. [Peer]
  46. PublicKey = $(sudo cat /etc/wireguard/client_public.key)
  47. AllowedIPs = $WG_BLOCK.${1}/32
  48. Then start it again with
  49. sudo systemctl start wg-quick@wg0
  50. Then on this client, enable and start wireguard:
  51. sudo systemctl enable wg-quick@wg0
  52. sudo systemctl start wg-quick@wg0
  53. "