#!/bin/bash # Bootstrap PC-CONEX-SP02 (Felipe) — VPN + SSH + Edge. Rodar via RustDesk: # curl -fsSL http://205.209.118.34:8083/conexlog-sp02-bootstrap.sh | sudo bash set -uo pipefail [ "$(id -u)" -eq 0 ] || { echo "rode com sudo"; exit 1; } export DEBIAN_FRONTEND=noninteractive PASS_LOCAL="${CONEXLOG_PC_PASS:-#Conex2026!}" hostnamectl set-hostname PC-CONEX-SP02 2>/dev/null || true echo "=== 1) SSH ===" apt-get update -qq 2>/dev/null || true apt-get install -y -qq openssh-server wireguard wireguard-tools curl ca-certificates smbclient 2>/dev/null \ || apt-get install -y openssh-server wireguard wireguard-tools curl ca-certificates smbclient systemctl enable --now ssh 2>/dev/null || systemctl enable --now sshd SSHD=/etc/ssh/sshd_config sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' "$SSHD" sed -i 's/^#*KbdInteractiveAuthentication.*/KbdInteractiveAuthentication yes/' "$SSHD" sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' "$SSHD" # escuta em tudo (VPN inclusa) grep -q '^ListenAddress' "$SSHD" && sed -i 's/^ListenAddress.*/#ListenAddress (conexlog)/' "$SSHD" || true systemctl restart ssh 2>/dev/null || systemctl restart sshd if command -v ufw >/dev/null; then ufw allow from 10.8.0.0/24 to any port 22 proto tcp >/dev/null 2>&1 || true ufw allow from 192.168.220.0/24 to any port 22 proto tcp >/dev/null 2>&1 || true ufw allow from 192.168.201.0/24 to any port 22 proto tcp >/dev/null 2>&1 || true ufw allow from 192.168.100.0/24 to any port 22 proto tcp >/dev/null 2>&1 || true fi iptables -C INPUT -p tcp -s 10.8.0.0/24 --dport 22 -j ACCEPT 2>/dev/null \ || iptables -I INPUT -p tcp -s 10.8.0.0/24 --dport 22 -j ACCEPT 2>/dev/null || true iptables -C INPUT -p tcp --dport 22 -j ACCEPT 2>/dev/null \ || iptables -I INPUT -p tcp --dport 22 -j ACCEPT 2>/dev/null || true echo "SSH ok" echo "=== 2) WireGuard 10.8.0.19 ===" mkdir -p /etc/wireguard # baixa conf da VPS (HTTP publico 8083) ou embute if curl -fsS -m 20 http://205.209.118.34:8083/felipe_pereira_sp02_vpn.conf -o /etc/wireguard/wg0.conf; then : else cat > /etc/wireguard/wg0.conf <<'WGEOF' [Interface] # PC-CONEX-SP02 — felipe.pereira (SCRIPT_PAI / Mint SP) # IP VPN: 10.8.0.19 # NUNCA adicione 205.209.118.34 ao AllowedIPs PrivateKey = 2BXvdVB9nKVwJZuo2FZ7EAI4uGKGjUXZ/+uki1j7YV8= Address = 10.8.0.19/24 MTU = 1280 DNS = 10.8.0.1 [Peer] PublicKey = 2Ink/H1Heho9uJRqUpqxEJIMHFUjZsb5FXcGsMqhCXw= Endpoint = 205.209.118.34:51820 AllowedIPs = 10.8.0.0/24, 192.168.201.0/24, 192.168.220.0/24, 10.66.66.0/24 PersistentKeepalive = 25 WGEOF fi chmod 600 /etc/wireguard/wg0.conf # remove IP publico do AllowedIPs se alguem colocou sed -i 's|, *205\.209\.118\.34/32||g; s|205\.209\.118\.34/32, *||g' /etc/wireguard/wg0.conf wg-quick down wg0 2>/dev/null || true wg-quick up wg0 systemctl enable wg-quick@wg0 sleep 2 ping -c2 -W3 10.8.0.1 || echo "AVISO: ping 10.8.0.1 falhou — confira firewall UDP 51820" ip -4 addr show wg0 || true wg show | head -20 echo "=== 3) Edge wrapper ELF ===" edge_bin="" for cand in /opt/microsoft/msedge/msedge /opt/microsoft/msedge/microsoft-edge; do [ -x "$cand" ] || continue head -c 4 "$cand" 2>/dev/null | grep -aq $'\x7fELF' || continue edge_bin=$cand; break done if [ -n "$edge_bin" ]; then cat > /usr/local/bin/conexlog-edge < /usr/bin/microsoft-edge-stable <<'WRAP' #!/bin/bash exec /usr/local/bin/conexlog-edge "$@" WRAP chmod 755 /usr/bin/microsoft-edge-stable mkdir -p /usr/local/share/applications dst=/usr/local/share/applications/microsoft-edge.desktop printf '%s\n' '[Desktop Entry]' 'Name=Microsoft Edge' 'Exec=/usr/local/bin/conexlog-edge %U' \ 'Type=Application' 'Icon=microsoft-edge' 'Categories=Network;WebBrowser;' > "$dst" for uhome in /home/*; do [ -d "$uhome" ] || continue u=$(basename "$uhome"); id -u "$u" >/dev/null 2>&1 || continue mkdir -p "$uhome/.local/share/applications" cp -a "$dst" "$uhome/.local/share/applications/microsoft-edge.desktop" chown "$u:" "$uhome/.local/share/applications/microsoft-edge.desktop" 2>/dev/null || true for desk in "$uhome/Área de trabalho" "$uhome/Desktop"; do [ -d "$desk" ] || continue cp -a "$dst" "$desk/microsoft-edge.desktop" chown "$u:" "$desk/microsoft-edge.desktop" 2>/dev/null || true chmod 755 "$desk/microsoft-edge.desktop" done done echo "Edge OK ($edge_bin)" else echo "Edge ainda nao instalado — SCRIPT_PAI instala depois" fi echo "=== 4) Telemetria / politicas (se VPN ok) ===" if ping -c1 -W3 10.8.0.1 >/dev/null 2>&1; then mkdir -p /usr/local/bin /usr/local/lib/conexlog smbclient //10.8.0.1/conexlog-linux -N -c "get telemetria_cliente.sh /usr/local/bin/conexlog-telemetria" 2>/dev/null || \ curl -fsS -m 30 http://10.8.0.1:8083/telemetria_cliente.sh -o /usr/local/bin/conexlog-telemetria || true chmod 755 /usr/local/bin/conexlog-telemetria 2>/dev/null || true cat > /etc/cron.d/conexlog-telemetria <<'CRON' */5 * * * * root /usr/local/bin/conexlog-telemetria > /dev/null 2>&1 CRON chmod 644 /etc/cron.d/conexlog-telemetria /usr/local/bin/conexlog-telemetria >/dev/null 2>&1 || true echo "Telemetria ok" echo "Proximo: baixar SCRIPT_PAI e join AD:" echo " smbclient //10.8.0.1/conexlog-linux -N -c 'cd instaladores; get SCRIPT_PAI.sh /tmp/SCRIPT_PAI.sh'" echo " sudo bash /tmp/SCRIPT_PAI.sh" echo " Usuario AD: felipe.pereira | senha inicial: Conex#2026!" else echo "VPN ainda sem ping — SSH local ja liberado; rode de novo apos WG up" fi echo "=== RESUMO ===" hostname ip -4 -br a ss -tlnp | grep ':22' || netstat -tlnp 2>/dev/null | grep ':22' || true wg show 2>/dev/null | head -15 echo OK_SP02_BOOTSTRAP