Skip to content

Commit c931052

Browse files
authored
Merge pull request #20 from sergeyklay/patch-1
Check whether the path given is absent in the PATH
2 parents 75e7b2c + 123984e commit c931052

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

update-golang.sh

+15-6
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ cache=$destination
118118

119119
show_vars() {
120120
echo user: "$(id)"
121-
121+
122122
cat <<EOF
123123
RELEASE_LIST=$release_list
124124
SOURCE=$source
@@ -263,7 +263,7 @@ profile_path_remove() {
263263
msg profile_path_remove: could not create temporary file: "$tmp"
264264
return
265265
fi
266-
grep -v "$path_mark" "$abs_profiled" > "$tmp"
266+
sed "/# DO NOT EDIT: installed by $path_mark/,/# $path_mark: end/d" "$abs_profiled" > "$tmp"
267267
cp "$tmp" "$abs_profiled"
268268
fi
269269
}
@@ -272,22 +272,31 @@ default_goroot=/usr/local/go
272272

273273
profile_path_add() {
274274
profile_path_remove
275+
{ echo "# DO NOT EDIT: installed by $path_mark"; echo ""; } >> "$abs_profiled"
275276

276277
msg profile_path_add: issuing new "$abs_gobin" to "$abs_profiled"
277-
local dont_edit=";# DO NOT EDIT: installed by $path_mark"
278-
echo "export PATH=\$PATH:$abs_gobin $dont_edit" >> "$abs_profiled"
278+
{ echo 'if ! echo "$PATH" | grep -Eq "(^|:)'"$abs_gobin"'($|:)"';
279+
echo "then";
280+
echo " export PATH=\$PATH:$abs_gobin";
281+
echo "fi"; } >> "$abs_profiled"
279282

280283
local user_gobin=
281284
[ -n "$GOPATH" ] && user_gobin=$(echo "$GOPATH" | awk -F: '{print $1}')/bin
282285
# shellcheck disable=SC2016
283286
[ -z "$user_gobin" ] && user_gobin='$HOME/go/bin' ;# we want $HOME literal
287+
284288
msg profile_path_add: issuing "$user_gobin" to "$abs_profiled"
285-
echo "export PATH=\$PATH:$user_gobin $dont_edit" >> "$abs_profiled"
289+
{ echo 'if ! echo "$PATH" | grep -Eq "(^|:)'"$user_gobin"'($|:)"';
290+
echo "then";
291+
echo " export PATH=\$PATH:$user_gobin";
292+
echo "fi"; } >> "$abs_profiled"
286293

287294
if [ "$abs_goroot" != $default_goroot ]; then
288295
msg profile_path_add: setting up custom GOROOT="$abs_goroot" to "$abs_profiled"
289-
echo "export GOROOT=$abs_goroot $dont_edit" >> "$abs_profiled"
296+
echo "export GOROOT=$abs_goroot" >> "$abs_profiled"
290297
fi
298+
echo "# $path_mark: end" >> "$abs_profiled"
299+
291300
chmod 755 "$abs_profiled"
292301
}
293302

0 commit comments

Comments
 (0)