#!/bin/bash # Usage: # build-dotnet-tarball [--bootstrap] # # Creates a source archive from a tag (or commit) at github.com/dotnet/installer # installer is a little strange, we need to clone it, check out the # tag, build it and then create a tarball from the archive directory # it creates. Also, it is likely that the source archive is only # buildable on the OS it was initially created in. set -euo pipefail IFS=$'\n\t' function print_usage { echo "Usage:" echo "$0 [--bootstrap] " echo echo "Creates a source archive from a tag at https://github.com/dotnet/installer" echo "" echo " --bootstrap build a source tarball usable for bootstrapping .NET" } function clean_dotnet_cache { rm -rf ~/.aspnet ~/.dotnet/ ~/.nuget/ ~/.local/share/NuGet ~/.templateengine rm -rf /tmp/NuGet /tmp/NuGetScratch /tmp/.NETCore* /tmp/.NETStandard* /tmp/.dotnet /tmp/dotnet.* /tmp/clr-debug-pipe* /tmp/Razor-Server /tmp/CoreFxPipe* /tmp/VBCSCompiler /tmp/.NETFramework* } function check_bootstrap_environment { if rpm -qa | grep dotnet ; then echo "error: dotnet is installed. Not a good idea for bootstrapping." exit 1 fi if [ -d /usr/lib/dotnet ] || [ -d /usr/lib64/dotnet ] || [ -d /usr/share/dotnet ] ; then echo "error: one of /usr/lib/dotnet /usr/lib64/dotnet or /usr/share/dotnet/ exists. Not a good idea for bootstrapping." exit 1 fi if command -v dotnet ; then echo "error: dotnet is in $PATH. Not a good idea for bootstrapping." exit 1 fi } function runtime_id { source /etc/os-release case "${ID}" in # Remove the RHEL minor version rhel) rid_version=${VERSION_ID%.*} ;; *) rid_version=${VERSION_ID} ;; esac echo "${ID}.${rid_version}-${arch}" } build_bootstrap=false declare -A archmap archmap=( ["aarch64"]="arm64" ["amd64"]="x64" ["armv8l"]="arm" ["i686"]="x86" ["i386"]="x86" ["x86_64"]="x64" ) arch=${archmap["$(uname -m)"]} positional_args=() while [[ "$#" -gt 0 ]]; do arg="${1}" case "${arg}" in --bootstrap) check_bootstrap_environment build_bootstrap=true shift ;; -h|--help) print_usage exit 0 ;; *) positional_args+=("$1") shift ;; esac done tag=${positional_args[0]:-} if [[ -z ${tag} ]]; then echo "error: missing tag to build" exit 1 fi set -x dir_name="dotnet-${tag}" unmodified_tarball_name="${dir_name}-original" tarball_name="${dir_name}" tarball_suffix=.tar.gz if [[ ${build_bootstrap} == true ]]; then unmodified_tarball_name="${unmodified_tarball_name}-${arch}-bootstrap" tarball_name="${tarball_name}-${arch}-bootstrap" tarball_suffix=.tar.xz fi if [ -f "${tarball_name}${tarball_suffix}" ]; then echo "error: ${tarball_name}${tarball_suffix} already exists" exit 1 fi if [ ! -f "${unmodified_tarball_name}.tar.gz" ]; then temp_dir=$(mktemp -d -p "$(pwd)") pushd "${temp_dir}" git clone https://github.com/dotnet/installer pushd installer git checkout "${tag}" git submodule update --init --recursive patch -p1 -i ../../installer-12736-no-sudo.patch patch -p1 -i ../../installer-12852-fix-internal-urls.patch clean_dotnet_cache mkdir -p "../${unmodified_tarball_name}" ./build.sh /p:ArcadeBuildTarball=true /p:TarballDir="$(readlink -f ../"${unmodified_tarball_name}")" popd popd tar cf "${unmodified_tarball_name}.tar.gz" -C "${temp_dir}" "${unmodified_tarball_name}" rm -rf "${temp_dir}" fi rm -rf "${tarball_name}" tar xf "${unmodified_tarball_name}.tar.gz" mv "${unmodified_tarball_name}" "${tarball_name}" pushd "${tarball_name}" if [[ ${build_bootstrap} == true ]]; then if [[ "$(wc -l < packages/archive/archiveArtifacts.txt)" != 1 ]]; then echo "error: this is not going to work! update $0 to fix this issue." exit 1 fi pushd packages/archive/ curl -O $(cat archiveArtifacts.txt) popd mkdir foo pushd foo tar xf ../packages/archive/Private.SourceBuilt.Artifacts.*.tar.gz sed -i -E 's|6.0.0-rtm.21521.16.0.0-rtm.21521.46.0.0-rtm.21521.16.0.0-rtm.21521.4