-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
install-from-source.sh
executable file
·229 lines (191 loc) · 6.67 KB
/
install-from-source.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/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.
set -e
is_ci=
for i in "$@"; do
case "$i" in
-y)
is_ci=true
shift # Past argument=value
;;
esac
done
# 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:
/usr/local/bin
Git Credential Manager is licensed under the MIT License: https://aka.ms/gcm/license"
while true; do
read -p "Do you want to continue? [Y/n] " yn
case $yn in
[Yy]*|"")
break
;;
[Nn]*)
exit
;;
*)
echo "Please answer yes or no."
;;
esac
done
fi
install_packages() {
pkg_manager=$1
install_verb=$2
packages=$3
for package in $packages; do
# Ensure we don't stomp on existing installations.
if [ ! -z $(which $package) ]; then
continue
fi
if [ $pkg_manager = apk ]; then
$sudo_cmd $pkg_manager $install_verb $package
elif [ $pkg_manager = zypper ]; then
$sudo_cmd $pkg_manager -n $install_verb $package
elif [ $pkg_manager = pacman ]; then
$sudo_cmd $pkg_manager --noconfirm $install_verb $package
else
$sudo_cmd $pkg_manager $install_verb $package -y
fi
done
}
ensure_dotnet_installed() {
if [ -z "$(verify_existing_dotnet_installation)" ]; then
curl -LO https://dot.net/v1/dotnet-install.sh
chmod +x ./dotnet-install.sh
bash -c "./dotnet-install.sh --channel 7.0"
# 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).
sdks=$(dotnet --list-sdks | cut -c 1-3)
# If we have a supported version installed, return.
supported_dotnet_versions="7.0"
for v in $supported_dotnet_versions; do
if [ $(echo $sdks | grep "$v") ]; then
echo $sdks
fi
done
}
add_to_PATH () {
for directory; do
if [ ! -d "$directory" ]; then
continue; # Skip nonexistent directory.
fi
case ":$PATH:" in
*":$directory:"*)
break
;;
*)
export PATH=$PATH:$directory
;;
esac
done
}
apt_install() {
pkg_name=$1
$sudo_cmd apt update
$sudo_cmd apt install $pkg_name -y 2>/dev/null
}
print_unsupported_distro() {
prefix=$1
distro=$2
echo "$prefix: $distro is not officially supported by the GCM project."
echo "See https://gh.io/gcm/linux for details."
}
sudo_cmd=
# 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
fi
fi
eval "$(sed -n 's/^ID=/distribution=/p' /etc/os-release)"
eval "$(sed -n 's/^VERSION_ID=/version=/p' /etc/os-release | tr -d '"')"
case "$distribution" in
debian | ubuntu)
$sudo_cmd apt update
install_packages apt install "curl git"
# Install dotnet packages and dependencies if needed.
if [ -z "$(verify_existing_dotnet_installation)" ]; then
# First try to use native feeds (Ubuntu 22.04 and later).
if ! apt_install dotnet7; 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-7.0 dpkg-dev -y
fi
fi
;;
fedora | centos | rhel)
$sudo_cmd dnf upgrade -y
# Install dotnet/GCM dependencies.
install_packages dnf install "curl git krb5-libs libicu openssl-libs zlib findutils which bash"
ensure_dotnet_installed
;;
alpine)
$sudo_cmd apk update
# Install dotnet/GCM dependencies.
install_packages apk add "curl git icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib which bash coreutils gcompat"
ensure_dotnet_installed
;;
sles | opensuse*)
$sudo_cmd zypper -n update
# Install dotnet/GCM dependencies.
install_packages zypper install "curl git find krb5 libicu libopenssl1_1"
ensure_dotnet_installed
;;
arch)
print_unsupported_distro "WARNING" "$distribution"
# --noconfirm required when running from container
$sudo_cmd pacman -Syu --noconfirm
# Install dotnet/GCM dependencies.
install_packages pacman -Sy "curl git glibc gcc krb5 icu openssl libc++ zlib"
ensure_dotnet_installed
;;
mariner)
print_unsupported_distro "WARNING" "$distribution"
$sudo_cmd tdnf update -y
# Install dotnet/GCM dependencies.
install_packages tdnf install "curl git krb5-libs libicu openssl-libs zlib findutils which bash"
ensure_dotnet_installed
;;
*)
print_unsupported_distro "ERROR" "$distribution"
exit
;;
esac
# 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
toplevel_path="$PWD/git-credential-manager"
test -d "$toplevel_path" || git clone https://github.com/git-ecosystem/git-credential-manager
fi
if [ -z "$DOTNET_ROOT" ]; then
DOTNET_ROOT="$(dirname $(which dotnet))"
fi
cd "$toplevel_path"
$sudo_cmd env "PATH=$PATH" $DOTNET_ROOT/dotnet build ./src/linux/Packaging.Linux/Packaging.Linux.csproj -c Release -p:InstallFromSource=true
add_to_PATH "/usr/local/bin"