-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatego.sh
executable file
·37 lines (31 loc) · 1.19 KB
/
updatego.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
#!/bin/bash
######################################################################################
# SCRIPT: Allow to quickly update go version in go.work and go.mod to system #
# CALL SIGN: bash updatego.sh #
# CALL EXAMPLE: bash updatego.sh #
######################################################################################
# Get Current Directory
CURRENT_DIR=$PWD;
# Get system go version
go_version=`go version | { read _ _ v _; echo ${v#go}; }`
echo "System Go version: $go_version"
echo "Replace Go version in go.work..."
# Check if a go.work file exist
if test -f ./go.work; then
# Replace go version with current
sed -i -e "s/go [0-9]\+\.[0-9]\+\.[0-9]\+/go ${go_version}/g" ./go.work
fi
echo "Replace Go version in go.mod..."
# Check if a go.work file exist
for obj in *; do
if [ -d "$obj" ]; then
cd $obj
# Check if a go.mod file exist
if test -f ./go.mod; then
# Replace go version with current
sed -i -e "s/go [0-9]\+\.[0-9]\+\.[0-9]\+/go ${go_version}/g" ./go.mod
fi
cd ..
fi
done
echo "All done!"