-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.ConfigureGo.sh
executable file
·68 lines (59 loc) · 2.08 KB
/
5.ConfigureGo.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
#!/bin/sh
echo "======================================"
echo " Step 1: Configuring Go Environment Variables"
echo "======================================"
# Define environment variables to export
ENV_VARS="
export GONOPROXY='github.com/goplugin'
export GONOSUMDB='github.com/goplugin'
export GO111MODULE='on'
export GOPRIVATE='github.com/goplugin'
export GOPROXY='direct'
export CGO_ENABLED='1'
"
# Step 1: Export variables for the current session (only if not already set)
echo "1. Exporting variables for the current session..."
echo "$ENV_VARS" | while IFS= read -r VAR; do
# Extract the variable name and value
VAR_NAME=$(echo "$VAR" | cut -d '=' -f 1)
# Check if the variable is already set
if [ -z "${!VAR_NAME}" ]; then
eval "$VAR"
if [ $? -eq 0 ]; then
echo "✅ Exported: $VAR"
else
echo "❌ Failed to export: $VAR"
fi
else
echo "⚠️ $VAR_NAME is already set to ${!VAR_NAME}. Skipping export."
fi
done
# Step 2: Append variables to ~/.bashrc (if not already added)
echo "2. Appending variables to ~/.bashrc (if not already added)..."
APPENDED_COUNT=0
echo "$ENV_VARS" | while IFS= read -r VAR; do
# Check if the variable is already in ~/.bashrc
if ! grep -qxF "$VAR" ~/.bashrc; then
echo "$VAR" >> ~/.bashrc
echo "✅ Added to ~/.bashrc: $VAR"
APPENDED_COUNT=$((APPENDED_COUNT + 1))
else
echo "⚠️ Already exists in ~/.bashrc: $VAR"
fi
done
if [ "$APPENDED_COUNT" -gt 0 ]; then
echo "✅ Variables successfully appended to ~/.bashrc."
else
echo "⚠️ No new variables were appended; all already exist in ~/.bashrc."
fi
# Step 3: Source ~/.bashrc to apply changes in the current session
echo "3. Sourcing ~/.bashrc to apply changes..."
. ~/.bashrc
if [ $? -eq 0 ]; then
echo "✅ Changes applied successfully."
else
echo "❌ Failed to source ~/.bashrc. Please do it manually: source ~/.bashrc"
fi
echo "======================================"
echo "✅ Go Environment Variables Configured Successfully!"
echo "======================================"