Skip to content

Commit

Permalink
Correcting linking issues for next and default /usr/local/go paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Benji Vesterby committed Dec 15, 2021
1 parent 83a0483 commit e631292
Showing 1 changed file with 14 additions and 45 deletions.
59 changes: 14 additions & 45 deletions gvm
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,12 @@ gvmroot="$HOME/.gvm"
srcd="$gvmroot/next"
version="$1"
versionroot="$gvmroot/$version"
defaultgoroot="/usr/local/go"
defaultgoroot="/usr/local/"
golanggit="https://go.googlesource.com/go"
dlroot="https://dl.google.com/go/"
update=$2
branch="master"

function override() {
if [[ -d $defaultgoroot ]]
then
printf "Removing existing %s\n" "$defaultgoroot"
if ! sudo rm -rf $defaultgoroot
then
fail "$(printf "Unable to remove existing %s\n" "$defaultgoroot")"
fi
fi

printf "Creating for %s to %s\n" "$defaultgoroot" "$gvmroot"
if ! sudo mkdir -p $defaultgoroot
then
fail "$(printf "Unable to create new to symlink %s\n" "$defaultgoroot")"
fi

if ! sudo ln -sf "$gvmroot"/go "$defaultgoroot"
then
fail "$(printf "Unable to symlink new %s\n" "$defaultgoroot")"
fi
}

function fail() {
printf "%s\n" "$1"
exit 1
Expand Down Expand Up @@ -176,15 +154,6 @@ then
fi
fi

# printf "Checking for existing %s\n" "$versionroot"
# if [[ ! -d "$gvmroot" ]]
# then
# if ! mkdir "$symln"
# then
# fail "$(printf "Unable to create directory %s\n" "$symln")"
# fi
# fi

if [[ "$version" == "next" ]]
then
printf "Installing Go %s\n" "$version"
Expand All @@ -198,16 +167,16 @@ then
mkdir "$srcd"
fi

if [[ ! -d "$srcd/go" ]]
srcd="$srcd/go"

if [[ ! -d "$srcd" ]]
then
printf "Cloning go source\n"
if ! git clone "$golanggit" "$srcd/go"
if ! git clone "$golanggit" "$srcd"
then
fail "$("Error cloning %s\n" "$golanggit")"
fi

srcd=$srcd/go

# Add update flag since source repo
# did not already exist
update="--update"
Expand Down Expand Up @@ -245,9 +214,6 @@ then

cd "$wd" || exit 1
fi

# Set correct path for symlink re-map
lnsrc="$versionroot"
else
if [[ ! -d "$versionroot" ]]
then
Expand All @@ -273,11 +239,11 @@ else

rm "$pkg"
fi

# Set correct path for symlink re-map
lnsrc="$versionroot/go"
fi

# Set correct path for symlink re-map
lnsrc="$versionroot/go"

printf "Updating symlink %s => %s\n" "$lnsrc" "$gvmroot"
if ! ln -sf "$lnsrc" "$gvmroot"
then
Expand All @@ -286,15 +252,18 @@ fi

# Check to see if the default root exists and if it is a symlink
# prior to prompting the user to override it
if [[ ! -L $defaultgoroot/bin || ! -e $defaultgoroot/bin ]]
if [[ ! -L $defaultgoroot/go || ! -e $defaultgoroot/go ]]
then
read -rp "Do you wish to override /usr/local/go \
[Yes: Y or y | No: Enter]? " yn

# Only trigger on `Y` or `y`
if [[ "$yn" == "Y" || "$yn" == "y" ]]
then
override
if ! sudo ln -sf "$gvmroot/go" "$defaultgoroot"
then
fail "$(printf "Unable to symlink new %s\n" "$defaultgoroot")"
fi
fi
fi

Expand All @@ -321,7 +290,7 @@ then
fi
fi

if which go
if which go&> /dev/null
then
pathgo=$(which go)
if [[ "$pathgo" != "$gvmroot/go/bin/go" ]]
Expand Down

0 comments on commit e631292

Please sign in to comment.