Skip to content

Commit

Permalink
dotnet: make 'dotnet' available to 'sudo' commands (#1007)
Browse files Browse the repository at this point in the history
* dotnet: use predefined DOTNET_ROOT in install script

* dotnet: create symbolic link in /usr/bin

* dotnet: bump patch version

* dotnet: add test for install dir and symlink

* Remove unneeded --force
  • Loading branch information
sliekens committed Jun 19, 2024
1 parent 1045404 commit 05a4cbf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/dotnet/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "dotnet",
"version": "2.1.0",
"version": "2.1.1",
"name": "Dotnet CLI",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnet",
"description": "This Feature installs the latest .NET SDK, which includes the .NET CLI and the shared runtime. Options are provided to choose a different version or additional versions.",
Expand Down
6 changes: 6 additions & 0 deletions src/dotnet/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ if [ ${#workloads[@]} -ne 0 ]; then
install_workloads "${workloads[@]}"
fi

# Create a symbolic link '/usr/bin/dotnet', to make dotnet available to 'sudo'
# This is necessary because 'sudo' resets the PATH variable, so it won't search the DOTNET_ROOT directory
if [ ! -e /usr/bin/dotnet ]; then
ln --symbolic "$DOTNET_ROOT/dotnet" /usr/bin/dotnet
fi

# Clean up
rm -rf /var/lib/apt/lists/*
rm -rf scripts
Expand Down
9 changes: 4 additions & 5 deletions src/dotnet/scripts/dotnet-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Maintainer: The Dev Container spec maintainers
DOTNET_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")
DOTNET_INSTALL_SCRIPT="$DOTNET_SCRIPTS/vendor/dotnet-install.sh"
DOTNET_INSTALL_DIR='/usr/share/dotnet'

# Prints the latest dotnet version in the specified channel
# Usage: fetch_latest_version_in_channel <channel> [<runtime>]
Expand Down Expand Up @@ -75,11 +74,11 @@ install_sdk() {
fi

# Currently this script does not make it possible to qualify the version, 'GA' is always implied
echo "Executing $DOTNET_INSTALL_SCRIPT --version $version --channel $channel --install-dir $DOTNET_INSTALL_DIR"
echo "Executing $DOTNET_INSTALL_SCRIPT --version $version --channel $channel --install-dir $DOTNET_ROOT"
"$DOTNET_INSTALL_SCRIPT" \
--version "$version" \
--channel "$channel" \
--install-dir "$DOTNET_INSTALL_DIR"
--install-dir "$DOTNET_ROOT"
}

# Installs a version of the .NET Runtime
Expand Down Expand Up @@ -107,12 +106,12 @@ install_runtime() {
version="$inputVersion"
fi

echo "Executing $DOTNET_INSTALL_SCRIPT --runtime $runtime --version $version --channel $channel --install-dir $DOTNET_INSTALL_DIR --no-path"
echo "Executing $DOTNET_INSTALL_SCRIPT --runtime $runtime --version $version --channel $channel --install-dir $DOTNET_ROOT --no-path"
"$DOTNET_INSTALL_SCRIPT" \
--runtime "$runtime" \
--version "$version" \
--channel "$channel" \
--install-dir "$DOTNET_INSTALL_DIR" \
--install-dir "$DOTNET_ROOT" \
--no-path
}

Expand Down
6 changes: 6 additions & 0 deletions test/dotnet/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ source dev-container-features-test-lib
source dotnet_env.sh
source dotnet_helpers.sh

check "dotnet is installed in DOTNET_ROOT and execute permission is granted" \
test -x "$DOTNET_ROOT/dotnet"

check "dotnet is symlinked correctly in /usr/bin" \
test -L /usr/bin/dotnet -a "$(readlink -f /usr/bin/dotnet)" = "$DOTNET_ROOT/dotnet"

expected=$(fetch_latest_version)

check "Latest .NET SDK version installed" \
Expand Down

0 comments on commit 05a4cbf

Please sign in to comment.