Skip to content

Commit 62eb6ab

Browse files
authored
Support linux install path from src (git-ecosystem#1409)
This PR fix git-ecosystem#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
2 parents ba2dcec + 54f6b46 commit 62eb6ab

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/linux/Packaging.Linux/Packaging.Linux.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<PropertyGroup>
1111
<InstallFromSource>false</InstallFromSource>
12+
<InstallPrefix>/usr/local</InstallPrefix>
1213
</PropertyGroup>
1314

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

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

3031
<Target Name="CoreClean">

src/linux/Packaging.Linux/build.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,21 @@ case "$i" in
3030
INSTALL_FROM_SOURCE="${i#*=}"
3131
shift # past argument=value
3232
;;
33+
--install-prefix=*)
34+
INSTALL_PREFIX="${i#*=}"
35+
shift # past argument=value
36+
;;
3337
*)
3438
# unknown option
3539
;;
3640
esac
3741
done
3842

43+
# Ensure install prefix exists
44+
if [! -d "$INSTALL_PREFIX" ]; then
45+
mkdir -p "$INSTALL_PREFIX"
46+
fi
47+
3948
# Perform pre-execution checks
4049
CONFIGURATION="${CONFIGURATION:=Debug}"
4150
if [ -z "$VERSION" ]; then
@@ -50,14 +59,11 @@ SYMBOLS="$OUTDIR/payload.sym"
5059
"$INSTALLER_SRC/layout.sh" --configuration="$CONFIGURATION" || exit 1
5160

5261
if [ $INSTALL_FROM_SOURCE = true ]; then
53-
INSTALL_LOCATION="/usr/local"
54-
mkdir -p "$INSTALL_LOCATION"
55-
56-
echo "Installing..."
62+
echo "Installing to $INSTALL_PREFIX"
5763

5864
# Install directories
59-
INSTALL_TO="$INSTALL_LOCATION/share/gcm-core/"
60-
LINK_TO="$INSTALL_LOCATION/bin/"
65+
INSTALL_TO="$INSTALL_PREFIX/share/gcm-core/"
66+
LINK_TO="$INSTALL_PREFIX/bin/"
6167

6268
mkdir -p "$INSTALL_TO" "$LINK_TO"
6369

src/linux/Packaging.Linux/install-from-source.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,30 @@ for i in "$@"; do
1313
is_ci=true
1414
shift # Past argument=value
1515
;;
16+
--install-prefix=*)
17+
installPrefix="${i#*=}"
18+
shift # past argument=value
19+
;;
1620
esac
1721
done
1822

23+
# If install-prefix is not passed, use default value
24+
if [ -z "$installPrefix" ]; then
25+
installPrefix=/usr/local
26+
fi
27+
28+
# Ensure install directory exists
29+
if [! -d "$installPrefix" ]; then
30+
echo "The folder $installPrefix does not exist"
31+
exit
32+
fi
33+
1934
# In non-ci scenarios, advertise what we will be doing and
2035
# give user the option to exit.
2136
if [ -z $is_ci ]; then
2237
echo "This script will download, compile, and install Git Credential Manager to:
2338
24-
/usr/local/bin
39+
$installPrefix/bin
2540
2641
Git Credential Manager is licensed under the MIT License: https://aka.ms/gcm/license"
2742

@@ -225,5 +240,5 @@ if [ -z "$DOTNET_ROOT" ]; then
225240
fi
226241

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

0 commit comments

Comments
 (0)