configure.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Constants
  2. NETWORK_IP="10.21.21.0"
  3. GATEWAY_IP="10.21.21.1"
  4. NGINX_IP="10.21.21.2"
  5. NGINX_PORT="80"
  6. TIPI_IP="$1"
  7. USERNAME="$(whoami)"
  8. # Apps
  9. APP_PI_HOLE_PORT="8081"
  10. APP_PI_HOLE_IP="10.21.21.20"
  11. # Store paths to intermediary config files
  12. ANSIBLE_HOSTS_FILE="./templates/ansible-hosts-sample.cfg"
  13. ENV_FILE="./templates/.env"
  14. # Remove intermediary config files
  15. [[ -f "$ENV_FILE" ]] && rm -f "$ENV_FILE"
  16. [[ -f "$ANSIBLE_HOSTS_FILE" ]] && rm -f "$ANSIBLE_HOSTS_FILE"
  17. # Copy template configs to intermediary configs
  18. [[ -f "./templates/.env-sample" ]] && cp "./templates/.env-sample" "$ENV_FILE"
  19. [[ -f "./templates/ansible-hosts-sample.cfg" ]] && cp "./templates/ansible-hosts-sample.cfg" "$ANSIBLE_HOSTS_FILE"
  20. # Install ansible if not installed
  21. if ! command -v ansible > /dev/null; then
  22. echo "Installing Ansible..."
  23. apt-get update
  24. apt-get install -y software-properties-common
  25. apt-add-repository -y ppa:ansible/ansible
  26. apt-get update
  27. apt-get install -y ansible
  28. fi
  29. # Install ssh-keygen if not installed
  30. if ! command -v ssh-keygen > /dev/null; then
  31. echo "Installing ssh-keygen..."
  32. apt-get update
  33. apt-get install -y ssh-keygen
  34. fi
  35. # Generate ssh keys
  36. if [[ ! -f "~/ssh/id_rsa_tipi" ]]; then
  37. echo "Generating ssh keys..."
  38. mkdir -p "~/ssh"
  39. ssh-keygen -t rsa -b 4096 -f "~/ssh/id_rsa_tipi" -N ""
  40. fi
  41. echo "Generating config files..."
  42. for template in "${ENV_FILE}" "${ANSIBLE_HOSTS_FILE}"; do
  43. # Umbrel
  44. sed -i "s/<network-ip>/${NETWORK_IP}/g" "${template}"
  45. sed -i "s/<gateway-ip>/${GATEWAY_IP}/g" "${template}"
  46. sed -i "s/<nginx-ip>/${NGINX_IP}/g" "${template}"
  47. sed -i "s/<nginx-port>/${NGINX_PORT}/g" "${template}"
  48. # Apps
  49. sed -i "s/<app-pi-hole-port>/${APP_PI_HOLE_PORT}/g" "${template}"
  50. sed -i "s/<app-pi-hole-ip>/${APP_PI_HOLE_IP}/g" "${template}"
  51. # Ansible
  52. sed -i "s/<host_ip>/${TIPI_IP}/g" "${template}"
  53. sed -i "s/<username>/${USERNAME}/g" "${template}"
  54. done
  55. # Copy SSH keys to ansible host
  56. echo "Copying SSH keys to tipi server..."
  57. ssh-copy-id -i "~/ssh/id_rsa_tipi" "${USERNAME}@${TIPI_IP}"
  58. mv -f "$ENV_FILE" "./.env"
  59. mv -f "$ANSIBLE_HOSTS_FILE" "./ansible/hosts"
  60. echo "Configuring permissions..."
  61. find "$UMBREL_ROOT" -path "$UMBREL_ROOT/app-data" -prune -o -exec chown 1000:1000 {} + || true
  62. # Run ansible playbook
  63. echo "Running Ansible playbook..."
  64. ansible-playbook -i "./ansible/hosts" "./ansible/playbook.yml"