-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdotnet-sdk
More file actions
executable file
·133 lines (110 loc) · 3.05 KB
/
dotnet-sdk
File metadata and controls
executable file
·133 lines (110 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
dotnet_releases_url=https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json
function sdk_help(){
echo ".NET Command Line SDK Switcher (1.0.0)
Usage: dotnet sdk [command]
Usage: dotnet sdk [version]
Commands:
latest Swtiches to the latest .NET Core SDK version
list Lists all installed .NET Core SDKs
releases List all available releases of .NET Core SDKs
get Downloads the provided release version. ('' or 'latest' for the latest release)
help Display help
Versions:
An installed version number of a .NET Core SDK"
}
function sdk_list(){
echo "The installed .NET Core SDKs are:"
ls -1 /usr/share/dotnet/sdk | sort | head -n -1
}
function sdk_switch(){
if [ ! -d "/usr/local/share/dotnet/sdk/$v" ]; then
echo "The $v version of .Net Core SDK was not found
Please, run \"dotnet sdk list\" to make sure you have it installed in /usr/local/share/dotnet/sdk"
exit 1
fi
echo "Switching .NET Core SDK version to $v"
echo "{
\"sdk\": {
\"version\": \"$v\"
}
}" >> global.json
}
function sdk_latest(){
if [ -e global.json ]; then
rm global.json
fi
echo ".NET Core SDK version switched to latest version."
dotnet --version
}
function sdk_releases(){
check_pre
echo "Releases available for the .NET Core SDK are:"
VS=$(curl -sS $dotnet_releases_url -H "Accept: application/json" | jq "map({date: .date,sdk: .\"version-sdk\"}) | unique_by(.sdk) | .[] | \"\(.date)\t\(.sdk)\" " -r)
echo "$VS"
}
function sdk_install(){
check_pre
if [ -z "$ver" ] || [ "$ver" == "latest" ]; then
version=$(curl -sS $dotnet_releases_url -H "Accept: application/json" | jq "map({sdk: .\"version-sdk\"}) | unique_by(.sdk) | .[-1] | .sdk " -r)
else
version="$ver"
fi
url=$(curl -sS $dotnet_releases_url -H "Accept: application/json" | jq "map({sdk: .\"version-sdk\",url: (.\"blob-sdk\" + (.\"sdk-mac-x64\" | rtrimstr(\".tar.gz\")) + \".pkg\" )}) | unique_by(.sdk) | .[] | select(.sdk==\"$version\") | .url " -r)
filename=$(curl -sS $dotnet_releases_url -H "Accept: application/json" | jq "map({sdk: .\"version-sdk\",filename: (.\"sdk-mac-x64\" | rtrimstr(\".tar.gz\") + \".pkg\" )}) | unique_by(.sdk) | .[] | select(.sdk==\"$version\") | .filename " -r)
cd ~/Downloads
echo "Dowloading .NET Core SDK version $version for MacOS"
curl -# -L -O $url
sudo installer -pkg ~/Downloads/$filename -target /
}
function check_pre(){
if ! [ -f "`which jq`" ]; then
echo "Install ./jq and dependencies?"
read -p "Continue (y/n)?" choice
case "$choice" in
y|Y )
install_jq
;;
n|N )
exit 1
;;
* )
echo "invalid"
exit 1
;;
esac
fi
}
function install_jq(){
if [ ! -f "`which brew`" ]; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
else
brew update
fi
brew install jq
}
case "$1" in
"help")
sdk_help
;;
"")
sdk_help
;;
"list")
sdk_list
;;
"latest")
sdk_latest
;;
"releases")
sdk_releases
;;
"get")
ver=$2
sdk_install
;;
*)
v=$1
sdk_switch
;;
esac