@@ -118,7 +118,7 @@ cache=$destination
118
118
119
119
show_vars () {
120
120
echo user: " $( id) "
121
-
121
+
122
122
cat << EOF
123
123
RELEASE_LIST=$release_list
124
124
SOURCE=$source
@@ -263,7 +263,7 @@ profile_path_remove() {
263
263
msg profile_path_remove: could not create temporary file: " $tmp "
264
264
return
265
265
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 "
267
267
cp " $tmp " " $abs_profiled "
268
268
fi
269
269
}
@@ -272,22 +272,31 @@ default_goroot=/usr/local/go
272
272
273
273
profile_path_add () {
274
274
profile_path_remove
275
+ { echo " # DO NOT EDIT: installed by $path_mark " ; echo " " ; } >> " $abs_profiled "
275
276
276
277
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 "
279
282
280
283
local user_gobin=
281
284
[ -n " $GOPATH " ] && user_gobin=$( echo " $GOPATH " | awk -F: ' {print $1}' ) /bin
282
285
# shellcheck disable=SC2016
283
286
[ -z " $user_gobin " ] && user_gobin=' $HOME/go/bin' ; # we want $HOME literal
287
+
284
288
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 "
286
293
287
294
if [ " $abs_goroot " != $default_goroot ]; then
288
295
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 "
290
297
fi
298
+ echo " # $path_mark : end" >> " $abs_profiled "
299
+
291
300
chmod 755 " $abs_profiled "
292
301
}
293
302
0 commit comments