#!/bin/bash # Verifica se è stato passato un nome utente if [ -z "$1" ]; then echo "Errore: Devi specificare un nome utente." echo "Uso: ./new-vpn-user.sh NomeDispositivo" exit 1 fi USER_NAME="$1" CONFIG_DIR="/home/daniely/configs" CONF_FILE="$CONFIG_DIR/$USER_NAME.conf" QR_FILE="$CONFIG_DIR/$USER_NAME.png" echo "--- Creazione Utente WireGuard: $USER_NAME ---" # 1. Crea l'utente con PiVPN (senza chiedere conferme extra) pivpn add -n "$USER_NAME" # 2. Verifica se il file .conf è stato creato if [ -f "$CONF_FILE" ]; then echo "✅ Configurazione creata: $CONF_FILE" # 3. Genera l'immagine QR Code dal file .conf # Legge il file conf e lo trasforma in un'immagine PNG qrencode -t png -o "$QR_FILE" -r "$CONF_FILE" echo "✅ QR Code generato: $QR_FILE" echo "" echo "-------------------------------------------------------" echo "PER SCARICARE I FILE SUL TUO MAC:" echo "Apri un NUOVO terminale sul Mac (non SSH) e incolla questo:" echo "" # Genera il comando scp dinamico con l'IP corrente del Pi CURRENT_IP=$(hostname -I | awk '{print $1}') echo "scp $USER@$CURRENT_IP:$CONFIG_DIR/$USER_NAME.* ~/Desktop/" echo "-------------------------------------------------------" else echo "❌ Errore: Il file di configurazione non è stato creato." fi