-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_profile
126 lines (108 loc) · 3.64 KB
/
.bash_profile
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
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# Function to extract the HOST and PORT values from .env.local files
get_host_and_port_value() {
local env_file=$1
local host=$(grep -E '^HOST=' "$env_file" | cut -d'=' -f2)
local port=$(grep -E '^PORT=' "$env_file" | cut -d'=' -f2)
echo "$host:$port"
}
# Function to check if a systemd service (auditoria.prod or auditoria.dev) is running
check_service_running() {
local service_name=$1
if systemctl is-active --quiet "$service_name"; then
return 0 # Service is active
else
return 1 # Service is not active
fi
}
# Bash function to display host and port information with colors
bash_completions_for_hosts() {
local prod_host_port=$(get_host_and_port_value ~/Auditoria/auditorIA-prod/.env.local)
local dev_host_port=$(get_host_and_port_value ~/Auditoria/auditorIA-dev/.env.local)
# Colors
local BLUE='\e[34m'
local GREEN='\e[32m'
local RED='\e[31m'
local RESET='\e[0m'
# Check if systemd services are running
local prod_running=false
local dev_running=false
if check_service_running "auditoria.prod"; then
prod_running=true
fi
if check_service_running "auditoria.dev"; then
dev_running=true
fi
# Display Prod host with colors
if [ "$prod_running" = true ]; then
echo -e "${GREEN}Prod host: ${BLUE}$prod_host_port ${GREEN}(running)${RESET}"
else
echo -e "${RED}Prod host: ${BLUE}$prod_host_port ${RED}(failure)${RESET}"
fi
# Display Dev host with colors
if [ "$dev_running" = true ]; then
echo -e "${GREEN}Dev host: ${BLUE}$dev_host_port ${GREEN}(running)${RESET}"
else
echo -e "${RED}Dev host: ${BLUE}$dev_host_port ${RED}(failure)${RESET}"
fi
}
# Alias for printing the host and port info
alias show_hosts="bash_completions_for_hosts"
# Function to extract the HOST and PORT values from .env.local files
get_host_and_port_value() {
local env_file=$1
local host=$(grep -E '^HOST=' "$env_file" | cut -d'=' -f2)
local port=$(grep -E '^PORT=' "$env_file" | cut -d'=' -f2)
echo "$host:$port"
}
# Function to check if a systemd service (auditoria.prod or auditoria.dev) is running
check_service_running() {
local service_name=$1
if systemctl is-active --quiet "$service_name"; then
return 0 # Service is active
else
return 1 # Service is not active
fi
}
# Bash function to display host and port information with colors
bash_completions_for_hosts() {
local prod_host_port=$(get_host_and_port_value ~/Auditoria/auditorIA-prod/.env.local)
local dev_host_port=$(get_host_and_port_value ~/Auditoria/auditorIA-dev/.env.local)
# Colors
local BLUE='\e[34m'
local GREEN='\e[32m'
local RED='\e[31m'
local RESET='\e[0m'
# Check if systemd services are running
local prod_running=false
local dev_running=false
if check_service_running "auditoria.prod"; then
prod_running=true
fi
if check_service_running "auditoria.dev"; then
dev_running=true
fi
# Display Prod host with colors
if [ "$prod_running" = true ]; then
echo -e "${GREEN}Prod host: ${BLUE}$prod_host_port ${GREEN}(running)${RESET}"
else
echo -e "${RED}Prod host: ${BLUE}$prod_host_port ${RED}(failure)${RESET}"
fi
# Display Dev host with colors
if [ "$dev_running" = true ]; then
echo -e "${GREEN}Dev host: ${BLUE}$dev_host_port ${GREEN}(running)${RESET}"
else
echo -e "${RED}Dev host: ${BLUE}$dev_host_port ${RED}(failure)${RESET}"
fi
}
# Alias for printing the host and port info
alias show_hosts="bash_completions_for_hosts"
# Run show_hosts only if the shell is a login shell and show_hosts hasn't been run before
if [ -z "$SHOW_HOSTS_RUN" ]; then
export SHOW_HOSTS_RUN=true
show_hosts
# Load node version
nvm use 20.18
fi