Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samruddhikhandale committed Jun 29, 2023
1 parent c9f3f1d commit b42b4f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/dotnet/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ DOTNET_VERSION_CODENAMES_REQUIRE_OLDER_LIBSSL_1="buster bullseye bionic focal hi
# alongside DOTNET_VERSION, but not set as default.
ADDITIONAL_VERSIONS=${ADDITIONALVERSIONS:-""}

APT_PREFERENCES_CONTENT="$(cat << 'EOF'
Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001
EOF
)"

APT_PREFERENCES_FILE_ADDED="false"
APT_PREFERENCES_UPDATED="false"

set -e

# Clean up
Expand Down Expand Up @@ -149,7 +159,7 @@ apt_cache_package_and_version_soft_match() {

apt-get update -y
major_minor_version="$(echo "${requested_version}" | cut -d "." --field=1,2)"
package_name="$(apt-cache search "${partial_package_name}-[0-9].[0-9]" | awk -F" - " '{print $1}' | grep -v "source-built-artifacts" | grep -m 1 "${partial_package_name}-${major_minor_version}")"
package_name="$(apt-cache search "${partial_package_name}-[0-9].[0-9]$" | awk -F" - " '{print $1}' | grep -m 1 "${partial_package_name}-${major_minor_version}")"
dot_escaped="${requested_version//./\\.}"
dot_plus_escaped="${dot_escaped//+/\\+}"
# Regex needs to handle debian package version number format: https://www.systutorials.com/docs/linux/man/5-deb-version/
Expand Down Expand Up @@ -194,13 +204,11 @@ install_using_apt() {
curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg
echo "deb [arch=${architecture} signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/microsoft-${ID}-${VERSION_CODENAME}-prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft.list

# See https://github.com/dotnet/core/issues/7699
cat << 'EOF' >> /etc/apt/preferences
Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001
EOF
[ ! -f /etc/apt/preferences ] && APT_PREFERENCES_FILE_ADDED="true"
APT_PREFERENCES_UPDATED="true"

# See https://github.com/dotnet/core/issues/7699
echo "${APT_PREFERENCES_CONTENT}" >> /etc/apt/preferences
apt-get update -y
fi

Expand Down Expand Up @@ -471,6 +479,14 @@ if [ "${CHANGE_OWNERSHIP}" = "true" ]; then
fi

# Clean up
if [ "${APT_PREFERENCES_UPDATED}" = "true" ]; then
if [ "${APT_PREFERENCES_FILE_ADDED}" = "true" ]; then
rm -f /etc/apt/preferences
else
head -n -3 /etc/apt/preferences > /tmp/preferences-temp && mv /tmp/preferences-temp /etc/apt/preferences
fi
fi

rm -rf /var/lib/apt/lists/*

echo "Done!"
3 changes: 3 additions & 0 deletions test/dotnet/install_dotnet_7_jammy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -e
# Optional: Import test library
source dev-container-features-test-lib

cat /etc/apt/preferences


check "dotnet sdks" dotnet --list-sdks
check "some major version of dotnet 7 is installed" bash -c "dotnet --list-sdks | grep '7\.[0-9]*\.[0-9]*'"
check "dotnet version 7 installed" bash -c "ls -l /usr/lib/dotnet/sdk | grep '7\.[0-9]*\.[0-9]*'"
Expand Down

0 comments on commit b42b4f8

Please sign in to comment.