diff --git a/src/Misc/externals.sh b/src/Misc/externals.sh index 62ba9126a9..e4f7f10da8 100755 --- a/src/Misc/externals.sh +++ b/src/Misc/externals.sh @@ -12,8 +12,8 @@ get_abs_path() { echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" } -LAYOUT_DIR=$(get_abs_path `dirname $0`/../../_layout) -DOWNLOAD_DIR="$(get_abs_path `dirname $0`/../../_downloads)/netcore2x" +LAYOUT_DIR=$(get_abs_path "$(dirname $0)/../../_layout") +DOWNLOAD_DIR="$(get_abs_path "$(dirname $0)/../../_downloads")/netcore2x" function failed() { local error=${1:-Undefined error} @@ -41,8 +41,8 @@ function acquireExternalTool() { # Check if the download already exists. local download_target="$DOWNLOAD_DIR/$relative_url" - local download_basename="$(basename $download_target)" - local download_dir="$(dirname $download_target)" + local download_basename="$(basename "$download_target")" + local download_dir="$(dirname "$download_target")" if [[ "$PRECACHE" != "" ]]; then if [ -f "$download_target" ]; then @@ -57,7 +57,7 @@ function acquireExternalTool() { # Download from source to the partial file. echo "Downloading $download_source" - mkdir -p "$(dirname $download_target)" || checkRC 'mkdir' + mkdir -p "$(dirname "$download_target")" || checkRC 'mkdir' # curl -f Fail silently (no output at all) on HTTP errors (H) # -k Allow connections to SSL sites without certs (H) # -S Show error. With -s, make curl show errors when they occur diff --git a/src/dev.sh b/src/dev.sh index 2c09641cbd..a34966194c 100755 --- a/src/dev.sh +++ b/src/dev.sh @@ -6,6 +6,8 @@ # ############################################################################### +set -e + DEV_CMD=$1 DEV_CONFIG=$2 @@ -16,9 +18,9 @@ PACKAGE_DIR="$SCRIPT_DIR/../_package" DOTNETSDK_ROOT="$SCRIPT_DIR/../_dotnetsdk" DOTNETSDK_VERSION="2.1.403" DOTNETSDK_INSTALLDIR="$DOTNETSDK_ROOT/$DOTNETSDK_VERSION" -AGENT_VERSION=`cat agentversion` +AGENT_VERSION=$(cat agentversion) -pushd $SCRIPT_DIR +pushd "$SCRIPT_DIR" BUILD_CONFIG="Debug" if [[ "$DEV_CONFIG" == "Release" ]]; then @@ -26,8 +28,8 @@ if [[ "$DEV_CONFIG" == "Release" ]]; then fi CURRENT_PLATFORM="windows" -if [[ (`uname` == "Linux") || (`uname` == "Darwin") ]]; then - CURRENT_PLATFORM=`echo \`uname\` | awk '{print tolower($0)}'` +if [[ ($(uname) == "Linux") || ($(uname) == "Darwin") ]]; then + CURRENT_PLATFORM=$(uname | awk '{print tolower($0)}') fi if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then @@ -102,44 +104,34 @@ function heading() { echo echo - echo ----------------------------------------- - echo ${1} - echo ----------------------------------------- + echo "-----------------------------------------" + echo " ${1}" + echo "-----------------------------------------" } function build () { heading "Building ..." + dotnet msbuild -t:Build -p:PackageRuntime="${RUNTIME_ID}" -p:BUILDCONFIG="${BUILD_CONFIG}" -p:Version="${AGENT_VERSION}" || failed build - if [[ ("$CURRENT_PLATFORM" == "windows") ]]; then - dotnet msbuild //t:Build //p:PackageRuntime=${RUNTIME_ID} //p:BUILDCONFIG=${BUILD_CONFIG} //p:Version=${AGENT_VERSION} || failed build - else - dotnet msbuild /t:Build /p:PackageRuntime=${RUNTIME_ID} /p:BUILDCONFIG=${BUILD_CONFIG} /p:Version=${AGENT_VERSION} || failed build - fi - - mkdir -p ${LAYOUT_DIR}/bin/en-US - grep --invert-match '^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > ${LAYOUT_DIR}/bin/en-US/strings.json + mkdir -p "${LAYOUT_DIR}/bin/en-US" + grep --invert-match '^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > "${LAYOUT_DIR}/bin/en-US/strings.json" } function layout () { heading "Create layout ..." + dotnet msbuild -t:layout -p:PackageRuntime="${RUNTIME_ID}" -p:BUILDCONFIG="${BUILD_CONFIG}" -p:Version="${AGENT_VERSION}" || failed build - if [[ ("$CURRENT_PLATFORM" == "windows") ]]; then - dotnet msbuild //t:layout //p:PackageRuntime=${RUNTIME_ID} //p:BUILDCONFIG=${BUILD_CONFIG} //p:Version=${AGENT_VERSION} || failed build - else - dotnet msbuild /t:layout /p:PackageRuntime=${RUNTIME_ID} /p:BUILDCONFIG=${BUILD_CONFIG} /p:Version=${AGENT_VERSION} || failed build - fi - - mkdir -p ${LAYOUT_DIR}/bin/en-US - grep --invert-match '^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > ${LAYOUT_DIR}/bin/en-US/strings.json + mkdir -p "${LAYOUT_DIR}/bin/en-US" + grep --invert-match '^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > "${LAYOUT_DIR}/bin/en-US/strings.json" #change execution flag to allow running with sudo if [[ ("$CURRENT_PLATFORM" == "linux") || ("$CURRENT_PLATFORM" == "darwin") ]]; then - chmod +x ${LAYOUT_DIR}/bin/Agent.Listener - chmod +x ${LAYOUT_DIR}/bin/Agent.Worker - chmod +x ${LAYOUT_DIR}/bin/Agent.PluginHost - chmod +x ${LAYOUT_DIR}/bin/installdependencies.sh + chmod +x "${LAYOUT_DIR}/bin/Agent.Listener" + chmod +x "${LAYOUT_DIR}/bin/Agent.Worker" + chmod +x "${LAYOUT_DIR}/bin/Agent.PluginHost" + chmod +x "${LAYOUT_DIR}/bin/installdependencies.sh" fi heading "Setup externals folder for $RUNTIME_ID agent's layout" @@ -156,11 +148,7 @@ function runtest () export VSTS_AGENT_SRC_DIR=${SCRIPT_DIR} - if [[ ("$CURRENT_PLATFORM" == "windows") ]]; then - dotnet msbuild //t:test //p:PackageRuntime=${RUNTIME_ID} //p:BUILDCONFIG=${BUILD_CONFIG} //p:Version=${AGENT_VERSION} || failed "failed tests" - else - dotnet msbuild /t:test /p:PackageRuntime=${RUNTIME_ID} /p:BUILDCONFIG=${BUILD_CONFIG} /p:Version=${AGENT_VERSION} || failed "failed tests" - fi + dotnet msbuild -t:test -p:PackageRuntime="${RUNTIME_ID}" -p:BUILDCONFIG="${BUILD_CONFIG}" -p:Version="${AGENT_VERSION}" || failed "failed tests" } function package () @@ -169,21 +157,23 @@ function package () echo "You must build first. Expecting to find ${LAYOUT_DIR}/bin" fi - agent_ver=`${LAYOUT_DIR}/bin/Agent.Listener --version` || failed "version" + agent_ver=$("${LAYOUT_DIR}/bin/Agent.Listener" --version) || failed "version" agent_pkg_name="vsts-agent-${RUNTIME_ID}-${agent_ver}" heading "Packaging ${agent_pkg_name}" - rm -Rf ${LAYOUT_DIR}/_diag - find ${LAYOUT_DIR}/bin -type f -name '*.pdb' -delete - mkdir -p $PACKAGE_DIR - pushd $PACKAGE_DIR > /dev/null - rm -Rf * + rm -Rf "${LAYOUT_DIR:?}/_diag" + find "${LAYOUT_DIR}/bin" -type f -name '*.pdb' -delete + + mkdir -p "$PACKAGE_DIR" + rm -Rf "${PACKAGE_DIR:?}/*" + + pushd "$PACKAGE_DIR" > /dev/null if [[ ("$CURRENT_PLATFORM" == "linux") || ("$CURRENT_PLATFORM" == "darwin") ]]; then tar_name="${agent_pkg_name}.tar.gz" echo "Creating $tar_name in ${LAYOUT_DIR}" - tar -czf "${tar_name}" -C ${LAYOUT_DIR} . + tar -czf "${tar_name}" -C "${LAYOUT_DIR}" . elif [[ ("$CURRENT_PLATFORM" == "windows") ]]; then zip_name="${agent_pkg_name}.zip" echo "Convert ${LAYOUT_DIR} to Windows style path" @@ -206,19 +196,19 @@ if [[ (! -d "${DOTNETSDK_INSTALLDIR}") || (! -e "${DOTNETSDK_INSTALLDIR}/.${DOTN # \dotnet # \.1.0.x echo "Download dotnetsdk into ${DOTNETSDK_INSTALLDIR}" - rm -Rf ${DOTNETSDK_DIR} + rm -Rf "${DOTNETSDK_DIR}" # run dotnet-install.ps1 on windows, dotnet-install.sh on linux if [[ ("$CURRENT_PLATFORM" == "windows") ]]; then echo "Convert ${DOTNETSDK_INSTALLDIR} to Windows style path" sdkinstallwindow_path=${DOTNETSDK_INSTALLDIR:1} sdkinstallwindow_path=${sdkinstallwindow_path:0:1}:${sdkinstallwindow_path:1} - powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& \"./Misc/dotnet-install.ps1\" -Version ${DOTNETSDK_VERSION} -InstallDir \"${sdkinstallwindow_path}\" -NoPath; exit $LastExitCode;" || checkRC dotnet-install.ps1 + powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& \"./Misc/dotnet-install.ps1\" -Version ${DOTNETSDK_VERSION} -InstallDir \"${sdkinstallwindow_path}\" -NoPath; exit \$LastExitCode;" || checkRC dotnet-install.ps1 else - bash ./Misc/dotnet-install.sh --version ${DOTNETSDK_VERSION} --install-dir ${DOTNETSDK_INSTALLDIR} --no-path || checkRC dotnet-install.sh + bash ./Misc/dotnet-install.sh --version ${DOTNETSDK_VERSION} --install-dir "${DOTNETSDK_INSTALLDIR}" --no-path || checkRC dotnet-install.sh fi - echo "${DOTNETSDK_VERSION}" > ${DOTNETSDK_INSTALLDIR}/.${DOTNETSDK_VERSION} + echo "${DOTNETSDK_VERSION}" > "${DOTNETSDK_INSTALLDIR}/.${DOTNETSDK_VERSION}" fi echo "Prepend ${DOTNETSDK_INSTALLDIR} to %PATH%" @@ -231,8 +221,8 @@ heading "Pre-cache external resources for $RUNTIME_ID package ..." bash ./Misc/externals.sh $RUNTIME_ID "Pre-Cache" || checkRC "externals.sh Pre-Cache" if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then - vswhere=`find $DOWNLOAD_DIR -name vswhere.exe | head -1` - vs_location=`$vswhere -latest -property installationPath` + vswhere=$(find "$DOWNLOAD_DIR" -name vswhere.exe | head -1) + vs_location=$("$vswhere" -latest -property installationPath) msbuild_location="$vs_location""\MSBuild\15.0\Bin\msbuild.exe" if [[ ! -e "${msbuild_location}" ]]; then