-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_network_switch.sh
executable file
·89 lines (68 loc) · 2.2 KB
/
git_network_switch.sh
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
#!/bin/bash
REQUIREMENTS=(
network-manager
ping
git
)
confirm () {
read confirm && [[ $confirm == [yYsS] ]]
}
connection_test () {
echo -e "$INFO - Testing connection..."
if ! sudo ping -c 1 8.8.8.8 -q &> /dev/null; then
echo -e "$ERROR - No internet connection, check the network status."
exit 1
else
echo -e "$INFO - Internet connection working properly."
fi
}
check_basic_programs () {
echo -e "$INFO - Checking basic programs..."
for program in ${REQUIREMENTS[@]}; do
if [[ ! -x $(which $program) ]]; then
echo -e "$INFO - $program not installed."
echo -e "$INFO - Installing $program."
sudo apt install $program -y
else
echo -e "$INFO - $program already installed."
fi
done
}
requirementes_test () {
echo -e "$INFO - Testing requirements..."
connection_test
check_basic_programs
}
is_wsl() {
case "$(uname -r)" in
*microsoft* ) true ;; # WSL 2
*Microsoft* ) true ;; # WSL 1
* ) false;;
esac
}
# Identificar a rede atual
git_config () {
if is_wsl; then
echo "WSL DETECTED: It is not possible to check the network SSID, do you want to chance git configuration to HTTP anyway?"
if confirm; then
git config --global url."ssh://[email protected]:443/".insteadOf "[email protected]:"
# git config --global url."ssh://[email protected]:443/".insteadOf "ssh://[email protected]/"
echo "Configuração do Git ajustada para usar a porta 443."
fi
else
CURRENT_SSID=$(nmcli -t -f active,ssid dev wifi | egrep '^(yes|sim)' | cut -d':' -f2)
# Definir o SSID da rede corporativa
CORPORATE_SSID="CD-COLABORADORES"
if [ "$CURRENT_SSID" == "$CORPORATE_SSID" ]; then
echo "Conectado à rede corporativa: $CORPORATE_SSID"
git config --global url."ssh://[email protected]:443/".insteadOf "[email protected]:"
# git config --global url."ssh://[email protected]:443/".insteadOf "ssh://[email protected]/"
echo "Configuração do Git ajustada para usar a porta 443."
else
echo "Você não está na rede corporativa. Mantendo as configurações padrão."
git config --global --unset url.ssh://[email protected]:443/.insteadOf
echo "Configuração do Git restaurada para usar a porta 22."
fi
fi
}
requirementes_test && git_config