Skip to content

Commit 0599c63

Browse files
samruddhikhandalegithub-actions
andauthored
[Updates] Automated vendor dotnet-install script (#698)
* Automated dotnet-install script update * version bump --------- Co-authored-by: github-actions <[email protected]>
1 parent 3aad9a7 commit 0599c63

File tree

2 files changed

+90
-6
lines changed

2 files changed

+90
-6
lines changed

src/dotnet/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "dotnet",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"name": "Dotnet CLI",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnet",
66
"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.",

src/dotnet/scripts/vendor/dotnet-install.sh

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ get_machine_architecture() {
314314
echo "ppc64le"
315315
return 0
316316
;;
317+
loongarch64)
318+
echo "loongarch64"
319+
return 0
320+
;;
317321
esac
318322
fi
319323

@@ -355,6 +359,10 @@ get_normalized_architecture_from_architecture() {
355359
echo "ppc64le"
356360
return 0
357361
;;
362+
loongarch64)
363+
echo "loongarch64"
364+
return 0
365+
;;
358366
esac
359367

360368
say_err "Architecture \`$architecture\` not supported. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues"
@@ -546,6 +554,40 @@ is_dotnet_package_installed() {
546554
fi
547555
}
548556

557+
# args:
558+
# downloaded file - $1
559+
# remote_file_size - $2
560+
validate_remote_local_file_sizes()
561+
{
562+
eval $invocation
563+
564+
local downloaded_file="$1"
565+
local remote_file_size="$2"
566+
local file_size=''
567+
568+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
569+
file_size="$(stat -c '%s' "$downloaded_file")"
570+
elif [[ "$OSTYPE" == "darwin"* ]]; then
571+
# hardcode in order to avoid conflicts with GNU stat
572+
file_size="$(/usr/bin/stat -f '%z' "$downloaded_file")"
573+
fi
574+
575+
if [ -n "$file_size" ]; then
576+
say "Downloaded file size is $file_size bytes."
577+
578+
if [ -n "$remote_file_size" ] && [ -n "$file_size" ]; then
579+
if [ "$remote_file_size" -ne "$file_size" ]; then
580+
say "The remote and local file sizes are not equal. The remote file size is $remote_file_size bytes and the local size is $file_size bytes. The local package may be corrupted."
581+
else
582+
say "The remote and local file sizes are equal."
583+
fi
584+
fi
585+
586+
else
587+
say "Either downloaded or local package size can not be measured. One of them may be corrupted."
588+
fi
589+
}
590+
549591
# args:
550592
# azure_feed - $1
551593
# channel - $2
@@ -914,14 +956,39 @@ copy_files_or_dirs_from_list() {
914956
done
915957
}
916958
959+
# args:
960+
# zip_uri - $1
961+
get_remote_file_size() {
962+
local zip_uri="$1"
963+
964+
if machine_has "curl"; then
965+
file_size=$(curl -sI "$zip_uri" | grep -i content-length | awk '{ num = $2 + 0; print num }')
966+
elif machine_has "wget"; then
967+
file_size=$(wget --spider --server-response -O /dev/null "$zip_uri" 2>&1 | grep -i 'Content-Length:' | awk '{ num = $2 + 0; print num }')
968+
else
969+
say "Neither curl nor wget is available on this system."
970+
return
971+
fi
972+
973+
if [ -n "$file_size" ]; then
974+
say "Remote file $zip_uri size is $file_size bytes."
975+
echo "$file_size"
976+
else
977+
say_verbose "Content-Length header was not extracted for $zip_uri."
978+
echo ""
979+
fi
980+
}
981+
917982
# args:
918983
# zip_path - $1
919984
# out_path - $2
985+
# remote_file_size - $3
920986
extract_dotnet_package() {
921987
eval $invocation
922988
923989
local zip_path="$1"
924990
local out_path="$2"
991+
local remote_file_size="$3"
925992
926993
local temp_out_path="$(mktemp -d "$temporary_file_template")"
927994
@@ -931,9 +998,13 @@ extract_dotnet_package() {
931998
local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/'
932999
find "$temp_out_path" -type f | grep -Eo "$folders_with_version_regex" | sort | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" false
9331000
find "$temp_out_path" -type f | grep -Ev "$folders_with_version_regex" | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" "$override_non_versioned_files"
934-
1001+
1002+
validate_remote_local_file_sizes "$zip_path" "$remote_file_size"
1003+
9351004
rm -rf "$temp_out_path"
936-
rm -f "$zip_path" && say_verbose "Temporary zip file $zip_path was removed"
1005+
if [ -z ${keep_zip+x} ]; then
1006+
rm -f "$zip_path" && say_verbose "Temporary zip file $zip_path was removed"
1007+
fi
9371008
9381009
if [ "$failed" = true ]; then
9391010
say_err "Extraction failed"
@@ -1427,9 +1498,10 @@ install_dotnet() {
14271498
eval $invocation
14281499
local download_failed=false
14291500
local download_completed=false
1501+
local remote_file_size=0
14301502
14311503
mkdir -p "$install_root"
1432-
zip_path="$(mktemp "$temporary_file_template")"
1504+
zip_path="${zip_path:-$(mktemp "$temporary_file_template")}"
14331505
say_verbose "Zip path: $zip_path"
14341506
14351507
for link_index in "${!download_links[@]}"
@@ -1467,8 +1539,10 @@ install_dotnet() {
14671539
return 1
14681540
fi
14691541
1542+
remote_file_size="$(get_remote_file_size "$download_link")"
1543+
14701544
say "Extracting zip from $download_link"
1471-
extract_dotnet_package "$zip_path" "$install_root" || return 1
1545+
extract_dotnet_package "$zip_path" "$install_root" "$remote_file_size" || return 1
14721546
14731547
# Check if the SDK version is installed; if not, fail the installation.
14741548
# if the version contains "RTM" or "servicing"; check if a 'release-type' SDK version is installed.
@@ -1618,6 +1692,14 @@ do
16181692
override_non_versioned_files=false
16191693
non_dynamic_parameters+=" $name"
16201694
;;
1695+
--keep-zip|-[Kk]eep[Zz]ip)
1696+
keep_zip=true
1697+
non_dynamic_parameters+=" $name"
1698+
;;
1699+
--zip-path|-[Zz]ip[Pp]ath)
1700+
shift
1701+
zip_path="$1"
1702+
;;
16211703
-?|--?|-h|--help|-[Hh]elp)
16221704
script_name="$(basename "$0")"
16231705
echo ".NET Tools Installer"
@@ -1663,7 +1745,7 @@ do
16631745
echo " -InstallDir"
16641746
echo " --architecture <ARCHITECTURE> Architecture of dotnet binaries to be installed, Defaults to \`$architecture\`."
16651747
echo " --arch,-Architecture,-Arch"
1666-
echo " Possible values: x64, arm, arm64, s390x and ppc64le"
1748+
echo " Possible values: x64, arm, arm64, s390x, ppc64le and loongarch64"
16671749
echo " --os <system> Specifies operating system to be used when selecting the installer."
16681750
echo " Overrides the OS determination approach used by the script. Supported values: osx, linux, linux-musl, freebsd, rhel.6."
16691751
echo " In case any other value is provided, the platform will be determined by the script based on machine configuration."
@@ -1688,6 +1770,8 @@ do
16881770
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
16891771
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
16901772
echo " Note: global.json must have a value for 'SDK:Version'"
1773+
echo " --keep-zip,-KeepZip If set, downloaded file is kept."
1774+
echo " --zip-path, -ZipPath If set, downloaded file is stored at the specified path."
16911775
echo " -?,--?,-h,--help,-Help Shows this help message"
16921776
echo ""
16931777
echo "Install Location:"

0 commit comments

Comments
 (0)