#!/bin/bash # Homelab Setup Script echo "🏠 Setting up homelab directories and files..." # Create main directories mkdir -p traefik/letsencrypt mkdir -p gitea mkdir -p registry mkdir -p wol-api mkdir -p pihole/etc-pihole mkdir -p pihole/etc-dnsmasq.d mkdir -p wireguard/config # Set proper permissions chmod 600 traefik/letsencrypt chmod 755 gitea registry pihole/etc-pihole pihole/etc-dnsmasq.d wireguard/config # Create .env file cat > .env << 'EOF' # Pi-hole admin password PIHOLE_PASSWORD=your_secure_password_here # Change this to a secure password! EOF # Create basic traefik.yml config cat > traefik/traefik.yml << 'EOF' # Static configuration api: dashboard: true insecure: false entryPoints: web: address: ":80" http: redirections: entryPoint: to: websecure scheme: https permanent: true websecure: address: ":443" providers: docker: endpoint: "unix:///var/run/docker.sock" exposedByDefault: false certificatesResolvers: leresolver: acme: httpChallenge: entryPoint: web email: your-email@example.com storage: /letsencrypt/acme.json EOF # Create basic WOL API Dockerfile cat > wol-api/Dockerfile << 'EOF' FROM python:3.9-slim WORKDIR /app # Install wake-on-lan package RUN pip install flask wakeonlan COPY app.py . EXPOSE 5000 CMD ["python", "app.py"] EOF # Create basic WOL API application cat > wol-api/app.py << 'EOF' from flask import Flask, request, jsonify from wakeonlan import send_magic_packet import logging app = Flask(__name__) logging.basicConfig(level=logging.INFO) # Define your devices here DEVICES = { "desktop": "00:11:22:33:44:55", # Replace with actual MAC addresses "laptop": "AA:BB:CC:DD:EE:FF", # Add more devices as needed } @app.route('/wake/', methods=['POST']) def wake_device(device): if device not in DEVICES: return jsonify({"error": "Device not found"}), 404 try: mac_address = DEVICES[device] send_magic_packet(mac_address) app.logger.info(f"Magic packet sent to {device} ({mac_address})") return jsonify({"message": f"Wake-on-LAN packet sent to {device}"}), 200 except Exception as e: app.logger.error(f"Error sending wake packet: {e}") return jsonify({"error": "Failed to send wake packet"}), 500 @app.route('/devices', methods=['GET']) def list_devices(): return jsonify({"devices": list(DEVICES.keys())}) @app.route('/health', methods=['GET']) def health_check(): return jsonify({"status": "healthy"}), 200 if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=False) EOF # Create Pi-hole custom DNS config cat > pihole/etc-dnsmasq.d/02-custom.conf << 'EOF' # Allow queries from local network interface=eth0 listen-address=127.0.0.1,0.0.0.0 bind-interfaces # Custom DNS entries for your homelab # Format: address=/domain.name/IP address=/traefik.zea.lt/192.168.1.100 address=/git.zea.lt/192.168.1.100 address=/registry.zea.lt/192.168.1.100 address=/wol.zea.lt/192.168.1.100 address=/pihole.zea.lt/192.168.1.100 EOF # Create startup script cat > start.sh << 'EOF' #!/bin/bash echo "🚀 Starting homelab services..." docker-compose up -d echo "✅ Services started!" echo "" echo "🔗 Access points:" echo " - Traefik Dashboard: https://traefik.zea.lt" echo " - Gitea: https://git.zea.lt" echo " - Pi-hole: https://pihole.zea.lt" echo " - Docker Registry: https://registry.zea.lt" echo " - WOL API: https://wol.zea.lt" echo "" echo "📋 Next steps:" echo " 1. Check WireGuard logs: docker logs wireguard" echo " 2. Get VPN configs from: ./wireguard/config/peer1/" echo " 3. Update .env with secure passwords" echo " 4. Update MAC addresses in wol-api/app.py" echo " 5. Update server IP in pihole/etc-dnsmasq.d/02-custom.conf" EOF # Create stop script cat > stop.sh << 'EOF' #!/bin/bash echo "🛑 Stopping homelab services..." docker-compose down echo "✅ Services stopped!" EOF # Create update script cat > update.sh << 'EOF' #!/bin/bash echo "🔄 Updating homelab services..." docker-compose pull docker-compose up -d echo "✅ Services updated!" EOF # Make scripts executable chmod +x start.sh stop.sh update.sh # Create .gitignore cat > .gitignore << 'EOF' # Sensitive data .env traefik/letsencrypt/ gitea/ registry/ pihole/etc-pihole/ wireguard/config/ # Logs *.log EOF echo "✅ Homelab setup complete!" echo "" echo "📝 TODO before starting:" echo " 1. Update .env with secure passwords" echo " 2. Update MAC addresses in wol-api/app.py" echo " 3. Update server IP in pihole/etc-dnsmasq.d/02-custom.conf" echo " 4. Make sure your domains (*.zea.lt) point to your server" echo "" echo "🚀 To start: ./start.sh" echo "🛑 To stop: ./stop.sh" echo "🔄 To update: ./update.sh"