2015-10-20 23:21:03 +00:00
#!/bin/bash
#
2015-11-16 19:21:57 +00:00
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
2015-10-27 21:19:04 +00:00
# Usage: publish.sh [file to be uploaded]
2015-10-20 23:21:03 +00:00
#
# Environment Dependencies:
2015-10-27 21:19:04 +00:00
# $STORAGE_CONTAINER
2015-10-20 23:21:03 +00:00
# $STORAGE_ACCOUNT
2015-10-27 21:19:04 +00:00
# $SASTOKEN
2015-10-20 23:21:03 +00:00
# $REPO_ID
2015-10-29 17:33:39 +00:00
SOURCE = " ${ BASH_SOURCE [0] } "
while [ -h " $SOURCE " ] ; do # resolve $SOURCE until the file is no longer a symlink
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
SOURCE = " $( readlink " $SOURCE " ) "
2015-12-28 19:47:21 +00:00
[ [ " $SOURCE " != /* ] ] && SOURCE = " $DIR / $SOURCE " # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
2015-10-29 17:33:39 +00:00
done
2015-12-29 10:34:10 +00:00
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
source " $DIR /../common/_common.sh "
2015-10-29 17:33:39 +00:00
2015-12-29 10:34:10 +00:00
SCRIPT_DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2015-10-20 23:21:03 +00:00
2015-10-27 21:19:04 +00:00
UPLOAD_FILE = $1
2015-10-20 23:21:03 +00:00
UPLOAD_JSON_FILE = "package_upload.json"
2015-11-11 01:30:01 +00:00
header "Publishing package"
2015-10-29 17:33:39 +00:00
2015-10-20 23:21:03 +00:00
execute( ) {
2015-10-28 19:43:38 +00:00
if ! validate_env_variables; then
# fail silently if the required variables are not available for publishing the file.
2015-11-05 17:07:52 +00:00
exit 0
2015-10-28 19:43:38 +00:00
fi
if [ [ ! -f " $UPLOAD_FILE " ] ] ; then
2015-11-05 17:07:52 +00:00
error " \" $UPLOAD_FILE \" file does not exist "
2015-10-20 23:21:03 +00:00
exit 1
fi
2015-11-05 17:07:52 +00:00
if [ [ $UPLOAD_FILE = = *.deb || $UPLOAD_FILE = = *.pkg ] ] ; then
upload_installers_to_blob_storage $UPLOAD_FILE
result = $?
elif [ [ $UPLOAD_FILE = = *.tar.gz ] ] ; then
upload_binaries_to_blob_storage $UPLOAD_FILE
result = $?
2015-10-27 21:19:04 +00:00
fi
2015-11-05 17:07:52 +00:00
exit $result
2015-10-20 23:21:03 +00:00
}
2015-10-28 19:43:38 +00:00
validate_env_variables( ) {
2015-10-20 23:21:03 +00:00
local ret = 0
2015-10-28 19:43:38 +00:00
if [ [ -z " $DOTNET_BUILD_VERSION " ] ] ; then
2015-10-29 17:33:39 +00:00
warning "DOTNET_BUILD_VERSION environment variable not set"
2015-10-20 23:21:03 +00:00
ret = 1
fi
2015-10-28 19:43:38 +00:00
2015-10-27 21:19:04 +00:00
if [ [ -z " $SASTOKEN " ] ] ; then
2015-10-29 17:33:39 +00:00
warning "SASTOKEN environment variable not set"
2015-10-20 23:21:03 +00:00
ret = 1
fi
if [ [ -z " $STORAGE_ACCOUNT " ] ] ; then
2015-10-29 17:33:39 +00:00
warning "STORAGE_ACCOUNT environment variable not set"
2015-10-20 23:21:03 +00:00
ret = 1
fi
2015-10-27 21:19:04 +00:00
if [ [ -z " $STORAGE_CONTAINER " ] ] ; then
2015-10-29 17:33:39 +00:00
warning "STORAGE_CONTAINER environment variable not set"
2015-10-20 23:21:03 +00:00
ret = 1
fi
2015-11-06 22:40:05 +00:00
if [ [ -z " $CHANNEL " ] ] ; then
2015-11-05 17:07:52 +00:00
warning "CHANNEL environment variable not set"
2015-10-29 00:11:32 +00:00
ret = 1
fi
2015-11-06 22:40:05 +00:00
if [ [ -z " $CONNECTION_STRING " ] ] ; then
warning "CONNECTION_STRING environment variable not set"
ret = 1
fi
2015-10-20 23:21:03 +00:00
return $ret
}
2015-11-06 22:40:05 +00:00
upload_file_to_blob_storage_azure_cli( ) {
local blob = $1
2015-11-05 17:07:52 +00:00
local file = $2
2015-11-11 01:30:01 +00:00
header " Uploading $file to blob storage "
2015-10-27 21:19:04 +00:00
2015-11-06 22:40:05 +00:00
# use azure cli to upload to blob storage. We cannot use curl to do this becuase azure has a max limit of 64mb that can be uploaded using REST
# statusCode=$(curl -s -w "%{http_code}" -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" $upload_URL -T $file)
azure storage blob upload --quiet --container $STORAGE_CONTAINER --blob $blob --blobtype block --connection-string " $CONNECTION_STRING " --file $file
result = $?
2015-10-29 17:33:39 +00:00
2015-11-06 22:40:05 +00:00
if [ " $result " -eq "0" ] ; then
2015-11-05 17:07:52 +00:00
info " successfully uploaded $filename to blob storage. "
return 0
else
error " uploading the $filename to blob storage - $statusCode "
return 1
2015-10-27 21:19:04 +00:00
fi
2015-11-05 17:07:52 +00:00
}
2015-10-27 21:19:04 +00:00
2015-11-05 17:07:52 +00:00
update_file_in_blob_storage( ) {
local update_URL = $1
local file = $2
local filecontent = $3
2015-10-27 21:19:04 +00:00
2015-11-11 01:30:01 +00:00
header " Updating $file in blob storage "
2015-10-27 21:19:04 +00:00
2015-11-12 06:13:35 +00:00
statusCode = $( curl -s -w "%{http_code}" -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" -H "Content-Type: text/plain" $update_URL --data-binary $filecontent --request PUT )
2015-11-05 17:07:52 +00:00
if [ " $statusCode " -eq "201" ] ; then
info " successfully updated $file in blob storage. "
return 0
2015-10-27 21:19:04 +00:00
else
2015-11-05 17:07:52 +00:00
error " updating the $file in blob storage - $statusCode "
return 1
fi
}
upload_binaries_to_blob_storage( ) {
local tarfile = $1
local filename = $( basename $tarfile )
2015-11-06 22:40:05 +00:00
local blob = " $CHANNEL /Binaries/ $DOTNET_BUILD_VERSION / $filename "
2015-11-05 17:07:52 +00:00
2015-11-07 00:35:33 +00:00
if ! upload_file_to_blob_storage_azure_cli $blob $tarfile ; then
return 1
fi
# create the latest blob
echo "Updating the latest dotnet binaries.."
local latestblob = " $CHANNEL /Binaries/Latest/dotnet- $OSNAME -x64.latest.tar.gz "
if ! upload_file_to_blob_storage_azure_cli $latestblob $tarfile ; then
return 1
2015-11-05 17:07:52 +00:00
fi
2015-11-07 00:35:33 +00:00
# update the index file
local indexContent = " Binaries/ $DOTNET_BUILD_VERSION / $filename "
local indexfile = " latest. $OSNAME .index "
2015-11-11 21:37:55 +00:00
local index_URL = " https:// $STORAGE_ACCOUNT .blob.core.windows.net/ $STORAGE_CONTAINER / $CHANNEL /dnvm/ $indexfile $SASTOKEN "
update_file_in_blob_storage $index_URL $indexfile $indexContent
# update the version file
2015-11-12 05:54:58 +00:00
# the "@" prefix tells curl to upload the content of the file
local versionContent = " @ $REPOROOT /artifacts/ $RID /stage2/.version "
2015-11-11 21:37:55 +00:00
local versionfile = " latest. $OSNAME .version "
local version_URL = " https:// $STORAGE_ACCOUNT .blob.core.windows.net/ $STORAGE_CONTAINER / $CHANNEL /dnvm/ $versionfile $SASTOKEN "
update_file_in_blob_storage $version_URL $versionfile $versionContent
2015-11-07 00:35:33 +00:00
return $?
2015-11-05 17:07:52 +00:00
}
upload_installers_to_blob_storage( ) {
local installfile = $1
local filename = $( basename $installfile )
2015-11-06 22:40:05 +00:00
local blob = " $CHANNEL /Installers/ $DOTNET_BUILD_VERSION / $filename "
2015-11-05 17:07:52 +00:00
2015-11-06 22:40:05 +00:00
if ! upload_file_to_blob_storage_azure_cli $blob $installfile ; then
2015-11-05 17:07:52 +00:00
return 1
fi
2015-11-07 00:35:33 +00:00
# create the latest blob
echo "Updating the latest dotnet installer.."
local extension = " ${ filename ##*. } "
local latestblob = " $CHANNEL /Installers/Latest/dotnet- $OSNAME -x64.latest. $extension "
if ! upload_file_to_blob_storage_azure_cli $latestblob $installfile ; then
return 1
fi
2015-11-05 17:07:52 +00:00
# debain packages need to be uploaded to the PPA feed too
if [ [ $installfile = = *.deb ] ] ; then
DEB_FILE = $installfile
2015-11-11 01:28:46 +00:00
UPLOAD_URL = " https:// $STORAGE_ACCOUNT .blob.core.windows.net/ $STORAGE_CONTAINER / $blob "
2015-11-05 17:07:52 +00:00
generate_repoclient_json
call_repo_client
2015-10-27 21:19:04 +00:00
fi
2015-10-20 23:21:03 +00:00
2015-11-05 17:07:52 +00:00
return 0
2015-10-20 23:21:03 +00:00
}
generate_repoclient_json( ) {
# Clean any existing json file
rm -f $SCRIPT_DIR /$UPLOAD_JSON_FILE
echo "{" >> " $SCRIPT_DIR / $UPLOAD_JSON_FILE "
echo " \"name\":\" $( _get_package_name) \", " >> " $SCRIPT_DIR / $UPLOAD_JSON_FILE "
echo " \"version\":\" $( _get_package_version) \", " >> " $SCRIPT_DIR / $UPLOAD_JSON_FILE "
echo " \"repositoryId\":\" $REPO_ID \", " >> " $SCRIPT_DIR / $UPLOAD_JSON_FILE "
echo " \"sourceUrl\":\" $UPLOAD_URL \" " >> " $SCRIPT_DIR / $UPLOAD_JSON_FILE "
echo "}" >> " $SCRIPT_DIR / $UPLOAD_JSON_FILE "
}
call_repo_client( ) {
$SCRIPT_DIR /repoapi_client.sh -addpkg $SCRIPT_DIR /$UPLOAD_JSON_FILE
}
# Extract the package name from the .deb filename
_get_package_name( ) {
local deb_filename = $( basename $DEB_FILE )
local package_name = ${ deb_filename %%_* }
echo $package_name
}
# Extract the package version from the .deb filename
_get_package_version( ) {
local deb_filename = $( basename $DEB_FILE )
local package_version = ${ deb_filename #*_ }
package_version = ${ package_version %-* }
echo $package_version
}
2015-10-27 21:19:04 +00:00
execute