Unverified Commit 1063e129 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

dotnet: allow multiple dotnet versions (#34)

* dotnet: allow multiple dotnet versions

* nit

* change description

* change condtion

* nit

* change exit code

* restructure linkinh

* nit

* adding installUsingApt

* export path

* fix path

* fix eof

* fix updaterc

* change access

* add USERNAME

* export

* debug 1

* add missing $
parent 502af2c6
...@@ -12,10 +12,20 @@ ...@@ -12,10 +12,20 @@
"type":"boolean", "type":"boolean",
"default": false, "default": false,
"description": "Install just the dotnet runtime if true, and sdk if false." "description": "Install just the dotnet runtime if true, and sdk if false."
},
"overrideDefaultVersion": {
"type": "boolean",
"default": "true",
"description": "If true, overrides existing version (if any) of dotnet on the PATH"
},
"installUsingApt": {
"type": "boolean",
"default": "true",
"description": "If true, it installs using apt instead of the release URL"
} }
}, },
"containerEnv": { "containerEnv": {
"DOTNET_ROOT": "/usr/local/dotnet", "DOTNET_ROOT": "/usr/local/dotnet/current",
"PATH": "${PATH}:${DOTNET_ROOT}" "PATH": "${PATH}:${DOTNET_ROOT}"
}, },
"extensions": [ "extensions": [
......
...@@ -15,6 +15,8 @@ USERNAME=${3:-"automatic"} ...@@ -15,6 +15,8 @@ USERNAME=${3:-"automatic"}
UPDATE_RC=${4:-"true"} UPDATE_RC=${4:-"true"}
TARGET_DOTNET_ROOT=${5:-"/usr/local/dotnet"} TARGET_DOTNET_ROOT=${5:-"/usr/local/dotnet"}
ACCESS_GROUP=${6:-"dotnet"} ACCESS_GROUP=${6:-"dotnet"}
OVERRIDE_DEFAULT_VERSION=${7:-"true"}
INSTALL_USING_APT=${8:-"true"}
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
DOTNET_ARCHIVE_ARCHITECTURES="amd64" DOTNET_ARCHIVE_ARCHITECTURES="amd64"
...@@ -92,8 +94,8 @@ get_common_setting() { ...@@ -92,8 +94,8 @@ get_common_setting() {
echo "$1=${!1}" echo "$1=${!1}"
} }
# Add TARGET_DOTNET_ROOT variable into PATH in bashrc/zshrc files. # Add dotnet directory to PATH in bashrc/zshrc files if OVERRIDE_DEFAULT_VERSION=true.
updaterc() { updaterc() {
if [ "${UPDATE_RC}" = "true" ]; then if [ "${UPDATE_RC}" = "true" ]; then
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..." echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
...@@ -209,6 +211,12 @@ install_using_apt() { ...@@ -209,6 +211,12 @@ install_using_apt() {
else else
# Sets DOTNET_VERSION and DOTNET_PACKAGE if matches found. # Sets DOTNET_VERSION and DOTNET_PACKAGE if matches found.
apt_cache_package_and_version_soft_match DOTNET_VERSION DOTNET_PACKAGE false apt_cache_package_and_version_soft_match DOTNET_VERSION DOTNET_PACKAGE false
if [[ $(dotnet --version) == *"${DOTNET_VERSION}"* ]] ; then
echo "Dotnet version ${DOTNET_VERSION} is already installed"
exit 1
fi
if [ "$?" != 0 ]; then if [ "$?" != 0 ]; then
return 1 return 1
fi fi
...@@ -307,6 +315,12 @@ install_using_dotnet_releases_url() { ...@@ -307,6 +315,12 @@ install_using_dotnet_releases_url() {
fi fi
get_full_version_details "${sdk_or_runtime}" get_full_version_details "${sdk_or_runtime}"
DOTNET_INSTALL_PATH="${TARGET_DOTNET_ROOT}/${DOTNET_VERSION}"
if [ -d "${DOTNET_INSTALL_PATH}" ]; then
echo "(!) Dotnet version ${DOTNET_VERSION} already exists."
exit 1
fi
# exports DOTNET_DOWNLOAD_URL, DOTNET_DOWNLOAD_HASH, DOTNET_DOWNLOAD_NAME # exports DOTNET_DOWNLOAD_URL, DOTNET_DOWNLOAD_HASH, DOTNET_DOWNLOAD_NAME
echo "DOWNLOAD LINK: ${DOTNET_DOWNLOAD_URL}" echo "DOWNLOAD LINK: ${DOTNET_DOWNLOAD_URL}"
...@@ -330,20 +344,28 @@ install_using_dotnet_releases_url() { ...@@ -330,20 +344,28 @@ install_using_dotnet_releases_url() {
echo "${DOTNET_DOWNLOAD_HASH} *${DOTNET_DOWNLOAD_NAME}" | sha512sum -c - echo "${DOTNET_DOWNLOAD_HASH} *${DOTNET_DOWNLOAD_NAME}" | sha512sum -c -
# Extract binaries and add to path. # Extract binaries and add to path.
mkdir -p "${TARGET_DOTNET_ROOT}" mkdir -p "${DOTNET_INSTALL_PATH}"
echo "Extract Binary to ${TARGET_DOTNET_ROOT}" echo "Extract Binary to ${DOTNET_INSTALL_PATH}"
tar -xzf "${TMP_DIR}/${DOTNET_DOWNLOAD_NAME}" -C "${TARGET_DOTNET_ROOT}" --strip-components=1 tar -xzf "${TMP_DIR}/${DOTNET_DOWNLOAD_NAME}" -C "${DOTNET_INSTALL_PATH}" --strip-components=1
updaterc "$(cat << EOF CURRENT_DIR="${TARGET_DOTNET_ROOT}/current"
export DOTNET_ROOT="${TARGET_DOTNET_ROOT}" if [[ ! -d "${CURRENT_DIR}" ]]; then
if [[ "\${PATH}" != *"\${DOTNET_ROOT}"* ]]; then export PATH="\${PATH}:\${DOTNET_ROOT}"; fi ln -s "${DOTNET_INSTALL_PATH}" "${CURRENT_DIR}"
EOF fi
)"
# Give write permissions to the user. # Give write permissions to the user.
chown -R ":${ACCESS_GROUP}" "${TARGET_DOTNET_ROOT}" chown -R "${USERNAME}:${USERNAME}" "${CURRENT_DIR}"
chmod g+r+w+s "${TARGET_DOTNET_ROOT}" chmod g+r+w+s "${CURRENT_DIR}"
chmod -R g+r+w "${TARGET_DOTNET_ROOT}" chmod -R g+r+w "${CURRENT_DIR}"
if [[ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]]; then
if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${DOTNET_INSTALL_PATH}"* ]] ; then
rm "${CURRENT_DIR}"
ln -s "${DOTNET_INSTALL_PATH}" "${CURRENT_DIR}"
fi
fi
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=${CURRENT_DIR}:\${PATH}; fi"
} }
########################### ###########################
...@@ -381,16 +403,16 @@ echo "(*) Installing .NET CLI..." ...@@ -381,16 +403,16 @@ echo "(*) Installing .NET CLI..."
. /etc/os-release . /etc/os-release
architecture="$(dpkg --print-architecture)" architecture="$(dpkg --print-architecture)"
use_dotnet_releases_url="false" if [[ "${DOTNET_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${DOTNET_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]] && [[ "${INSTALL_USING_APT}" = "true" ]]; then
if [[ "${DOTNET_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${DOTNET_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
echo "Detected ${VERSION_CODENAME} on ${architecture}. Attempting to install dotnet from apt" echo "Detected ${VERSION_CODENAME} on ${architecture}. Attempting to install dotnet from apt"
install_using_apt "${DOTNET_SDK_OR_RUNTIME}" || use_dotnet_releases_url="true" install_using_apt "${DOTNET_SDK_OR_RUNTIME}"
else else
use_dotnet_releases_url="true" if [[ "${INSTALL_USING_APT}" = "false" ]]; then
fi echo "Installing dotnet from releases url"
else
echo "Could not install dotnet from apt. Attempting to install dotnet from releases url"
fi
if [ "${use_dotnet_releases_url}" = "true" ]; then
echo "Could not install dotnet from apt. Attempting to install dotnet from releases url"
install_using_dotnet_releases_url "${DOTNET_SDK_OR_RUNTIME}" install_using_dotnet_releases_url "${DOTNET_SDK_OR_RUNTIME}"
fi fi
......
...@@ -19,7 +19,7 @@ _BUILD_ARG_RUBY="./ruby/install.sh ${_B ...@@ -19,7 +19,7 @@ _BUILD_ARG_RUBY="./ruby/install.sh ${_B
_BUILD_ARG_RUST="./rust/install.sh /usr/local/cargo /usr/local/rustup automatic true false ${_BUILD_ARG_RUST_VERSION:-latest} ${_BUILD_ARG_RUST_PROFILE:-minimal}" _BUILD_ARG_RUST="./rust/install.sh /usr/local/cargo /usr/local/rustup automatic true false ${_BUILD_ARG_RUST_VERSION:-latest} ${_BUILD_ARG_RUST_PROFILE:-minimal}"
_BUILD_ARG_POWERSHELL="./powershell/install.sh ${_BUILD_ARG_POWERSHELL_VERSION:-latest}" _BUILD_ARG_POWERSHELL="./powershell/install.sh ${_BUILD_ARG_POWERSHELL_VERSION:-latest}"
_BUILD_ARG_DESKTOP_LITE="./desktop-lite/install.sh automatic ${_BUILD_ARG_DESKTOP_LITE_PASSWORD:-vscode} true ${_BUILD_ARG_DESKTOP_LITE_VNCPORT:-5901} ${_BUILD_ARG_DESKTOP_LITE_WEBPORT:-6080}" _BUILD_ARG_DESKTOP_LITE="./desktop-lite/install.sh automatic ${_BUILD_ARG_DESKTOP_LITE_PASSWORD:-vscode} true ${_BUILD_ARG_DESKTOP_LITE_VNCPORT:-5901} ${_BUILD_ARG_DESKTOP_LITE_WEBPORT:-6080}"
_BUILD_ARG_DOTNET="./dotnet/install.sh ${_BUILD_ARG_DOTNET_VERSION:-latest} ${_BUILD_ARG_DOTNET_RUNTIMEONLY:-false} automatic true /usr/local/dotnet dotnet" _BUILD_ARG_DOTNET="./dotnet/install.sh ${_BUILD_ARG_DOTNET_VERSION:-latest} ${_BUILD_ARG_DOTNET_RUNTIMEONLY:-false} automatic true /usr/local/dotnet dotnet ${_BUILD_ARG_DOTNET_OVERRIDEDEFAULTVERSION:-true} ${_BUILD_ARG_DOTNET_INSTALLUSINGAPT:-true}"
_BUILD_ARG_JUPYTERLAB="./jupyterlab/install.sh ${_BUILD_ARG_JUPYTERLAB_VERSION:-latest}" automatic ${_BUILD_ARG_JUPYTERLAB_PYTHONBINARY:-python}" true _BUILD_ARG_JUPYTERLAB="./jupyterlab/install.sh ${_BUILD_ARG_JUPYTERLAB_VERSION:-latest}" automatic ${_BUILD_ARG_JUPYTERLAB_PYTHONBINARY:-python}" true
_BUILD_ARG_PHP="./php/install.sh ${_BUILD_ARG_PHP_VERSION:-latest} /usr/local/php ${_BUILD_ARG_PHP_INSTALLCOMPOSER:-true} true automatic true" _BUILD_ARG_PHP="./php/install.sh ${_BUILD_ARG_PHP_VERSION:-latest} /usr/local/php ${_BUILD_ARG_PHP_INSTALLCOMPOSER:-true} true automatic true"
_BUILD_ARG_ORYX="./oryx/install.sh" _BUILD_ARG_ORYX="./oryx/install.sh"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment