Skip to content

Commit

Permalink
Support linux install path from src (#1409)
Browse files Browse the repository at this point in the history
This PR fix #1304.

I found that the add func add_to_PATH [1] doesn't persist the path
to the $PATH env variable.

To persist in the current shell is necessary to use a dot or `source`
see doc [2].

_When a script is run using source it runs within the existing shell,
any variables created or modified by the script will remain available
after the script completes. In contrast if the script is run just as
filename, then a separate subshell (with a completely separate set of
variables) would be spawned to run the script._

To persist the PATH among the reboot/new shell, it is necessary to
update the _.profile_ with `echo 'PATH="$PATH:$installPath'
>>~/.profile`.

I don't know if this is the correct behavior, Prior to this commit, it
was working because the `/usr/local/bin` is already in the PATH.

[1]: https://github.com/git-ecosystem/git-credential-manager/blob/afcb6b87302b34d1809a0a057f24c7ba7a3ff5db/src/linux/Packaging.Linux/install-from-source.sh#L94
[2]: https://ss64.com/bash/source.htmlvvvvvvv
  • Loading branch information
ldennington authored Oct 19, 2023
2 parents ba2dcec + 54f6b46 commit 62eb6ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/linux/Packaging.Linux/Packaging.Linux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<PropertyGroup>
<InstallFromSource>false</InstallFromSource>
<InstallPrefix>/usr/local</InstallPrefix>
</PropertyGroup>

<ItemGroup>
Expand All @@ -23,8 +24,8 @@
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<Target Name="CoreCompile" Condition="'$(OSPlatform)'=='linux'">
<Message Text="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(Version)'" Importance="High" />
<Exec Command="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(Version)'" />
<Message Text="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(Version)' --install-prefix='$(InstallPrefix)'" Importance="High" />
<Exec Command="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(Version)' --install-prefix='$(InstallPrefix)'" />
</Target>

<Target Name="CoreClean">
Expand Down
18 changes: 12 additions & 6 deletions src/linux/Packaging.Linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ case "$i" in
INSTALL_FROM_SOURCE="${i#*=}"
shift # past argument=value
;;
--install-prefix=*)
INSTALL_PREFIX="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done

# Ensure install prefix exists
if [! -d "$INSTALL_PREFIX" ]; then
mkdir -p "$INSTALL_PREFIX"
fi

# Perform pre-execution checks
CONFIGURATION="${CONFIGURATION:=Debug}"
if [ -z "$VERSION" ]; then
Expand All @@ -50,14 +59,11 @@ SYMBOLS="$OUTDIR/payload.sym"
"$INSTALLER_SRC/layout.sh" --configuration="$CONFIGURATION" || exit 1

if [ $INSTALL_FROM_SOURCE = true ]; then
INSTALL_LOCATION="/usr/local"
mkdir -p "$INSTALL_LOCATION"

echo "Installing..."
echo "Installing to $INSTALL_PREFIX"

# Install directories
INSTALL_TO="$INSTALL_LOCATION/share/gcm-core/"
LINK_TO="$INSTALL_LOCATION/bin/"
INSTALL_TO="$INSTALL_PREFIX/share/gcm-core/"
LINK_TO="$INSTALL_PREFIX/bin/"

mkdir -p "$INSTALL_TO" "$LINK_TO"

Expand Down
21 changes: 18 additions & 3 deletions src/linux/Packaging.Linux/install-from-source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@ for i in "$@"; do
is_ci=true
shift # Past argument=value
;;
--install-prefix=*)
installPrefix="${i#*=}"
shift # past argument=value
;;
esac
done

# If install-prefix is not passed, use default value
if [ -z "$installPrefix" ]; then
installPrefix=/usr/local
fi

# Ensure install directory exists
if [! -d "$installPrefix" ]; then
echo "The folder $installPrefix does not exist"
exit
fi

# In non-ci scenarios, advertise what we will be doing and
# give user the option to exit.
if [ -z $is_ci ]; then
echo "This script will download, compile, and install Git Credential Manager to:
/usr/local/bin
$installPrefix/bin
Git Credential Manager is licensed under the MIT License: https://aka.ms/gcm/license"

Expand Down Expand Up @@ -225,5 +240,5 @@ if [ -z "$DOTNET_ROOT" ]; then
fi

cd "$toplevel_path"
$sudo_cmd env "PATH=$PATH" $DOTNET_ROOT/dotnet build ./src/linux/Packaging.Linux/Packaging.Linux.csproj -c Release -p:InstallFromSource=true
add_to_PATH "/usr/local/bin"
$sudo_cmd env "PATH=$PATH" $DOTNET_ROOT/dotnet build ./src/linux/Packaging.Linux/Packaging.Linux.csproj -c Release -p:InstallFromSource=true -p:installPrefix=$installPrefix
add_to_PATH "$installPrefix/bin"

0 comments on commit 62eb6ab

Please sign in to comment.