Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install-from-source.sh and surrounding infrastructure #630

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/validate-install-from-source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: validate-install-from-source

on:
push:
branches:
- main

jobs:
docker:
name: ${{matrix.vector.image}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
vector:
- image: ubuntu
- image: debian
- image: linuxmintd/mint20-amd64
- image: fedora
- image: centos
- image: redhat/ubi8
- image: alpine
container: ${{matrix.vector.image}}
steps:
- uses: actions/checkout@v1
- run: |
if [ ${{matrix.vector.image}} == "centos" ]; then
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
fi

sh "${GITHUB_WORKSPACE}/src/linux/Packaging.Linux/install-from-source.sh" -y
git-credential-manager-core --help || exit 1
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ sudo /usr/local/share/gcm-core/uninstall.sh
<a name="linux-install-instructions"></a>
### Linux

#### Experimental: install from source helper script

If you would like to help dogfood our new install from source helper script,
run the following:

1. To ensure `curl` is installed:

```shell
curl --version
```

If `curl` is not installed, please use your distribution's package manager
to install it.

0. To download and run the script:

```shell
curl -LO https://raw.githubusercontent.com/GitCredentialManager/git-credential-manager/main/src/linux/Packaging.Linux/install-from-source.sh &&
sh ./install-from-source.sh &&
git-credential-manager-core configure
```

__Note:__ You will be prompted to enter your credentials so that the script
can download GCM's dependencies using your distribution's package
manager.

#### Ubuntu/Debian distributions

Download the latest [.deb package](https://github.com/GitCredentialManager/git-credential-manager/releases/latest), and run the following:
Expand Down
8 changes: 6 additions & 2 deletions src/linux/Packaging.Linux/Packaging.Linux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<PropertyGroup>
<InstallFromSource>false</InstallFromSource>
</PropertyGroup>

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

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

<Target Name="CoreClean">
Expand Down
117 changes: 74 additions & 43 deletions src/linux/Packaging.Linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ make_absolute () {
# Building
#####################################################################
echo "Building Packaging.Linux..."

# Parse script arguments
for i in "$@"
do
Expand All @@ -32,6 +31,10 @@ case "$i" in
VERSION="${i#*=}"
shift # past argument=value
;;
--install-from-source=*)
INSTALL_FROM_SOURCE=${i#*=}
shift # past argument=value
;;
*)
# unknown option
;;
Expand Down Expand Up @@ -59,22 +62,28 @@ if [ -z "$VERSION" ]; then
die "--version was not set"
fi

ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
if test -z "$ARCH"; then
die "Could not determine host architecture!"
if [ $INSTALL_FROM_SOURCE = false ]; then
ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
if test -z "$ARCH"; then
die "Could not determine host architecture!"
fi
fi

# Outputs
PAYLOAD="$PROJ_OUT/payload/$CONFIGURATION"
SYMBOLOUT="$PROJ_OUT/payload.sym/$CONFIGURATION"

TAROUT="$PROJ_OUT/tar/$CONFIGURATION"
TARBALL="$TAROUT/gcmcore-linux_$ARCH.$VERSION.tar.gz"
SYMTARBALL="$TAROUT/symbols-linux_$ARCH.$VERSION.tar.gz"
if [ $INSTALL_FROM_SOURCE = false ]; then
TAROUT="$PROJ_OUT/tar/$CONFIGURATION"
TARBALL="$TAROUT/gcmcore-linux_$ARCH.$VERSION.tar.gz"
SYMTARBALL="$TAROUT/symbols-linux_$ARCH.$VERSION.tar.gz"

DEBOUT="$PROJ_OUT/deb/$CONFIGURATION"
DEBROOT="$DEBOUT/root"
DEBPKG="$DEBOUT/gcmcore-linux_$ARCH.$VERSION.deb"
DEBOUT="$PROJ_OUT/deb/$CONFIGURATION"
DEBROOT="$DEBOUT/root"
DEBPKG="$DEBOUT/gcmcore-linux_$ARCH.$VERSION.deb"
else
INSTALL_LOCATION="/usr/local"
fi

# Cleanup payload directory
if [ -d "$PAYLOAD" ]; then
Expand All @@ -89,7 +98,13 @@ if [ -d "$SYMBOLOUT" ]; then
fi

# Ensure directories exists
mkdir -p "$PAYLOAD" "$SYMBOLOUT" "$DEBROOT"
mkdir -p "$PAYLOAD" "$SYMBOLOUT"

if [ $INSTALL_FROM_SOURCE = false ]; then
mkdir -p "$DEBROOT"
else
mkdir -p "$INSTALL_LOCATION"
fi

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

#####################################################################
# PACKING
# PACKING AND INSTALLING
#####################################################################
echo "Packing Packaging.Linux..."
# Cleanup any old archive files
if [ -e "$TAROUT" ]; then
echo "Deleteing old archive '$TAROUT'..."
rm "$TAROUT"
fi

# Ensure the parent directory for the archive exists
mkdir -p "$TAROUT" || exit 1

# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
echo "Setting file permissions..."
/bin/chmod -R 755 "$PAYLOAD" || exit 1

# Build binaries tarball
echo "Building binaries tarball..."
pushd "$PAYLOAD"
tar -czvf "$TARBALL" * || exit 1
popd

# Build symbols tarball
echo "Building symbols tarball..."
pushd "$SYMBOLOUT"
tar -czvf "$SYMTARBALL" * || exit 1
popd

# Build .deb
INSTALL_TO="$DEBROOT/usr/local/share/gcm-core/"
LINK_TO="$DEBROOT/usr/local/bin/"
mkdir -p "$DEBROOT/DEBIAN" "$INSTALL_TO" "$LINK_TO" || exit 1
if [ $INSTALL_FROM_SOURCE = false ]; then
echo "Packing Packaging.Linux..."
# Cleanup any old archive files
if [ -e "$TAROUT" ]; then
echo "Deleteing old archive '$TAROUT'..."
rm "$TAROUT"
fi

# Ensure the parent directory for the archive exists
mkdir -p "$TAROUT" || exit 1

# Build binaries tarball
echo "Building binaries tarball..."
pushd "$PAYLOAD"
tar -czvf "$TARBALL" * || exit 1
popd

# Build symbols tarball
echo "Building symbols tarball..."
pushd "$SYMBOLOUT"
tar -czvf "$SYMTARBALL" * || exit 1
popd

# Build .deb
INSTALL_TO="$DEBROOT/usr/local/share/gcm-core/"
LINK_TO="$DEBROOT/usr/bin/"
mkdir -p "$DEBROOT/DEBIAN" "$INSTALL_TO" "$LINK_TO" || exit 1

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

dpkg-deb --build "$DEBROOT" "$DEBPKG" || exit 1
else
echo "Installing..."

# Install directories
INSTALL_TO="$INSTALL_LOCATION/share/gcm-core/"
LINK_TO="$INSTALL_LOCATION/bin/"
MESSAGE="Install complete."
fi

mkdir -p "$INSTALL_TO" "$LINK_TO"

# Copy all binaries and shared libraries to target installation location
cp -R "$PAYLOAD"/* "$INSTALL_TO" || exit 1

# Create symlink
ln -s -r "$INSTALL_TO/git-credential-manager-core" \
"$LINK_TO/git-credential-manager-core" || exit 1

dpkg-deb --build "$DEBROOT" "$DEBPKG" || exit 1
if [ ! -f "$LINK_TO/git-credential-manager-core" ]; then
ln -s -r "$INSTALL_TO/git-credential-manager-core" \
"$LINK_TO/git-credential-manager-core" || exit 1
fi

echo "Pack complete."
echo $MESSAGE
Loading