From 201d77c41c55b8c49e87720af73038e82f113300 Mon Sep 17 00:00:00 2001 From: daniele Date: Sat, 27 Dec 2025 09:52:35 +0100 Subject: [PATCH] Add new-vpn-user.sh (Pi1 VPN helper) --- scripts/pi1-master/new-vpn-user.sh | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 scripts/pi1-master/new-vpn-user.sh diff --git a/scripts/pi1-master/new-vpn-user.sh b/scripts/pi1-master/new-vpn-user.sh new file mode 100755 index 0000000..e71e3eb --- /dev/null +++ b/scripts/pi1-master/new-vpn-user.sh @@ -0,0 +1,40 @@ +#!/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