120 lines
4.3 KiB
Bash
Executable File
120 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script pour ajouter les variables d'environnement manquantes dans la nouvelle structure env/<project>/.env
|
|
|
|
set -e
|
|
|
|
# Couleurs pour l'affichage
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
ENV_DIR="/home/debian/4NK_env/env"
|
|
BACKUP_DIR="${ENV_DIR}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo -e "${BLUE} Ajout des Variables d'Environnement Manquantes${NC}"
|
|
echo -e "${BLUE} Nouvelle Structure env/<project>/.env${NC}"
|
|
echo -e "${BLUE}========================================${NC}"
|
|
echo
|
|
|
|
# Fonction pour vérifier si une variable existe dans un fichier
|
|
check_var_exists() {
|
|
local env_file="$1"
|
|
local var_name="$2"
|
|
grep -q "^${var_name}=" "$env_file" 2>/dev/null
|
|
}
|
|
|
|
# Fonction pour ajouter une variable si elle n'existe pas
|
|
add_var_if_missing() {
|
|
local env_file="$1"
|
|
local var_name="$2"
|
|
local var_value="$3"
|
|
local description="$4"
|
|
|
|
if ! check_var_exists "$env_file" "$var_name"; then
|
|
echo -e "${YELLOW}Ajout de ${var_name} dans $(basename $(dirname $env_file)): ${description}${NC}"
|
|
echo "${var_name}=${var_value}" >> "$env_file"
|
|
return 0
|
|
else
|
|
echo -e "${GREEN}✓ ${var_name} existe déjà dans $(basename $(dirname $env_file))${NC}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Créer une sauvegarde
|
|
echo -e "${BLUE}Création d'une sauvegarde: ${BACKUP_DIR}${NC}"
|
|
cp -r "$ENV_DIR" "$BACKUP_DIR"
|
|
|
|
echo -e "${BLUE}Ajout des variables manquantes...${NC}"
|
|
echo
|
|
|
|
# Variables pour lecoffre_node
|
|
echo -e "${CYAN}=== Variables lecoffre_node ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/lecoffre_node/.env" "BITCOIN_RPC_USER" "bitcoin_user" "Nom d'utilisateur RPC Bitcoin"
|
|
add_var_if_missing "$ENV_DIR/lecoffre_node/.env" "BITCOIN_RPC_PASSWORD" "FAKE-DATA-IA-bitcoin_password_secure" "Mot de passe RPC Bitcoin"
|
|
add_var_if_missing "$ENV_DIR/lecoffre_node/.env" "BITCOIN_RPC_PORT" "38332" "Port RPC Bitcoin"
|
|
|
|
echo
|
|
|
|
# Variables pour blindbit-oracle
|
|
echo -e "${CYAN}=== Variables blindbit-oracle ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/blindbit-oracle/.env" "BLINDBIT_API_PORT" "8000" "Port de l'API BlindBit"
|
|
add_var_if_missing "$ENV_DIR/blindbit-oracle/.env" "BITCOIN_RPC_URL" "http://bitcoin:38332" "URL du RPC Bitcoin"
|
|
|
|
echo
|
|
|
|
# Variables pour sdk_relay
|
|
echo -e "${CYAN}=== Variables sdk_relay ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/sdk_relay/.env" "RELAY_PORT" "8090" "Port du relay"
|
|
add_var_if_missing "$ENV_DIR/sdk_relay/.env" "RELAY_HTTP_PORT" "8091" "Port HTTP du relay"
|
|
add_var_if_missing "$ENV_DIR/sdk_relay/.env" "STORAGE_URL" "http://sdk_storage:8080" "URL du service de stockage"
|
|
|
|
echo
|
|
|
|
# Variables pour sdk_storage
|
|
echo -e "${CYAN}=== Variables sdk_storage ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/sdk_storage/.env" "STORAGE_PORT" "8080" "Port du service de stockage"
|
|
add_var_if_missing "$ENV_DIR/sdk_storage/.env" "STORAGE_DATA_DIR" "/app/data" "Répertoire des données de stockage"
|
|
|
|
echo
|
|
|
|
# Variables pour ihm_client
|
|
echo -e "${CYAN}=== Variables ihm_client ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/ihm_client/.env" "VITE_API_URL" "https://dev4.4nkweb.com/api" "URL de l'API pour Vite"
|
|
add_var_if_missing "$ENV_DIR/ihm_client/.env" "VITE_4NK_URL" "https://dev4.4nkweb.com" "URL 4NK pour Vite"
|
|
add_var_if_missing "$ENV_DIR/ihm_client/.env" "VITE_RELAY_URL" "wss://dev4.4nkweb.com/ws" "URL du relay pour Vite"
|
|
|
|
echo
|
|
|
|
# Variables pour lecoffre-front
|
|
echo -e "${CYAN}=== Variables lecoffre-front ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/lecoffre-front/.env" "NEXTJS_APP_ENV_NAME" "development" "Nom de l'environnement Next.js"
|
|
|
|
echo
|
|
|
|
# Variables pour monitoring
|
|
echo -e "${CYAN}=== Variables monitoring ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/monitoring/.env" "GRAFANA_ADMIN_USER" "admin" "Utilisateur admin Grafana"
|
|
add_var_if_missing "$ENV_DIR/monitoring/.env" "GRAFANA_ADMIN_PASSWORD" "admin123" "Mot de passe admin Grafana"
|
|
|
|
echo
|
|
|
|
# Variables pour sdk_signer
|
|
echo -e "${CYAN}=== Variables sdk_signer ===${NC}"
|
|
add_var_if_missing "$ENV_DIR/sdk_signer/.env" "SIGNER_LOG_LEVEL" "info" "Niveau de log du signer"
|
|
|
|
echo
|
|
|
|
echo -e "${GREEN}✅ Variables ajoutées avec succès !${NC}"
|
|
echo
|
|
echo -e "${BLUE}Fichiers:${NC}"
|
|
echo -e "${YELLOW} - Répertoire principal: ${ENV_DIR}${NC}"
|
|
echo -e "${YELLOW} - Sauvegarde: ${BACKUP_DIR}${NC}"
|
|
echo
|
|
echo -e "${BLUE}Pour tester:${NC}"
|
|
echo -e "${YELLOW} cd /home/debian/4NK_env/scripts${NC}"
|
|
echo -e "${YELLOW} ./test-env-config.sh${NC}"
|
|
echo
|