Skip to content

Commit

Permalink
Merge pull request #839 from ldennington/ubuntu-jammy
Browse files Browse the repository at this point in the history
install from source: use native feeds for Ubuntu 22.04
  • Loading branch information
ldennington authored Aug 22, 2022
2 parents bf690c3 + ba3e2b1 commit c2c0cdc
Showing 1 changed file with 46 additions and 34 deletions.
80 changes: 46 additions & 34 deletions src/linux/Packaging.Linux/install-from-source.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/bin/sh

# halt execution immediately on failure
# note there are some scenarios in which this will not exit;
# see https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
# for additional details
# Halt execution immediately on failure.
# Note there are some scenarios in which this will not exit; see
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
# for additional details.
set -e

is_ci=
for i in "$@"; do
case "$i" in
-y)
is_ci=true
shift # past argument=value
shift # Past argument=value
;;
esac
done

# in non-ci scenarios, advertise what we will be doing and
# give user the option to exit
# 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:
Expand Down Expand Up @@ -47,7 +47,7 @@ install_shared_packages() {

local shared_packages="git curl"
for package in $shared_packages; do
# ensure we don't stomp on existing installations
# Ensure we don't stomp on existing installations.
if [ ! -z $(which $package) ]; then
continue
fi
Expand All @@ -66,19 +66,19 @@ ensure_dotnet_installed() {
chmod +x ./dotnet-install.sh
bash -c "./dotnet-install.sh"

# since we have to run the dotnet install script with bash, dotnet isn't added
# to the process PATH, so we manually add it here
# Since we have to run the dotnet install script with bash, dotnet isn't
# added to the process PATH, so we manually add it here.
cd ~
export DOTNET_ROOT=$(pwd)/.dotnet
add_to_PATH $DOTNET_ROOT
fi
}

verify_existing_dotnet_installation() {
# get initial pieces of installed sdk version(s)
# Get initial pieces of installed sdk version(s).
sdks=$(dotnet --list-sdks | cut -c 1-3)

# if we have a supported version installed, return
# If we have a supported version installed, return.
supported_dotnet_versions="6.0"
for v in $supported_dotnet_versions; do
if [ $(echo $sdks | grep "$v") ]; then
Expand All @@ -90,7 +90,7 @@ verify_existing_dotnet_installation() {
add_to_PATH () {
for directory; do
if [ ! -d "$directory" ]; then
continue; # skip nonexistent directory
continue; # Skip nonexistent directory.
fi
case ":$PATH:" in
*":$directory:"*)
Expand All @@ -103,10 +103,17 @@ add_to_PATH () {
done
}

apt_install() {
pkg_name=$1

$sudo_cmd apt update
$sudo_cmd apt install $pkg_name -y 2>/dev/null
}

sudo_cmd=

# if the user isn't root, we need to use `sudo` for certain commands
# (e.g. installing packages)
# If the user isn't root, we need to use `sudo` for certain commands
# (e.g. installing packages).
if [ -z "$sudo_cmd" ]; then
if [ `id -u` != 0 ]; then
sudo_cmd=sudo
Expand All @@ -120,37 +127,42 @@ case "$distribution" in
$sudo_cmd apt update
install_shared_packages apt install

# add dotnet package repository/signing key
$sudo_cmd apt update && $sudo_cmd apt install wget -y
curl -LO https://packages.microsoft.com/config/"$distribution"/"$version"/packages-microsoft-prod.deb
$sudo_cmd dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

# proactively install tzdata to prevent prompts
export DEBIAN_FRONTEND=noninteractive
$sudo_cmd apt install -y --no-install-recommends tzdata

# install dotnet packages and dependencies if needed
# Install dotnet packages and dependencies if needed.
if [ -z "$(verify_existing_dotnet_installation)" ]; then
$sudo_cmd apt update
$sudo_cmd apt install apt-transport-https -y
$sudo_cmd apt update
$sudo_cmd apt install dotnet-sdk-6.0 dpkg-dev -y
# First try to use native feeds (Ubuntu 22.04 and later).
if ! apt_install dotnet6; then
# If the native feeds fail, we fall back to
# packages.microsoft.com. We begin by adding the dotnet package
# repository/signing key.
$sudo_cmd apt update && $sudo_cmd apt install wget -y
curl -LO https://packages.microsoft.com/config/"$distribution"/"$version"/packages-microsoft-prod.deb
$sudo_cmd dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

# Proactively install tzdata to prevent prompts.
export DEBIAN_FRONTEND=noninteractive
$sudo_cmd apt install -y --no-install-recommends tzdata

$sudo_cmd apt update
$sudo_cmd apt install apt-transport-https -y
$sudo_cmd apt update
$sudo_cmd apt install dotnet-sdk-6.0 dpkg-dev -y
fi
fi
;;
linuxmint)
$sudo_cmd apt update
install_shared_packages apt install

# install dotnet packages and dependencies
# Install dotnet packages and dependencies.
$sudo_cmd apt install libc6 libgcc1 libgssapi-krb5-2 libssl1.1 libstdc++6 zlib1g libicu66 -y
ensure_dotnet_installed
;;
fedora | centos | rhel)
$sudo_cmd dnf update -y
install_shared_packages dnf install

# install dotnet/gcm dependencies
# Install dotnet/GCM dependencies.
$sudo_cmd dnf install krb5-libs libicu openssl-libs zlib findutils which bash -y

ensure_dotnet_installed
Expand All @@ -159,7 +171,7 @@ case "$distribution" in
$sudo_cmd apk update
install_shared_packages apk add

# install dotnet/gcm dependencies
# Install dotnet/GCM dependencies.
$sudo_cmd apk add icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib which bash coreutils gcompat

ensure_dotnet_installed
Expand All @@ -170,7 +182,7 @@ case "$distribution" in
;;
esac

# detect if the script is part of a full source checkout or standalone instead
# Detect if the script is part of a full source checkout or standalone instead.
script_path="$(cd "$(dirname "$0")" && pwd)"
toplevel_path="${script_path%/src/linux/Packaging.Linux}"
if [ "z$script_path" = "z$toplevel_path" ] || [ ! -f "$toplevel_path/Git-Credential-Manager.sln" ]; then
Expand Down

0 comments on commit c2c0cdc

Please sign in to comment.