-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgomod-update.sh
More file actions
executable file
·73 lines (62 loc) · 1.64 KB
/
gomod-update.sh
File metadata and controls
executable file
·73 lines (62 loc) · 1.64 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
#!/bin/bash
CONFIG_FILE="/tmp/gomod_config"
# Load the $gomod variable from the configuration file if it exists
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
# Confirm the value of $gomod with the user
read -p "The current value of the Go module is '$gomod'. Is this correct? (y/n): " confirm
if [ "$confirm" != "y" ]; then
unset gomod
fi
fi
# Check if $gomod is set, if not prompt the user and save it
if [ -z "$gomod" ]; then
read -p "Please enter the name of the Go module: " gomod
echo "gomod=$gomod" > "$CONFIG_FILE"
fi
# Confirm the value of $gomod
echo "Go module name: $gomod"
# Remove old Go mod file
echo "Removing old Go mod file..."
if rm go.* 2>/dev/null; then
echo "Old Go mod file removed successfully."
else
echo "No old Go mod file found to remove."
fi
# Remove old binary if present
echo "Removing old binary...if present"
if [ -f "$gomod" ]; then
if rm "$gomod"; then
echo "Old binary removed successfully."
else
echo "Error: Failed to remove old binary." >&2
exit 1
fi
else
echo "No old binary found to remove."
fi
# Reinitialize Go module
echo "Reinitializing Go module..."
if go mod init "$gomod"; then
echo "Go module reinitialized successfully."
else
echo "Error: Failed to reinitialize Go module." >&2
exit 1
fi
# Tidy up
echo "Tidying up..."
if go mod tidy; then
echo "Modules tidied up successfully."
else
echo "Error: Failed to tidy up modules." >&2
exit 1
fi
# Build new binary
echo "Building new binary..."
if go build -o "$gomod"; then
echo "New binary built successfully."
else
echo "Error: Failed to build new binary." >&2
exit 1
fi
echo "Script completed successfully."