-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-nuget-config.sh
34 lines (27 loc) · 1.26 KB
/
add-nuget-config.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
#!/bin/bash
# $1: secret-name
secretFilePath="/run/secrets/$1"
if [ -n "$1" ] && [ -f "$secretFilePath" ]; then
xmllint --xpath "//configuration/packageSources/add" $secretFilePath | \
while read -r xmlElement; do
pkgSource=$(echo $xmlElement | awk -F\" '{ print $2 }')
if [ "$pkgSource" = "nuget.org" ]; then
# skip nuget.org
continue
fi
pkgSourceUrl=$(echo $xmlElement | awk -F\" '{ print $4 }')
pkgSourceUsername=$(xmllint --xpath "string(//configuration/packageSourceCredentials/$pkgSource/add[@key='Username']/@value)" $secretFilePath)
pkgSourcePassword=$(xmllint --xpath "string(//configuration/packageSourceCredentials/$pkgSource/add[@key='ClearTextPassword']/@value)" $secretFilePath)
if [ -n "$pkgSourceUsername" ] && [ -n "$pkgSourcePassword" ]; then
# dotnet nuget add source with username and password
dotnet nuget add source -n $pkgSource \
-u $pkgSourceUsername \
-p $pkgSourcePassword \
--store-password-in-clear-text $pkgSourceUrl
else
# dotnet nuget add source
dotnet nuget add source -n $pkgSource $pkgSourceUrl
fi
echo "added '$pkgSource' package source"
done
fi