fix: scripts properly set ENABLED flags and all env vars for providers
setup-env.sh: - Each provider choice now sets its *_ENABLEED=true flag explicitly - All provider fields written to .env (model, base_url, api_key, enabled) - Shows active provider status in summary manage-keys.sh: - Each provider menu sets *_ENABLEED=true when key is added - Sets *_ENABLEED=false when key is removed - Writes all required env vars (model, base_url) not just API key - Shows provider status with enabled/disabled state - Better organized menu Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
|
||||
ENV_FILE=".env"
|
||||
|
||||
# Couleurs
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
@@ -17,19 +16,16 @@ BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
echo -e "${RED}Fichier .env non trouve. Lance d'abord: bash scripts/setup-env.sh${NC}"
|
||||
echo -e "${RED}.env non trouve. Lance d'abord: bash scripts/setup-env.sh${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Fonction pour lire une valeur dans .env
|
||||
get_env() {
|
||||
grep "^${1}=" "$ENV_FILE" 2>/dev/null | cut -d'=' -f2- || echo ""
|
||||
}
|
||||
|
||||
# Fonction pour ecrire une valeur dans .env
|
||||
set_env() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local key="$1" value="$2"
|
||||
if grep -q "^${key}=" "$ENV_FILE"; then
|
||||
sed -i "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
|
||||
else
|
||||
@@ -37,29 +33,33 @@ set_env() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Fonction pour effacer une valeur dans .env
|
||||
clear_env() {
|
||||
local key="$1"
|
||||
sed -i "s|^${key}=.*|${key}=|" "$ENV_FILE"
|
||||
}
|
||||
|
||||
# Fonction pour afficher le statut d'une cle
|
||||
show_key_status() {
|
||||
local name="$1"
|
||||
local key="$2"
|
||||
show_status() {
|
||||
local name="$1" key="$2"
|
||||
local value=$(get_env "$key")
|
||||
if [ -n "$value" ] && [ "$value" != "" ]; then
|
||||
local enabled_key="${3:-}"
|
||||
local enabled=""
|
||||
if [ -n "$enabled_key" ]; then
|
||||
enabled=$(get_env "$enabled_key")
|
||||
fi
|
||||
|
||||
if [ -z "$value" ]; then
|
||||
echo -e " ${RED}--${NC} ${name}: ${YELLOW}non configure${NC}"
|
||||
elif [ -n "$enabled_key" ] && [ "$enabled" != "true" ]; then
|
||||
local masked="${value:0:8}...${value: -4}"
|
||||
echo -e " ${YELLOW}!!${NC} ${name}: ${masked} ${YELLOW}(desactive)${NC}"
|
||||
else
|
||||
local masked="${value:0:8}...${value: -4}"
|
||||
echo -e " ${GREEN}OK${NC} ${name}: ${masked}"
|
||||
else
|
||||
echo -e " ${RED}--${NC} ${name}: ${YELLOW}non configure${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Fonction pour demander une cle
|
||||
ask_key() {
|
||||
local name="$1"
|
||||
local key="$2"
|
||||
local name="$1" key="$2"
|
||||
local current=$(get_env "$key")
|
||||
|
||||
echo ""
|
||||
@@ -67,7 +67,7 @@ ask_key() {
|
||||
local masked="${current:0:8}...${current: -4}"
|
||||
echo -e " Actuel: ${masked}"
|
||||
fi
|
||||
echo -ne " ${YELLOW}Nouvelle cle (Enter pour garder, 'x' pour effacer):${NC} "
|
||||
echo -ne " ${YELLOW}Nouvelle valeur (Enter = garder, 'x' = effacer):${NC} "
|
||||
stty -echo 2>/dev/null || true
|
||||
read -r value
|
||||
stty echo 2>/dev/null || true
|
||||
@@ -75,94 +75,172 @@ ask_key() {
|
||||
|
||||
if [ "$value" = "x" ]; then
|
||||
clear_env "$key"
|
||||
echo -e " ${RED}Cle supprimee${NC}"
|
||||
echo -e " ${RED}Supprime${NC}"
|
||||
elif [ -n "$value" ]; then
|
||||
set_env "$key" "$value"
|
||||
echo -e " ${GREEN}Cle mise a jour${NC}"
|
||||
echo -e " ${GREEN}Mis a jour${NC}"
|
||||
else
|
||||
echo -e " ${CYAN}Inchange${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
ask_value() {
|
||||
local name="$1" key="$2" default="$3"
|
||||
local current=$(get_env "$key")
|
||||
echo -ne " ${YELLOW}${name}${NC} [${current:-$default}]: "
|
||||
read -r value
|
||||
if [ -n "$value" ]; then
|
||||
set_env "$key" "$value"
|
||||
elif [ -z "$current" ] && [ -n "$default" ]; then
|
||||
set_env "$key" "$default"
|
||||
fi
|
||||
}
|
||||
|
||||
restart_hint() {
|
||||
echo ""
|
||||
echo -e " ${YELLOW}Redemarre pour appliquer: docker compose restart backend${NC}"
|
||||
}
|
||||
|
||||
# ===========================================
|
||||
# Menu principal
|
||||
# Menu
|
||||
# ===========================================
|
||||
while true; do
|
||||
echo ""
|
||||
echo -e "${CYAN}${BOLD}=========================================${NC}"
|
||||
echo -e "${CYAN}${BOLD} Wordly.art - Gestion des cles API${NC}"
|
||||
echo -e "${CYAN}${BOLD} Wordly - Gestion des cles API${NC}"
|
||||
echo -e "${CYAN}${BOLD}=========================================${NC}"
|
||||
echo ""
|
||||
echo -e "${BOLD}Statut actuel :${NC}"
|
||||
echo -e " Service actif: ${BOLD}$(get_env TRANSLATION_SERVICE)${NC}"
|
||||
echo ""
|
||||
|
||||
# Traduction
|
||||
echo -e " ${BOLD}Traduction :${NC}"
|
||||
show_key_status "OpenAI" "OPENAI_API_KEY"
|
||||
show_key_status "DeepL" "DEEPL_API_KEY"
|
||||
show_key_status "OpenRouter" "OPENROUTER_API_KEY"
|
||||
show_key_status "DeepSeek" "DEEPSEEK_API_KEY"
|
||||
show_key_status "Minimax" "MINIMAX_API_KEY"
|
||||
show_key_status "Google" "GOOGLE_API_KEY"
|
||||
echo -e " ${BOLD}Providers:${NC}"
|
||||
show_status "Google " "GOOGLE_TRANSLATE_ENABLED"
|
||||
show_status "Ollama " "OLLAMA_BASE_URL" "OLLAMA_ENABLED"
|
||||
show_status "DeepSeek " "DEEPSEEK_API_KEY" "DEEPSEEK_ENABLED"
|
||||
show_status "Minimax " "MINIMAX_API_KEY" "MINIMAX_ENABLED"
|
||||
show_status "DeepL " "DEEPL_API_KEY" "DEEPL_ENABLED"
|
||||
show_status "OpenAI " "OPENAI_API_KEY" "OPENAI_ENABLED"
|
||||
show_status "OpenRouter " "OPENROUTER_API_KEY" "OPENROUTER_ENABLED"
|
||||
echo ""
|
||||
|
||||
# Paiement
|
||||
echo -e " ${BOLD}Paiement :${NC}"
|
||||
show_key_status "Stripe Secret" "STRIPE_SECRET_KEY"
|
||||
show_key_status "Stripe Webhook" "STRIPE_WEBHOOK_SECRET"
|
||||
show_key_status "Stripe Price Starter" "STRIPE_STARTER_PRICE_ID"
|
||||
show_key_status "Stripe Price Pro" "STRIPE_PRO_PRICE_ID"
|
||||
show_key_status "Stripe Price Business" "STRIPE_BUSINESS_PRICE_ID"
|
||||
echo -e " ${BOLD}Stripe:${NC}"
|
||||
show_status "Secret Key " "STRIPE_SECRET_KEY"
|
||||
show_status "Webhook " "STRIPE_WEBHOOK_SECRET"
|
||||
show_status "Starter " "STRIPE_STARTER_PRICE_ID"
|
||||
show_status "Pro " "STRIPE_PRO_PRICE_ID"
|
||||
show_status "Business " "STRIPE_BUSINESS_PRICE_ID"
|
||||
echo ""
|
||||
|
||||
# Menu
|
||||
echo -e "${BOLD}Actions :${NC}"
|
||||
echo " 1) Configurer OpenAI"
|
||||
echo " 2) Configurer DeepL"
|
||||
echo " 3) Configurer OpenRouter"
|
||||
echo " 4) Configurer Stripe (toutes les cles)"
|
||||
echo " 5) Changer le mot de passe admin"
|
||||
echo " 6) Changer le service de traduction"
|
||||
echo " 7) Configurer DeepSeek"
|
||||
echo " 8) Configurer Minimax (m2.7)"
|
||||
echo " 9) Tout afficher (attention: secrets visibles)"
|
||||
echo " 0) Quitter"
|
||||
echo -e "${BOLD}Actions:${NC}"
|
||||
echo " 1) DeepSeek 4) OpenAI 7) Stripe"
|
||||
echo " 2) Minimax 5) DeepL 8) Mot de passe admin"
|
||||
echo " 3) OpenRouter 6) Ollama 9) Changer provider par defaut"
|
||||
echo ""
|
||||
echo " 0) Quitter v) Voir tout (.env brut)"
|
||||
echo ""
|
||||
echo -ne "${YELLOW}Choix:${NC} "
|
||||
read -r choice
|
||||
|
||||
case "$choice" in
|
||||
1)
|
||||
echo -e "\n${BOLD}--- OpenAI ---${NC}"
|
||||
echo " Ou: https://platform.openai.com/api-keys"
|
||||
ask_key "OpenAI" "OPENAI_API_KEY"
|
||||
echo -e "\n${BOLD}--- DeepSeek ---${NC}"
|
||||
echo " https://platform.deepseek.com/api_keys"
|
||||
ask_key "API Key" "DEEPSEEK_API_KEY"
|
||||
ask_value "Modele" "DEEPSEEK_MODEL" "deepseek-chat"
|
||||
ask_value "Base URL" "DEEPSEEK_BASE_URL" "https://api.deepseek.com/v1"
|
||||
if [ -n "$(get_env DEEPSEEK_API_KEY)" ]; then
|
||||
set_env "DEEPSEEK_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider DeepSeek ACTIVE${NC}"
|
||||
else
|
||||
set_env "DEEPSEEK_ENABLED" "false"
|
||||
echo -e " ${RED}Provider DeepSeek DESACTIVE (pas de cle)${NC}"
|
||||
fi
|
||||
restart_hint
|
||||
;;
|
||||
2)
|
||||
echo -e "\n${BOLD}--- DeepL ---${NC}"
|
||||
echo " Ou: https://www.deepl.com/pro-api (gratuit 500k caracteres/mois)"
|
||||
ask_key "DeepL" "DEEPL_API_KEY"
|
||||
echo -e "\n${BOLD}--- Minimax (m2.7 / MiniMax-M1) ---${NC}"
|
||||
echo " https://platform.minimaxi.com/"
|
||||
ask_key "API Key" "MINIMAX_API_KEY"
|
||||
ask_value "Modele" "MINIMAX_MODEL" "MiniMax-M1"
|
||||
ask_value "Base URL" "MINIMAX_BASE_URL" "https://api.minimax.chat/v1"
|
||||
ask_value "Group ID (optionnel)" "MINIMAX_GROUP_ID" ""
|
||||
if [ -n "$(get_env MINIMAX_API_KEY)" ]; then
|
||||
set_env "MINIMAX_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider Minimax ACTIVE${NC}"
|
||||
else
|
||||
set_env "MINIMAX_ENABLED" "false"
|
||||
echo -e " ${RED}Provider Minimax DESACTIVE (pas de cle)${NC}"
|
||||
fi
|
||||
restart_hint
|
||||
;;
|
||||
3)
|
||||
echo -e "\n${BOLD}--- OpenRouter ---${NC}"
|
||||
echo " Ou: https://openrouter.ai/keys"
|
||||
ask_key "OpenRouter" "OPENROUTER_API_KEY"
|
||||
echo " https://openrouter.ai/keys"
|
||||
ask_key "API Key" "OPENROUTER_API_KEY"
|
||||
ask_value "Modele" "OPENROUTER_MODEL" "deepseek/deepseek-chat"
|
||||
if [ -n "$(get_env OPENROUTER_API_KEY)" ]; then
|
||||
set_env "OPENROUTER_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider OpenRouter ACTIVE${NC}"
|
||||
else
|
||||
set_env "OPENROUTER_ENABLED" "false"
|
||||
echo -e " ${RED}Provider OpenRouter DESACTIVE${NC}"
|
||||
fi
|
||||
restart_hint
|
||||
;;
|
||||
4)
|
||||
echo -e "\n${BOLD}--- Stripe ---${NC}"
|
||||
echo " Ou: https://dashboard.stripe.com/apikeys"
|
||||
echo " Webhooks: https://dashboard.stripe.com/webhooks"
|
||||
echo " Prices: https://dashboard.stripe.com/products"
|
||||
ask_key "Stripe Secret Key" "STRIPE_SECRET_KEY"
|
||||
ask_key "Stripe Webhook Secret" "STRIPE_WEBHOOK_SECRET"
|
||||
ask_key "Price ID Starter" "STRIPE_STARTER_PRICE_ID"
|
||||
ask_key "Price ID Pro" "STRIPE_PRO_PRICE_ID"
|
||||
ask_key "Price ID Business" "STRIPE_BUSINESS_PRICE_ID"
|
||||
echo ""
|
||||
echo -e "${GREEN}Cles Stripe configurees.${NC}"
|
||||
echo -e "${YELLOW}Pense a redemarrer: docker compose restart backend${NC}"
|
||||
echo -e "\n${BOLD}--- OpenAI ---${NC}"
|
||||
echo " https://platform.openai.com/api-keys"
|
||||
ask_key "API Key" "OPENAI_API_KEY"
|
||||
ask_value "Modele" "OPENAI_MODEL" "gpt-4o-mini"
|
||||
ask_value "Base URL" "OPENAI_BASE_URL" "https://api.openai.com/v1"
|
||||
if [ -n "$(get_env OPENAI_API_KEY)" ]; then
|
||||
set_env "OPENAI_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider OpenAI ACTIVE${NC}"
|
||||
else
|
||||
set_env "OPENAI_ENABLED" "false"
|
||||
echo -e " ${RED}Provider OpenAI DESACTIVE${NC}"
|
||||
fi
|
||||
restart_hint
|
||||
;;
|
||||
5)
|
||||
echo -e "\n${BOLD}--- Changer le mot de passe admin ---${NC}"
|
||||
echo -e "\n${BOLD}--- DeepL ---${NC}"
|
||||
echo " https://www.deepl.com/pro-api"
|
||||
ask_key "API Key" "DEEPL_API_KEY"
|
||||
if [ -n "$(get_env DEEPL_API_KEY)" ]; then
|
||||
set_env "DEEPL_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider DeepL ACTIVE${NC}"
|
||||
else
|
||||
set_env "DEEPL_ENABLED" "false"
|
||||
echo -e " ${RED}Provider DeepL DESACTIVE${NC}"
|
||||
fi
|
||||
restart_hint
|
||||
;;
|
||||
6)
|
||||
echo -e "\n${BOLD}--- Ollama (local) ---${NC}"
|
||||
ask_value "URL" "OLLAMA_BASE_URL" "http://ollama:11434"
|
||||
ask_value "Modele" "OLLAMA_MODEL" "llama3"
|
||||
set_env "OLLAMA_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider Ollama ACTIVE${NC}"
|
||||
restart_hint
|
||||
;;
|
||||
7)
|
||||
echo -e "\n${BOLD}--- Stripe ---${NC}"
|
||||
echo " Dashboard: https://dashboard.stripe.com"
|
||||
echo " API Keys: https://dashboard.stripe.com/apikeys"
|
||||
echo " Webhooks: https://dashboard.stripe.com/webhooks"
|
||||
echo " Products: https://dashboard.stripe.com/products"
|
||||
echo ""
|
||||
echo -e " ${CYAN}Mode test: utilise sk_test_... pour tester${NC}"
|
||||
echo -e " ${CYAN}Carte test: 4242 4242 4242 4242${NC}"
|
||||
echo ""
|
||||
ask_key "Secret Key (sk_...)" "STRIPE_SECRET_KEY"
|
||||
ask_key "Webhook Secret (whsec_...)" "STRIPE_WEBHOOK_SECRET"
|
||||
ask_key "Price ID Starter (price_...)" "STRIPE_STARTER_PRICE_ID"
|
||||
ask_key "Price ID Pro (price_...)" "STRIPE_PRO_PRICE_ID"
|
||||
ask_key "Price ID Business (price_...)" "STRIPE_BUSINESS_PRICE_ID"
|
||||
echo ""
|
||||
echo -e " ${GREEN}Stripe configure${NC}"
|
||||
restart_hint
|
||||
;;
|
||||
8)
|
||||
echo -e "\n${BOLD}--- Mot de passe admin ---${NC}"
|
||||
echo -ne " Nouveau mot de passe: "
|
||||
stty -echo 2>/dev/null || true
|
||||
read -r new_pass
|
||||
@@ -175,11 +253,11 @@ while true; do
|
||||
echo ""
|
||||
|
||||
if [ "$new_pass" != "$new_pass2" ]; then
|
||||
echo -e " ${RED}Les mots de passe ne correspondent pas${NC}"
|
||||
echo -e " ${RED}Ne correspondent pas${NC}"
|
||||
elif [ -z "$new_pass" ]; then
|
||||
echo -e " ${RED}Mot de passe vide${NC}"
|
||||
echo -e " ${RED}Vide${NC}"
|
||||
else
|
||||
echo -e " ${CYAN}Generation du hash...${NC}"
|
||||
echo -e " ${CYAN}Generation bcrypt...${NC}"
|
||||
NEW_HASH=$(docker run --rm python:3.12-slim bash -c \
|
||||
"pip install 'passlib[bcrypt]' bcrypt > /dev/null 2>&1 && \
|
||||
python3 -c \"from passlib.context import CryptContext; \
|
||||
@@ -187,69 +265,48 @@ while true; do
|
||||
if [ -n "$NEW_HASH" ]; then
|
||||
set_env "ADMIN_PASSWORD_HASH" "$NEW_HASH"
|
||||
echo -e " ${GREEN}Mot de passe mis a jour${NC}"
|
||||
echo -e " ${YELLOW}Redemarre le backend: docker compose restart backend${NC}"
|
||||
restart_hint
|
||||
else
|
||||
echo -e " ${RED}Erreur lors de la generation du hash${NC}"
|
||||
echo -e " ${RED}Erreur generation hash${NC}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
6)
|
||||
echo -e "\n${BOLD}--- Service de traduction ---${NC}"
|
||||
9)
|
||||
echo -e "\n${BOLD}--- Provider par defaut ---${NC}"
|
||||
echo " Actuel: $(get_env TRANSLATION_SERVICE)"
|
||||
echo " 1) ollama (local, gratuit)"
|
||||
echo " 2) deepl (haute qualite)"
|
||||
echo " 3) openai (GPT)"
|
||||
echo " 4) openrouter (multi-modeles)"
|
||||
echo " 5) deepseek (bon rapport qualite/prix)"
|
||||
echo " 6) minimax (MiniMax-M1 / m2.7)"
|
||||
echo ""
|
||||
echo " 1) google 5) deepseek"
|
||||
echo " 2) ollama 6) minimax"
|
||||
echo " 3) deepl 7) openrouter"
|
||||
echo " 4) openai"
|
||||
echo ""
|
||||
echo -ne " Choix: "
|
||||
read -r svc
|
||||
case "$svc" in
|
||||
1) set_env "TRANSLATION_SERVICE" "ollama" ;;
|
||||
2) set_env "TRANSLATION_SERVICE" "deepl" ;;
|
||||
3) set_env "TRANSLATION_SERVICE" "openai" ;;
|
||||
4) set_env "TRANSLATION_SERVICE" "openrouter" ;;
|
||||
1) set_env "TRANSLATION_SERVICE" "google" ;;
|
||||
2) set_env "TRANSLATION_SERVICE" "ollama" ;;
|
||||
3) set_env "TRANSLATION_SERVICE" "deepl" ;;
|
||||
4) set_env "TRANSLATION_SERVICE" "openai" ;;
|
||||
5) set_env "TRANSLATION_SERVICE" "deepseek" ;;
|
||||
6) set_env "TRANSLATION_SERVICE" "minimax" ;;
|
||||
*) echo -e " ${RED}Choix invalide${NC}" ;;
|
||||
7) set_env "TRANSLATION_SERVICE" "openrouter" ;;
|
||||
*) echo -e " ${RED}Invalide${NC}" ;;
|
||||
esac
|
||||
echo -e " ${GREEN}Service mis a jour${NC}"
|
||||
echo -e " ${YELLOW}Redemarre: docker compose restart backend${NC}"
|
||||
echo -e " ${GREEN}Provider par defaut: $(get_env TRANSLATION_SERVICE)${NC}"
|
||||
restart_hint
|
||||
;;
|
||||
7)
|
||||
echo -e "\n${BOLD}--- DeepSeek ---${NC}"
|
||||
echo " Ou: https://platform.deepseek.com/api_keys"
|
||||
echo " Modele par defaut: deepseek-chat"
|
||||
ask_key "DeepSeek" "DEEPSEEK_API_KEY"
|
||||
if [ -n "$(get_env DEEPSEEK_API_KEY)" ]; then
|
||||
set_env "DEEPSEEK_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider DeepSeek active${NC}"
|
||||
fi
|
||||
;;
|
||||
8)
|
||||
echo -e "\n${BOLD}--- Minimax (m2.7 / MiniMax-M1) ---${NC}"
|
||||
echo " Ou: https://platform.minimaxi.com/"
|
||||
echo " Modele par defaut: MiniMax-M1"
|
||||
ask_key "Minimax" "MINIMAX_API_KEY"
|
||||
if [ -n "$(get_env MINIMAX_API_KEY)" ]; then
|
||||
set_env "MINIMAX_ENABLED" "true"
|
||||
echo -e " ${GREEN}Provider Minimax active${NC}"
|
||||
fi
|
||||
;;
|
||||
9)
|
||||
v)
|
||||
echo ""
|
||||
echo -e "${RED}${BOLD}ATTENTION: Secrets visibles!${NC}"
|
||||
echo -ne "${YELLOW}Taper 'oui' pour continuer:${NC} "
|
||||
echo -ne "${YELLOW}Taper 'oui':${NC} "
|
||||
read -r confirm
|
||||
if [ "$confirm" = "oui" ]; then
|
||||
echo ""
|
||||
cat "$ENV_FILE" | grep -v "^#" | grep -v "^$"
|
||||
grep -v "^#" "$ENV_FILE" | grep -v "^$"
|
||||
fi
|
||||
;;
|
||||
0)
|
||||
echo ""
|
||||
echo -e "${GREEN}Au revoir!${NC}"
|
||||
echo -e "\n${GREEN}Au revoir!${NC}"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user