diff --git a/install-dotnet-ubuntu-22.sh b/install-dotnet-ubuntu-22.sh new file mode 100644 index 0000000..fe520ac --- /dev/null +++ b/install-dotnet-ubuntu-22.sh @@ -0,0 +1,245 @@ +#!/usr/bin/env bash + +############################################################# +# Author: Taryel Hlontsi, 2024 +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +############################################################# + +doc=$(cat <<'EOF' +NOTES: +1) In fact, Emacs has a built-in feature to autoinstall LSP (OmniSharp or csharp_ls) and DAP (netcoredbg) +2) Different versions of .NET can be extracted to the same directory, which coexist side-by-side +3) If something else than $HOME/.dontet is specified, you would need to install the dotnet tools with --tool-path option +4) OmniSharp is a golden standard but it may not work with the latest dotnet SDK, in this case prefer csharp-ls +5) For debugging a debug profile is needed, example: +(dap-register-debug-template + "NetCoreDbg::Launch" + (list :type "coreclr" + :request "launch" + :program "/home/zed/Documents/dotnet-console-games/Projects/2048/bin/Debug/2048.dll" + :cwd "/home/zed/Documents/dotnet-console-games/Projects/2048/" + :mode "launch" + :name "NetCoreDbg::Launch" + :dap-compilation "dotnet build")) +Then evaluate this snippet, M+x dap-debug and finally select that profile +6) Debugger can also be run as a console app, example: +netcoredbg --interpreter=cli -- dotnet 2048.dll +In this case, for priting out the code lines in console, this has to be included in csproj: +true +Docs are there: https://github.com/Samsung/netcoredbg/blob/master/docs/cli.md +7) To start a PowerShell session just type: pwsh +EOF +) + +############################################################# +# SETUP SECTION, do NOT use "sudo" or "./" to run the script. Source it! +############################################################# +LINK_SDK6="https://download.visualstudio.microsoft.com/download/pr/19144d78-6f95-4810-a9f6-3bf86035a244/23f4654fc5352e049b517937f94be839/dotnet-sdk-6.0.421-linux-x64.tar.gz" +LINK_SDK8="https://download.visualstudio.microsoft.com/download/pr/0a1b3cbd-b4af-4d0d-9ed7-0054f0e200b4/4bcc533c66379caaa91770236667aacb/dotnet-sdk-8.0.204-linux-x64.tar.gz" +LINK_OMNI="https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.39.11/omnisharp-linux-x64-net6.0.tar.gz" +LINK_DEBUGGER="https://github.com/Samsung/netcoredbg/releases/download/3.1.0-1031/netcoredbg-linux-amd64.tar.gz" +INSTALL_DIR=$HOME/.dotnet +LOG_DIR="${INSTALL_DIR}/logs" +LOG="${LOG_DIR}/log.txt" +BASHRC="$HOME/.bashrc" + +############################################################# +# HELPER FUNCTIONS +############################################################# +info() { + GREEN='\033[1;32m' + NC='\033[0m' + echo -e "${GREEN}$1${NC}" + echo -e "INFO:\t$1" >> $LOG +} + +trace() { + YELLOW='\033[1;33m' + NC='\033[0m' + echo -e "${YELLOW}$1${NC}" + echo -e "TRACE:\t$1" >> $LOG +} + +warn() { + PURPLE='\033[1;35m' + NC='\033[0m' + echo -e "${PURPLE}$1${NC}" + echo -e "WARN:\t$1" >> $LOG +} + +error() { + RED='\033[1;31m' + NC='\033[0m' + echo -e "${RED}$1${NC}" + echo -e "ERROR:\t$1" >> $LOG +} + +############################################################# +# 1 - DOWNLOAD SDK +############################################################# +download_sdk() { + local step_name='STEP 1 Downloading the SDK' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + + if [[ -z "$1" ]]; then + error "The URL link to SDK archive is expected as argument for this function!" + return 1 + fi + + local link="$1" + local archive=$INSTALL_DIR/dotnet.tar.gz + + export DOTNET_CLI_TELEMETRY_OPTOUT=1 + + wget --continue $link --output-document $archive && \ + tar zxf $archive -C $INSTALL_DIR && \ + rm $archive + + [[ $? -gt 0 ]] && { error "$step_name failed, stopping now"; return 1; } + + info "done" +} + +############################################################# +# 2 - SET UP BASH PROFILE +############################################################# +setup_bash_profile() { + local step_name='STEP 2 Setup bash profile' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + + echo :$PATH: | grep -q -E ":$HOME/.local/bin:" || echo 'export PATH=$PATH:$HOME/.local/bin' >> $BASHRC && \ + sed -i '/export DOTNET_ROOT=\$HOME\/.dotnet/d' $BASHRC > /dev/null 2>&1 && \ + sed -i '/export PATH=\$PATH:\$HOME\/.dotnet/d' $BASHRC > /dev/null 2>&1 && \ + sed -i '/export DOTNET_CLI_TELEMETRY_OPTOUT=1/d' $BASHRC > /dev/null 2>&1 && \ + echo 'export DOTNET_ROOT=$HOME/.dotnet' >> $BASHRC && \ + echo 'export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools' >> $BASHRC && \ + echo 'export DOTNET_CLI_TELEMETRY_OPTOUT=1' >> $BASHRC + + [[ $? -gt 0 ]] && { error "$step_name failed, stopping now"; return 1; } + + source "$BASHRC" + + info "done" +} + +############################################################# +# 3 - INSTALL POWERSHELL +############################################################# +install_powershell() { + local step_name='STEP 3 Installing powershell' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + + dotnet tool install --global PowerShell + + [[ $? -gt 0 ]] && { error "$step_name failed, stopping now"; return 1; } + + info "done" +} + +############################################################# +# 4 - DOWNLOAD NETCOREDBG +############################################################# +download_netcoredbg() { + local step_name='STEP 4 Downloading netcoredbg' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + local archive=$INSTALL_DIR/netcoredbg.tar.gz + local target=$INSTALL_DIR + + wget --continue $LINK_DEBUGGER --output-document $archive && \ + mkdir -p $target && \ + tar zxf $archive -C $target && \ + rm $archive && \ + mkdir -p $HOME/.local/bin && \ + ln -s $target/netcoredbg/netcoredbg $HOME/.local/bin/netcoredbg + + [[ $? -gt 0 ]] && { error "$step_name failed, stopping now"; return 1; } + + info "done" +} + +############################################################# +# 5 - DOWNLOAD OMNISHARP +############################################################# +download_omnisharp() { + local step_name='STEP 5 Downloading Omnisharp' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + local archive=$INSTALL_DIR/omnisharp.tar.gz + local target=$INSTALL_DIR/omnisharp + + wget --continue $LINK_OMNI --output-document $archive && \ + mkdir -p $target && \ + tar zxf $archive -C $target && \ + rm $archive && \ + mkdir -p $HOME/.local/bin && \ + ln -s $target/OmniSharp $HOME/.local/bin/OmniSharp + + [[ $? -gt 0 ]] && { error "$step_name failed, stopping now"; return 1; } + + info "done" +} + +############################################################# +# 6 - INSTALL CSHARP-LS (OPTIONAL) +############################################################# +install_csharp_ls() { + local step_name='STEP 6 Installing csharp-ls' + warn "Press enter to proceed with $step_name"; read + info "$step_name" + + dotnet tool install --global csharp-ls + + [[ $? -gt 0 ]] && { error "$step_name failed, stopping now"; return 1; } + + info "done" +} + +############################################################# +# RUN SECTION +############################################################# +if [ $0 == $BASH_SOURCE ]; then + error "Do not run the script in a subshell via ./ Instead you should 'source' it!" + exit 1 +fi + +user=$(whoami) +if [ $user == root ]; then + error "You should NOT be using a root account" + return 1 +fi + +mkdir -p $INSTALL_DIR +mkdir -p $LOG_DIR + +echo $(date +'%Y-%m-%d %H:%M') > $LOG +info "$doc" + +download_sdk $LINK_SDK6 && \ + download_sdk $LINK_SDK8 && \ + setup_bash_profile && \ + install_powershell && \ + download_netcoredbg && \ + download_omnisharp && \ + #install_csharp_ls && \ + +dotnet --list-sdks + +info "Bye!" +info "PS. Log is here: ${LOG}" + +return 0