Skip to content

Commit 7b76633

Browse files
author
Chris Maunder
committed
.NET install corrections for macOS/Ubuntu/Debian
1 parent ad0bed2 commit 7b76633

File tree

5 files changed

+92
-121
lines changed

5 files changed

+92
-121
lines changed

devops/install/dotnet-install-arm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fi
135135
echo -e "${bold}Creating Main Directory${reset}"
136136

137137
if [[ -d /opt/dotnet ]]; then
138-
echo "/opt/dotnet already exists on your filesystem."
138+
echo "/opt/dotnet already exists on your filesystem."
139139
else
140140
echo "Creating Main Directory"
141141
mkdir /opt/dotnet

devops/install/dotnet-install.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,11 @@ get_user_install_path() {
939939
echo "$DOTNET_INSTALL_DIR"
940940
else
941941
if [ "$normalized_os" == "osx" ]; then
942-
echo "/usr/local/share/dotnet"
942+
# if [ "$(get_machine_architecture)" = "arm64" ]; then
943+
# echo "/opt/dotnet"
944+
# else
945+
echo "/usr/local/share/dotnet"
946+
# fi
943947
else
944948
echo "$HOME/.dotnet"
945949
fi

src/SDK/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ else
7575
write "Installing System.Drawing support "
7676
fi
7777

78-
if [ $"$architecture" = 'arm64' ]; then
78+
if [ "$architecture" = 'arm64' ]; then
7979
arch -x86_64 /usr/local/bin/brew list fontconfig >/dev/null 2>/dev/null || \
8080
arch -x86_64 /usr/local/bin/brew install fontconfig >/dev/null 2>/dev/null &
8181
spin $!
@@ -95,7 +95,7 @@ else
9595
else
9696
writeLine "Installing System.Drawing support "
9797

98-
if [ $"$architecture" = 'arm64' ]; then
98+
if [ "$architecture" = 'arm64' ]; then
9999
arch -x86_64 /usr/local/bin/brew list fontconfig || arch -x86_64 /usr/local/bin/brew install fontconfig
100100
arch -x86_64 /usr/local/bin/brew list libomp || arch -x86_64 /usr/local/bin/brew install libomp
101101
else

src/scripts/utils.sh

Lines changed: 77 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function checkForAdminRights () {
347347
fi
348348

349349
if [ "$isAdmin" = false ] && [ "$requestPassword" = true ]; then
350-
if [ "$os" == "macos" ]; then
350+
if [ "$os" = "macos" ]; then
351351
# THIS DOES NOT WORK
352352
# This shows the password prompt, but the admin rights starts and ends with the "whoami"
353353
# call. Once that call finishes, admin rights no longer apply.
@@ -409,7 +409,7 @@ function checkForTool () {
409409

410410
# Ensure Brew is installed. NOTE: macOS has curl built in, so no worries
411411
# about recursion if calling checkForTool "curl"
412-
if [ $"$architecture" = 'arm64' ]; then
412+
if [ "$architecture" = 'arm64' ]; then
413413
if [ ! -f /usr/local/bin/brew ]; then
414414

415415
checkForAdminAndWarn "arch -x86_64 /bin/bash -c '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)'"
@@ -504,7 +504,7 @@ function checkForTool () {
504504
}
505505

506506
function setupSSL() {
507-
if [ "$os" = "linux" ] && [ "$architecture" == "x86_64" ]; then
507+
if [ "$os" = "linux" ] && [ "$architecture" = "x86_64" ]; then
508508

509509
if [ ! -f /usr/lib/x86_64-linux-gnu/libssl.so.1.1 ] || [ ! -e /usr/lib/libcrypto.so.1.1 ]; then
510510

@@ -587,7 +587,7 @@ function getDotNetVersion() {
587587
IFS=$'\n' # set the Internal Field Separator as end of line
588588
while read -r line
589589
do
590-
if [[ ${line} == *'Microsoft.NETCore.App '* ]]; then
590+
if [[ $line == *'Microsoft.NETCore.App '* ]]; then
591591
dotnet_version=$(echo "${line}" | cut -d ' ' -f 2)
592592
# echo "GET: Found .NET runtime $dotnet_version" >&3
593593

@@ -619,6 +619,32 @@ function getMajorDotNetVersion() {
619619
echo "$dotnet_major_version"
620620
}
621621

622+
function setDotNetLocation () {
623+
624+
local profile_location=$1
625+
local dotnet_path=$2
626+
627+
if [ -f $location ]; then
628+
629+
if grep -q "export DOTNET_ROOT=${profile_location}"; then
630+
write "Already added link to $profile_location"
631+
else
632+
write "Adding Link to $location"
633+
echo 'export DOTNET_ROOT=${dotnet_path}' >> $profile_location
634+
export DOTNET_ROOT=${dotnet_path}
635+
fi
636+
637+
if [[ $PATH == *"${dotnet_path}"* ]]; then
638+
write "PATH contains location of .NET"
639+
else
640+
write "Adding location of .NET to PATH"
641+
echo "export PATH=${dotnet_path}${PATH:+:${PATH}}" >> $profile_location
642+
export PATH=${dotnet_path}${PATH:+:${PATH}}
643+
fi
644+
fi
645+
}
646+
647+
622648
function setupDotNet () {
623649

624650
# only major/minor versions accepted (eg 7.0)
@@ -684,7 +710,7 @@ function setupDotNet () {
684710
IFS=$'\n' # set the Internal Field Separator as end of line
685711
while read -r line
686712
do
687-
if [[ ${line} == *'Microsoft.NETCore.App '* ]]; then
713+
if [[ $line == *'Microsoft.NETCore.App '* ]]; then
688714

689715
dotnet_version=$(echo "${line}" | cut -d ' ' -f 2)
690716
dotnet_major_version=$(echo "${dotnet_version}" | cut -d '.' -f 1)
@@ -714,7 +740,7 @@ function setupDotNet () {
714740
fi
715741

716742
mustInstall="false"
717-
if [ "$haveRequested" == true ]; then
743+
if [ "$haveRequested" = true ]; then
718744
writeLine "All good. .NET ${requestedType} is ${highestDotNetVersion}" $color_success
719745
elif (( $comparison == 0 )); then
720746
writeLine "All good. .NET ${requestedType} is ${highestDotNetVersion}" $color_success
@@ -737,18 +763,25 @@ function setupDotNet () {
737763
return 6 # unable to download required asset
738764
fi
739765

740-
if [ "$architecture" = 'arm64' ]; then
741-
dotnet_path="/opt/dotnet"
742-
elif [ "$os" = "linux" ]; then
743-
dotnet_path="/usr/lib/dotnet/"
766+
if [ "$os" = "linux" ]; then
767+
dotnet_basepath="/usr/lib/"
744768
else # macOS x64
745-
# dotnet_path="~/.dotnet/"
746-
dotnet_path="/usr/local/share/dotnet/"
769+
# dotnet_basepath="~/."
770+
# if [ "$architecture" = 'arm64' ]; then
771+
# dotnet_basepath="/opt/"
772+
# else
773+
dotnet_basepath="/usr/local/share/"
774+
# fi
747775
fi
776+
dotnet_path="${dotnet_basepath}/dotnet/"
748777

778+
useCustomDotNetInstallScript=false
779+
# No longer using the arm64 custom script: standard install script seems good enough now.
749780
# output a warning message if no admin rights and instruct user on manual steps
750-
if [ "$architecture" = 'arm64' ]; then
751-
install_instructions="sudo bash '${installScriptsDirPath}/dotnet-install-arm.sh' $requestedNetMajorMinorVersion $requestedType"
781+
# if [ "$architecture" = 'arm64' ]; then useCustomDotNetInstallScript=true; fi
782+
783+
if [ "$useCustomDotNetInstallScript" = true ]; then
784+
install_instructions="sudo bash '${installScriptsDirPath}/dotnet-install-arm.sh' $requestedNetMajorMinorVersion $requestedType"
752785
else
753786
install_instructions="sudo bash '${installScriptsDirPath}/dotnet-install.sh' --install-dir '${dotnet_path}' --channel $requestedNetMajorMinorVersion --runtime $requestedType"
754787
fi
@@ -757,8 +790,8 @@ function setupDotNet () {
757790
if [ "$isAdmin" = true ] || [ "$attemptSudoWithoutAdminRights" = true ]; then
758791
if [ "$os" = "linux" ]; then
759792

760-
# Disabled this due to it not proving reliable
761-
if [ "$os_name" = "debian-SKIP" ]; then
793+
# Potentially not reliable. Only blessed by MS for Debian >= 12
794+
if [ "$os_name" = "debian" ] && [ ! "$os_vers" < "12" ]; then
762795

763796
wget https://packages.microsoft.com/config/debian/${os_vers}/packages-microsoft-prod.deb -O packages-microsoft-prod.deb >/dev/null
764797
sudo dpkg -i packages-microsoft-prod.deb >/dev/null
@@ -770,11 +803,11 @@ function setupDotNet () {
770803
sudo apt-get update && sudo apt-get install -y aspnetcore-runtime-$requestedNetMajorMinorVersion >/dev/null
771804
fi
772805

773-
# .NET 9 is almost good to go
774-
elif [ "$os_name" == "ubuntu" ] && [ "$requestedNetMajorVersion" == "9" ]; then
806+
# .NET 9 seems to settle down the "we do/we don't" that MS is doing with .NET 6,7 and 8.
807+
elif [ "$requestedNetMajorVersion" = "9" ]; then # ... && [ "$os_name" = "ubuntu" ]
775808

776809
# TODO: Change this to a " >= 24.10"
777-
if [ "$os_vers" == "24.10" ]; then
810+
if [ "$os_name" = "ubuntu" ] && [ "$os_vers" = "24.10" ]; then
778811
if [ "$requestedType" = "sdk" ]; then
779812
sudo apt-get update && sudo apt-get install -y dotnet-sdk-$requestedNetMajorMinorVersion >/dev/null
780813
else
@@ -793,7 +826,7 @@ function setupDotNet () {
793826
# Needed if we're installing .NET without an installer to help us
794827
installAptPackages "ca-certificates libc6 libgcc-s1 libicu74 liblttng-ust1 libssl3 libstdc++6 libunwind8 zlib1g"
795828

796-
if [ "$architecture" = 'arm64' ]; then
829+
if [ "$useCustomDotNetInstallScript" = true ]; then
797830
# installs in /opt/dotnet
798831
if [ $verbosity = "quiet" ]; then
799832
sudo bash "${installScriptsDirPath}/dotnet-install-arm.sh" "${requestedNetMajorVersion}.0" "$requestedType" "quiet"
@@ -814,7 +847,7 @@ function setupDotNet () {
814847
else
815848
# macOS
816849

817-
# Needed if we're installing .NET without an installer to help us
850+
# (Maybe) needed if we're installing .NET without an installer to help us
818851
# installAptPackages "ca-certificates libc6 libgcc-s1 libicu74 liblttng-ust1 libssl3 libstdc++6 libunwind8 zlib1g"
819852

820853
if [ $verbosity = "quiet" ]; then
@@ -831,48 +864,22 @@ function setupDotNet () {
831864
# return 2 # failed to install required runtime
832865
#fi
833866

834-
if [ "$os" = "linux" ] && [ "$architecture" != "arm64" ]; then
835-
836-
# Add link
837-
# ln -s /opt/dotnet/dotnet /usr/local/bin
838-
839-
# if [ "$os_name" = "debian" ]; then
840-
# sudo ln ~/.dotnet/dotnet /usr/bin
841-
#fi
842-
843-
# make link permanent
844-
if grep -q 'export DOTNET_ROOT=' ~/.bashrc; then
845-
echo 'Already added link to .bashrc'
846-
else
847-
echo 'export DOTNET_ROOT=/usr/bin/' >> ~/.bashrc
848-
fi
867+
# The install script is for CI/CD and doesn't actually register .NET. So add
868+
# link and env variables
869+
writeLine "Link Binaries to /usr/local/bin..."
870+
if [ -e /usr/local/bin/dotnet ]; then
871+
rm /usr/local/bin/dotnet
849872
fi
873+
ln -s ${dotnet_path}dotnet /usr/local/bin
850874

851-
if [ "$os" == "macos" ]; then
852-
# The install script is for CI/CD and doesn't actually register .NET. So add
853-
# link and env variable
854-
export DOTNET_ROOT=${dotnet_path}
855-
export PATH=${DOTNET_ROOT}${PATH:+:${PATH}}
856-
857-
if [ -e /usr/local/bin/dotnet ]; then
858-
rm /usr/local/bin/dotnet
859-
fi
860-
861-
if [ ! -e /usr/local/bin/dotnet ]; then
862-
ln -fs "${dotnet_path}dotnet" "/usr/local/bin/dotnet"
863-
fi
864-
865-
# if [ -f ~/.bashrc ]; then
866-
if [ ! -f ~/.bashrc ] || [ $(grep -q 'export DOTNET_ROOT=' ~/.bashrc) ]; then
867-
sudo echo "export DOTNET_ROOT=${dotnet_path}" >> ~/.bashrc
868-
sudo echo "export PATH=${dotnet_path}${PATH:+:${PATH}}" >> ~/.bashrc
869-
fi
870-
# elif [ -f ~/.bash_profile ]; then
871-
# if grep -q 'export DOTNET_ROOT=' ~/.bash_profile; then
872-
# echo 'export DOTNET_ROOT=${dotnet_path}' >> ~/.bash_profile
873-
# echo "export PATH=${dotnet_path}${PATH:+:${PATH}}" >> ~/.bash_profile
874-
# fi
875-
# fi
875+
if [ -f " /home/pi/.bashrc" ]; then
876+
setDotNetLocation " /home/pi/.bashrc" "${dotnet_path}"
877+
elif [ -f " ~/.bashrc" ]; then
878+
setDotNetLocation " ~/.bashrc" "${dotnet_path}"
879+
elif [ -f " ~/.bash_profile" ]; then
880+
setDotNetLocation " ~/.bash_profile" "${dotnet_path}"
881+
elif [ -f " ~/.zshrc" ]; then
882+
setDotNetLocation " ~/.zshrc" "${dotnet_path}"
876883
fi
877884
fi
878885

@@ -1098,7 +1105,7 @@ function setupPython () {
10981105
[ "$os_name" = "debian" ]; then
10991106

11001107
# ensure gcc is installed
1101-
if [ "$os_name" == "debian" ]; then
1108+
if [ "$os_name" = "debian" ]; then
11021109
# gcc and make
11031110
installAptPackages "build-essential make"
11041111
# to build python on Debian
@@ -1209,7 +1216,7 @@ function setupPython () {
12091216
# Build and install Python
12101217
cd Python-${pythonPatchVersion}
12111218

1212-
if [ "$os_name" == "debian" ]; then
1219+
if [ "$os_name" = "debian" ]; then
12131220
# Native debian is giving us troubles. The instructions should be optimised down
12141221
# to just what's needed, but for now we'll just throw everything at the problem
12151222
# until we find a solution to the "SSLError("Can't connect to HTTPS URL because
@@ -2355,7 +2362,7 @@ function getValueFromModuleSettingsFile () {
23552362
local moduleId=$2
23562363
local property=$3
23572364

2358-
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" == "true" ]; then
2365+
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" = "true" ]; then
23592366
echo "Searching for '${property}' in a suitable modulesettings.json file in ${moduleDirPath}" >&3
23602367
fi
23612368

@@ -2412,7 +2419,7 @@ function getValueFromModuleSettingsFile () {
24122419
if [ "${moduleSettingValue}" != "" ]; then settings_file_used="modulesettings.json"; fi
24132420
fi
24142421

2415-
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" == "true" ]; then
2422+
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" = "true" ]; then
24162423
if [ "${moduleSettingValue}" = "" ]; then
24172424
echo "Cannot find ${moduleId}.${property} in modulesettings in ${moduleDirPath}" >&3
24182425
else
@@ -2465,7 +2472,7 @@ function getValueFromModuleSettings () {
24652472
key=$".Modules.${moduleId}.${property}"
24662473
fi
24672474

2468-
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" == "true" ]; then
2475+
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" = "true" ]; then
24692476
echo jsonFile is $json_file >&3
24702477
echo parse_mode is $parse_mode >&3
24712478
fi
@@ -2527,9 +2534,9 @@ function getValueFromModuleSettings () {
25272534
fi
25282535

25292536
# Really??
2530-
if [ "$jsonValue" == "null" ]; then jsonValue=""; fi
2537+
if [ "$jsonValue" = "null" ]; then jsonValue=""; fi
25312538

2532-
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" == "true" ]; then
2539+
if [ "$verbosity" = "loud" ] && [ "$debug_json_parse" = "true" ]; then
25332540
echo "${key} = $jsonValue" >&3;
25342541
fi
25352542

@@ -2570,7 +2577,7 @@ function getModuleIdFromModuleSettings () {
25702577
fi
25712578

25722579
# Really?? A literal "null"?
2573-
if [ "$jsonValue" == "null" ]; then jsonValue=""; fi
2580+
if [ "$jsonValue" = "null" ]; then jsonValue=""; fi
25742581

25752582
# debug
25762583
# if [ "$verbosity" = "loud" ]; then echo "${key} = $jsonValue" >&3; fi
@@ -2616,7 +2623,7 @@ function getValueFromJsonFile () {
26162623
fi
26172624

26182625
# Really?? A literal "null"?
2619-
if [ "$jsonValue" == "null" ]; then jsonValue=""; fi
2626+
if [ "$jsonValue" = "null" ]; then jsonValue=""; fi
26202627

26212628
# debug
26222629
# if [ "$verbosity" = "loud" ]; then echo "${key} = $jsonValue" >&3; fi
@@ -2718,46 +2725,6 @@ function getDisplaySize () {
27182725
echo "Rows=$(tput lines) Cols=$(tput cols)"
27192726
}
27202727

2721-
haveDisplayedMacOSDirCreatePermissionError=false
2722-
function displayMacOSDirCreatePermissionError () {
2723-
2724-
if [[ $OSTYPE == 'darwin'* ]] && [ "$haveDisplayedMacOSDirCreatePermissionError" = false ]; then
2725-
2726-
haveDisplayedMacOSDirCreatePermissionError=true
2727-
2728-
writeLine ''
2729-
writeLine ''
2730-
writeLine 'We may be able to suggest something:' $color_info
2731-
2732-
if [ "$os_name" = "Sonoma" ]; then # macOS 14 / Kernal 23
2733-
# Note that  will appear as the Apple symbol on macOS, but probably not on Windows or Linux
2734-
writeLine '1. Pull down the  Apple menu and choose "System Settings"'
2735-
writeLine '2. Choose “Privacy & Security"'
2736-
writeLine '3. Scroll down to “Full Disk Access” and click the right arrow >'
2737-
writeLine '4. Click the [+] plus button, and in the popup, navigate to the'
2738-
writeLine ' /Applications/Utilities/ folder and choose "Terminal"'
2739-
writeLine '5. Relaunch Terminal. The “Operation not permitted” error messages should'
2740-
writeLine ' be gone'
2741-
else
2742-
writeLine '1. Pull down the  Apple menu and choose "System Preferences"'
2743-
writeLine '2. Choose “Security & Privacy” control panel'
2744-
writeLine '3. Now select the “Privacy” tab, then from the left-side menu select'
2745-
writeLine ' “Full Disk Access”'
2746-
writeLine '4. Click the lock icon in the lower left corner of the preference '
2747-
writeLine ' panel and authenticate with an admin level login'
2748-
writeLine '5. Now click the [+] plus button so we can full disk access to Terminal'
2749-
writeLine "6. Navigate to the /Applications/Utilities/ folder and choose 'Terminal'"
2750-
writeLine ' to grant Terminal Full Disk Access privileges'
2751-
writeLine '7. Relaunch Terminal, the “Operation not permitted” error messages should'
2752-
writeLine ' be gone'
2753-
fi
2754-
2755-
writeLine ''
2756-
fi
2757-
2758-
# quit 8 # unable to create file or directory
2759-
}
2760-
27612728
function needRosettaAndiBrew () {
27622729

27632730
writeLine

0 commit comments

Comments
 (0)