1
1
#! /bin/sh
2
2
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.
7
7
set -e
8
8
9
9
is_ci=
10
10
for i in " $@ " ; do
11
11
case " $i " in
12
12
-y)
13
13
is_ci=true
14
- shift # past argument=value
14
+ shift # Past argument=value
15
15
;;
16
16
esac
17
17
done
18
18
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.
21
21
if [ -z $is_ci ]; then
22
22
echo " This script will download, compile, and install Git Credential Manager to:
23
23
@@ -47,7 +47,7 @@ install_shared_packages() {
47
47
48
48
local shared_packages=" git curl"
49
49
for package in $shared_packages ; do
50
- # ensure we don't stomp on existing installations
50
+ # Ensure we don't stomp on existing installations.
51
51
if [ ! -z $( which $package ) ]; then
52
52
continue
53
53
fi
@@ -66,19 +66,19 @@ ensure_dotnet_installed() {
66
66
chmod +x ./dotnet-install.sh
67
67
bash -c " ./dotnet-install.sh"
68
68
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.
71
71
cd ~
72
72
export DOTNET_ROOT=$( pwd) /.dotnet
73
73
add_to_PATH $DOTNET_ROOT
74
74
fi
75
75
}
76
76
77
77
verify_existing_dotnet_installation () {
78
- # get initial pieces of installed sdk version(s)
78
+ # Get initial pieces of installed sdk version(s).
79
79
sdks=$( dotnet --list-sdks | cut -c 1-3)
80
80
81
- # if we have a supported version installed, return
81
+ # If we have a supported version installed, return.
82
82
supported_dotnet_versions=" 6.0"
83
83
for v in $supported_dotnet_versions ; do
84
84
if [ $( echo $sdks | grep " $v " ) ]; then
@@ -90,7 +90,7 @@ verify_existing_dotnet_installation() {
90
90
add_to_PATH () {
91
91
for directory; do
92
92
if [ ! -d " $directory " ]; then
93
- continue ; # skip nonexistent directory
93
+ continue ; # Skip nonexistent directory.
94
94
fi
95
95
case " :$PATH :" in
96
96
* " :$directory :" * )
@@ -103,10 +103,17 @@ add_to_PATH () {
103
103
done
104
104
}
105
105
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
+
106
113
sudo_cmd=
107
114
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).
110
117
if [ -z " $sudo_cmd " ]; then
111
118
if [ ` id -u` != 0 ]; then
112
119
sudo_cmd=sudo
@@ -120,37 +127,42 @@ case "$distribution" in
120
127
$sudo_cmd apt update
121
128
install_shared_packages apt install
122
129
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.
134
131
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
139
151
fi
140
152
;;
141
153
linuxmint)
142
154
$sudo_cmd apt update
143
155
install_shared_packages apt install
144
156
145
- # install dotnet packages and dependencies
157
+ # Install dotnet packages and dependencies.
146
158
$sudo_cmd apt install libc6 libgcc1 libgssapi-krb5-2 libssl1.1 libstdc++6 zlib1g libicu66 -y
147
159
ensure_dotnet_installed
148
160
;;
149
161
fedora | centos | rhel)
150
162
$sudo_cmd dnf update -y
151
163
install_shared_packages dnf install
152
164
153
- # install dotnet/gcm dependencies
165
+ # Install dotnet/GCM dependencies.
154
166
$sudo_cmd dnf install krb5-libs libicu openssl-libs zlib findutils which bash -y
155
167
156
168
ensure_dotnet_installed
@@ -159,7 +171,7 @@ case "$distribution" in
159
171
$sudo_cmd apk update
160
172
install_shared_packages apk add
161
173
162
- # install dotnet/gcm dependencies
174
+ # Install dotnet/GCM dependencies.
163
175
$sudo_cmd apk add icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib which bash coreutils gcompat
164
176
165
177
ensure_dotnet_installed
@@ -170,7 +182,7 @@ case "$distribution" in
170
182
;;
171
183
esac
172
184
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.
174
186
script_path=" $( cd " $( dirname " $0 " ) " && pwd) "
175
187
toplevel_path=" ${script_path%/ src/ linux/ Packaging.Linux} "
176
188
if [ " z$script_path " = " z$toplevel_path " ] || [ ! -f " $toplevel_path /Git-Credential-Manager.sln" ]; then
0 commit comments