Skip to content

Commit c2c0cdc

Browse files
authored
Merge pull request #839 from ldennington/ubuntu-jammy
install from source: use native feeds for Ubuntu 22.04
2 parents bf690c3 + ba3e2b1 commit c2c0cdc

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

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

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/bin/sh
22

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

99
is_ci=
1010
for i in "$@"; do
1111
case "$i" in
1212
-y)
1313
is_ci=true
14-
shift # past argument=value
14+
shift # Past argument=value
1515
;;
1616
esac
1717
done
1818

19-
# in non-ci scenarios, advertise what we will be doing and
20-
# give user the option to exit
19+
# In non-ci scenarios, advertise what we will be doing and
20+
# give user the option to exit.
2121
if [ -z $is_ci ]; then
2222
echo "This script will download, compile, and install Git Credential Manager to:
2323
@@ -47,7 +47,7 @@ install_shared_packages() {
4747

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

69-
# since we have to run the dotnet install script with bash, dotnet isn't added
70-
# to the process PATH, so we manually add it here
69+
# Since we have to run the dotnet install script with bash, dotnet isn't
70+
# added to the process PATH, so we manually add it here.
7171
cd ~
7272
export DOTNET_ROOT=$(pwd)/.dotnet
7373
add_to_PATH $DOTNET_ROOT
7474
fi
7575
}
7676

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

81-
# if we have a supported version installed, return
81+
# If we have a supported version installed, return.
8282
supported_dotnet_versions="6.0"
8383
for v in $supported_dotnet_versions; do
8484
if [ $(echo $sdks | grep "$v") ]; then
@@ -90,7 +90,7 @@ verify_existing_dotnet_installation() {
9090
add_to_PATH () {
9191
for directory; do
9292
if [ ! -d "$directory" ]; then
93-
continue; # skip nonexistent directory
93+
continue; # Skip nonexistent directory.
9494
fi
9595
case ":$PATH:" in
9696
*":$directory:"*)
@@ -103,10 +103,17 @@ add_to_PATH () {
103103
done
104104
}
105105

106+
apt_install() {
107+
pkg_name=$1
108+
109+
$sudo_cmd apt update
110+
$sudo_cmd apt install $pkg_name -y 2>/dev/null
111+
}
112+
106113
sudo_cmd=
107114

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

123-
# add dotnet package repository/signing key
124-
$sudo_cmd apt update && $sudo_cmd apt install wget -y
125-
curl -LO https://packages.microsoft.com/config/"$distribution"/"$version"/packages-microsoft-prod.deb
126-
$sudo_cmd dpkg -i packages-microsoft-prod.deb
127-
rm packages-microsoft-prod.deb
128-
129-
# proactively install tzdata to prevent prompts
130-
export DEBIAN_FRONTEND=noninteractive
131-
$sudo_cmd apt install -y --no-install-recommends tzdata
132-
133-
# install dotnet packages and dependencies if needed
130+
# Install dotnet packages and dependencies if needed.
134131
if [ -z "$(verify_existing_dotnet_installation)" ]; then
135-
$sudo_cmd apt update
136-
$sudo_cmd apt install apt-transport-https -y
137-
$sudo_cmd apt update
138-
$sudo_cmd apt install dotnet-sdk-6.0 dpkg-dev -y
132+
# First try to use native feeds (Ubuntu 22.04 and later).
133+
if ! apt_install dotnet6; then
134+
# If the native feeds fail, we fall back to
135+
# packages.microsoft.com. We begin by adding the dotnet package
136+
# repository/signing key.
137+
$sudo_cmd apt update && $sudo_cmd apt install wget -y
138+
curl -LO https://packages.microsoft.com/config/"$distribution"/"$version"/packages-microsoft-prod.deb
139+
$sudo_cmd dpkg -i packages-microsoft-prod.deb
140+
rm packages-microsoft-prod.deb
141+
142+
# Proactively install tzdata to prevent prompts.
143+
export DEBIAN_FRONTEND=noninteractive
144+
$sudo_cmd apt install -y --no-install-recommends tzdata
145+
146+
$sudo_cmd apt update
147+
$sudo_cmd apt install apt-transport-https -y
148+
$sudo_cmd apt update
149+
$sudo_cmd apt install dotnet-sdk-6.0 dpkg-dev -y
150+
fi
139151
fi
140152
;;
141153
linuxmint)
142154
$sudo_cmd apt update
143155
install_shared_packages apt install
144156

145-
# install dotnet packages and dependencies
157+
# Install dotnet packages and dependencies.
146158
$sudo_cmd apt install libc6 libgcc1 libgssapi-krb5-2 libssl1.1 libstdc++6 zlib1g libicu66 -y
147159
ensure_dotnet_installed
148160
;;
149161
fedora | centos | rhel)
150162
$sudo_cmd dnf update -y
151163
install_shared_packages dnf install
152164

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

156168
ensure_dotnet_installed
@@ -159,7 +171,7 @@ case "$distribution" in
159171
$sudo_cmd apk update
160172
install_shared_packages apk add
161173

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

165177
ensure_dotnet_installed
@@ -170,7 +182,7 @@ case "$distribution" in
170182
;;
171183
esac
172184

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

0 commit comments

Comments
 (0)