-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_github_credentials.sh
More file actions
executable file
·162 lines (136 loc) · 4.84 KB
/
Copy pathsetup_github_credentials.sh
File metadata and controls
executable file
·162 lines (136 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# Script para configurar credenciais GitHub
# Barramento MCPs v2.0
set -e
# Cores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}🔧 Configuração de Credenciais GitHub - Barramento MCPs v2.0${NC}"
echo ""
# Verificar se já está configurado
if [ ! -z "$GITHUB_TOKEN" ] && [ ! -z "$GITHUB_USERNAME" ]; then
echo -e "${GREEN}✅ Credenciais já configuradas!${NC}"
echo "GITHUB_TOKEN: ${GITHUB_TOKEN:0:10}..."
echo "GITHUB_USERNAME: $GITHUB_USERNAME"
echo ""
read -p "Deseja reconfigurar? (y/N): " reconfigure
if [[ ! $reconfigure =~ ^[Yy]$ ]]; then
echo -e "${GREEN}✅ Usando credenciais existentes${NC}"
exit 0
fi
fi
echo -e "${YELLOW}📋 Para obter um token GitHub:${NC}"
echo "1. Acesse: https://github.com/settings/tokens"
echo "2. Clique em 'Generate new token (classic)'"
echo "3. Configure:"
echo " - Note: 'Barramento MCPs v2.0'"
echo " - Expiration: 90 days"
echo " - Scopes: repo, workflow, admin:org"
echo "4. Copie o token (começa com ghp_)"
echo ""
# Solicitar token
read -p "🔑 Cole seu token GitHub: " github_token
if [ -z "$github_token" ]; then
echo -e "${RED}❌ Token não pode estar vazio${NC}"
exit 1
fi
# Verificar formato do token
if [[ ! $github_token =~ ^ghp_ ]]; then
echo -e "${RED}❌ Token inválido. Deve começar com 'ghp_'${NC}"
exit 1
fi
# Solicitar username
read -p "👤 Digite seu username GitHub: " github_username
if [ -z "$github_username" ]; then
echo -e "${RED}❌ Username não pode estar vazio${NC}"
exit 1
fi
# Testar credenciais
echo ""
echo -e "${BLUE}🧪 Testando credenciais...${NC}"
# Testar token
response=$(curl -s -H "Authorization: token $github_token" https://api.github.com/user)
if echo "$response" | grep -q '"login"'; then
echo -e "${GREEN}✅ Token válido!${NC}"
api_username=$(echo "$response" | grep '"login"' | cut -d'"' -f4)
echo "Username da API: $api_username"
# Verificar se username confere
if [ "$api_username" != "$github_username" ]; then
echo -e "${YELLOW}⚠️ Username informado ($github_username) difere do token ($api_username)${NC}"
read -p "Usar $api_username? (Y/n): " use_api_username
if [[ ! $use_api_username =~ ^[Nn]$ ]]; then
github_username=$api_username
fi
fi
else
echo -e "${RED}❌ Token inválido ou sem permissões${NC}"
echo "Resposta da API: $response"
exit 1
fi
# Verificar rate limit
rate_limit=$(curl -s -H "Authorization: token $github_token" https://api.github.com/rate_limit)
remaining=$(echo "$rate_limit" | grep '"remaining"' | cut -d':' -f2 | tr -d ' ,')
echo "Rate limit restante: $remaining requests"
if [ "$remaining" -lt 100 ]; then
echo -e "${YELLOW}⚠️ Rate limit baixo. Aguarde o reset.${NC}"
fi
# Configurar variáveis de ambiente
echo ""
echo -e "${BLUE}💾 Configurando variáveis de ambiente...${NC}"
# Adicionar ao .bashrc/.zshrc
shell_config=""
if [ -f "$HOME/.zshrc" ]; then
shell_config="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
shell_config="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
shell_config="$HOME/.bash_profile"
fi
if [ ! -z "$shell_config" ]; then
# Remover configurações antigas
sed -i.bak '/^export GITHUB_TOKEN=/d' "$shell_config" 2>/dev/null || true
sed -i.bak '/^export GITHUB_USERNAME=/d' "$shell_config" 2>/dev/null || true
# Adicionar novas configurações
echo "" >> "$shell_config"
echo "# GitHub credentials for Barramento MCPs v2.0" >> "$shell_config"
echo "export GITHUB_TOKEN=\"$github_token\"" >> "$shell_config"
echo "export GITHUB_USERNAME=\"$github_username\"" >> "$shell_config"
echo -e "${GREEN}✅ Variáveis adicionadas ao $shell_config${NC}"
fi
# Configurar para sessão atual
export GITHUB_TOKEN="$github_token"
export GITHUB_USERNAME="$github_username"
# Criar arquivo .env
cat > .env << EOF
# GitHub credentials for Barramento MCPs v2.0
GITHUB_TOKEN=$github_token
GITHUB_USERNAME=$github_username
# Outras configurações
LOG_LEVEL=INFO
ENVIRONMENT=development
MAX_UPLOAD_SIZE_MB=100
UPLOAD_TIMEOUT_SECONDS=300
MAX_CONCURRENT_UPLOADS=3
ENABLE_METRICS=true
ENABLE_TRACING=true
ENABLE_GOVERNANCE=true
EOF
echo -e "${GREEN}✅ Arquivo .env criado${NC}"
# Verificar configuração final
echo ""
echo -e "${GREEN}🎉 Configuração concluída!${NC}"
echo ""
echo "📊 Resumo da configuração:"
echo " 🔑 Token: ${GITHUB_TOKEN:0:10}..."
echo " 👤 Username: $GITHUB_USERNAME"
echo " 📁 Arquivo .env: $(pwd)/.env"
echo " 📝 Shell config: $shell_config"
echo ""
echo -e "${BLUE}🚀 Próximos passos:${NC}"
echo "1. Recarregue o shell: source $shell_config"
echo "2. Execute o upload: ./scripts/upload_project_to_github.sh barramento-mcps-v2"
echo ""
echo -e "${GREEN}✅ Credenciais GitHub configuradas com sucesso!${NC}"