Skip to content

Commit 8aca3eb

Browse files
authored
Merge pull request #630 from ldennington/install-from-source
Add `install-from-source.sh` and surrounding infrastructure
2 parents a154b16 + b2a0717 commit 8aca3eb

File tree

5 files changed

+322
-45
lines changed

5 files changed

+322
-45
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: validate-install-from-source
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
docker:
10+
name: ${{matrix.vector.image}}
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
vector:
16+
- image: ubuntu
17+
- image: debian
18+
- image: linuxmintd/mint20-amd64
19+
- image: fedora
20+
- image: centos
21+
- image: redhat/ubi8
22+
- image: alpine
23+
container: ${{matrix.vector.image}}
24+
steps:
25+
- uses: actions/checkout@v1
26+
- run: |
27+
if [ ${{matrix.vector.image}} == "centos" ]; then
28+
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
29+
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
30+
fi
31+
32+
sh "${GITHUB_WORKSPACE}/src/linux/Packaging.Linux/install-from-source.sh" -y
33+
git-credential-manager-core --help || exit 1

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ sudo /usr/local/share/gcm-core/uninstall.sh
8989
<a name="linux-install-instructions"></a>
9090
### Linux
9191

92+
#### Experimental: install from source helper script
93+
94+
If you would like to help dogfood our new install from source helper script,
95+
run the following:
96+
97+
1. To ensure `curl` is installed:
98+
99+
```shell
100+
curl --version
101+
```
102+
103+
If `curl` is not installed, please use your distribution's package manager
104+
to install it.
105+
106+
0. To download and run the script:
107+
108+
```shell
109+
curl -LO https://raw.githubusercontent.com/GitCredentialManager/git-credential-manager/main/src/linux/Packaging.Linux/install-from-source.sh &&
110+
sh ./install-from-source.sh &&
111+
git-credential-manager-core configure
112+
```
113+
114+
__Note:__ You will be prompted to enter your credentials so that the script
115+
can download GCM's dependencies using your distribution's package
116+
manager.
117+
92118
#### Ubuntu/Debian distributions
93119

94120
Download the latest [.deb package](https://github.com/GitCredentialManager/git-credential-manager/releases/latest), and run the following:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88
</PropertyGroup>
99

10+
<PropertyGroup>
11+
<InstallFromSource>false</InstallFromSource>
12+
</PropertyGroup>
13+
1014
<ItemGroup>
1115
<None Include="**/*" />
1216
</ItemGroup>
@@ -19,8 +23,8 @@
1923
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
2024

2125
<Target Name="CoreCompile" DependsOnTargets="GetBuildVersion" Condition="'$(OSPlatform)'=='linux'">
22-
<Message Text="$(MSBuildProjectDirectory)\build.sh --configuration='$(Configuration)' --version='$(BuildVersion)'" Importance="High" />
23-
<Exec Command="$(MSBuildProjectDirectory)\build.sh --configuration='$(Configuration)' --version='$(BuildVersion)'" />
26+
<Message Text="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(BuildVersion)'" Importance="High" />
27+
<Exec Command="$(MSBuildProjectDirectory)\build.sh --install-from-source=$(InstallFromSource) --configuration='$(Configuration)' --version='$(BuildVersion)'" />
2428
</Target>
2529

2630
<Target Name="CoreClean">

src/linux/Packaging.Linux/build.sh

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ make_absolute () {
1919
# Building
2020
#####################################################################
2121
echo "Building Packaging.Linux..."
22-
2322
# Parse script arguments
2423
for i in "$@"
2524
do
@@ -32,6 +31,10 @@ case "$i" in
3231
VERSION="${i#*=}"
3332
shift # past argument=value
3433
;;
34+
--install-from-source=*)
35+
INSTALL_FROM_SOURCE=${i#*=}
36+
shift # past argument=value
37+
;;
3538
*)
3639
# unknown option
3740
;;
@@ -59,22 +62,28 @@ if [ -z "$VERSION" ]; then
5962
die "--version was not set"
6063
fi
6164

62-
ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
63-
if test -z "$ARCH"; then
64-
die "Could not determine host architecture!"
65+
if [ $INSTALL_FROM_SOURCE = false ]; then
66+
ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
67+
if test -z "$ARCH"; then
68+
die "Could not determine host architecture!"
69+
fi
6570
fi
6671

6772
# Outputs
6873
PAYLOAD="$PROJ_OUT/payload/$CONFIGURATION"
6974
SYMBOLOUT="$PROJ_OUT/payload.sym/$CONFIGURATION"
7075

71-
TAROUT="$PROJ_OUT/tar/$CONFIGURATION"
72-
TARBALL="$TAROUT/gcmcore-linux_$ARCH.$VERSION.tar.gz"
73-
SYMTARBALL="$TAROUT/symbols-linux_$ARCH.$VERSION.tar.gz"
76+
if [ $INSTALL_FROM_SOURCE = false ]; then
77+
TAROUT="$PROJ_OUT/tar/$CONFIGURATION"
78+
TARBALL="$TAROUT/gcmcore-linux_$ARCH.$VERSION.tar.gz"
79+
SYMTARBALL="$TAROUT/symbols-linux_$ARCH.$VERSION.tar.gz"
7480

75-
DEBOUT="$PROJ_OUT/deb/$CONFIGURATION"
76-
DEBROOT="$DEBOUT/root"
77-
DEBPKG="$DEBOUT/gcmcore-linux_$ARCH.$VERSION.deb"
81+
DEBOUT="$PROJ_OUT/deb/$CONFIGURATION"
82+
DEBROOT="$DEBOUT/root"
83+
DEBPKG="$DEBOUT/gcmcore-linux_$ARCH.$VERSION.deb"
84+
else
85+
INSTALL_LOCATION="/usr/local"
86+
fi
7887

7988
# Cleanup payload directory
8089
if [ -d "$PAYLOAD" ]; then
@@ -89,7 +98,13 @@ if [ -d "$SYMBOLOUT" ]; then
8998
fi
9099

91100
# Ensure directories exists
92-
mkdir -p "$PAYLOAD" "$SYMBOLOUT" "$DEBROOT"
101+
mkdir -p "$PAYLOAD" "$SYMBOLOUT"
102+
103+
if [ $INSTALL_FROM_SOURCE = false ]; then
104+
mkdir -p "$DEBROOT"
105+
else
106+
mkdir -p "$INSTALL_LOCATION"
107+
fi
93108

94109
# Publish core application executables
95110
echo "Publishing core application..."
@@ -135,40 +150,44 @@ mv "$PAYLOAD"/*.pdb "$SYMBOLOUT" || exit 1
135150
echo "Build complete."
136151

137152
#####################################################################
138-
# PACKING
153+
# PACKING AND INSTALLING
139154
#####################################################################
140-
echo "Packing Packaging.Linux..."
141-
# Cleanup any old archive files
142-
if [ -e "$TAROUT" ]; then
143-
echo "Deleteing old archive '$TAROUT'..."
144-
rm "$TAROUT"
145-
fi
146-
147-
# Ensure the parent directory for the archive exists
148-
mkdir -p "$TAROUT" || exit 1
149-
150155
# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
151156
echo "Setting file permissions..."
152157
/bin/chmod -R 755 "$PAYLOAD" || exit 1
153158

154-
# Build binaries tarball
155-
echo "Building binaries tarball..."
156-
pushd "$PAYLOAD"
157-
tar -czvf "$TARBALL" * || exit 1
158-
popd
159-
160-
# Build symbols tarball
161-
echo "Building symbols tarball..."
162-
pushd "$SYMBOLOUT"
163-
tar -czvf "$SYMTARBALL" * || exit 1
164-
popd
165-
166-
# Build .deb
167-
INSTALL_TO="$DEBROOT/usr/local/share/gcm-core/"
168-
LINK_TO="$DEBROOT/usr/local/bin/"
169-
mkdir -p "$DEBROOT/DEBIAN" "$INSTALL_TO" "$LINK_TO" || exit 1
159+
if [ $INSTALL_FROM_SOURCE = false ]; then
160+
echo "Packing Packaging.Linux..."
161+
# Cleanup any old archive files
162+
if [ -e "$TAROUT" ]; then
163+
echo "Deleteing old archive '$TAROUT'..."
164+
rm "$TAROUT"
165+
fi
166+
167+
# Ensure the parent directory for the archive exists
168+
mkdir -p "$TAROUT" || exit 1
169+
170+
# Build binaries tarball
171+
echo "Building binaries tarball..."
172+
pushd "$PAYLOAD"
173+
tar -czvf "$TARBALL" * || exit 1
174+
popd
175+
176+
# Build symbols tarball
177+
echo "Building symbols tarball..."
178+
pushd "$SYMBOLOUT"
179+
tar -czvf "$SYMTARBALL" * || exit 1
180+
popd
181+
182+
# Build .deb
183+
INSTALL_TO="$DEBROOT/usr/local/share/gcm-core/"
184+
LINK_TO="$DEBROOT/usr/bin/"
185+
mkdir -p "$DEBROOT/DEBIAN" "$INSTALL_TO" "$LINK_TO" || exit 1
170186

171187
# make the debian control file
188+
# this is purposefully not indented, see
189+
# https://stackoverflow.com/questions/9349616/bash-eof-in-if-statement
190+
# for details
172191
cat >"$DEBROOT/DEBIAN/control" <<EOF
173192
Package: gcmcore
174193
Version: $VERSION
@@ -183,13 +202,25 @@ Description: Cross Platform Git Credential Manager command line utility.
183202
For more information see https://aka.ms/gcm
184203
EOF
185204

205+
dpkg-deb --build "$DEBROOT" "$DEBPKG" || exit 1
206+
else
207+
echo "Installing..."
208+
209+
# Install directories
210+
INSTALL_TO="$INSTALL_LOCATION/share/gcm-core/"
211+
LINK_TO="$INSTALL_LOCATION/bin/"
212+
MESSAGE="Install complete."
213+
fi
214+
215+
mkdir -p "$INSTALL_TO" "$LINK_TO"
216+
186217
# Copy all binaries and shared libraries to target installation location
187218
cp -R "$PAYLOAD"/* "$INSTALL_TO" || exit 1
188219

189220
# Create symlink
190-
ln -s -r "$INSTALL_TO/git-credential-manager-core" \
191-
"$LINK_TO/git-credential-manager-core" || exit 1
192-
193-
dpkg-deb --build "$DEBROOT" "$DEBPKG" || exit 1
221+
if [ ! -f "$LINK_TO/git-credential-manager-core" ]; then
222+
ln -s -r "$INSTALL_TO/git-credential-manager-core" \
223+
"$LINK_TO/git-credential-manager-core" || exit 1
224+
fi
194225

195-
echo "Pack complete."
226+
echo $MESSAGE

0 commit comments

Comments
 (0)