2015-10-20 23:21:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
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
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
execute(){
|
|
|
|
if ! validate_inputs; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-10-27 21:19:04 +00:00
|
|
|
if ! upload_file_to_blob_storage; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# debain packages need to be uploaded to the PPA feed too
|
|
|
|
if [[ $UPLOAD_FILE == *.deb ]]; then
|
|
|
|
DEB_FILE=$UPLOAD_FILE
|
|
|
|
generate_repoclient_json
|
|
|
|
call_repo_client
|
|
|
|
fi
|
2015-10-20 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_inputs(){
|
|
|
|
local ret=0
|
2015-10-27 21:19:04 +00:00
|
|
|
if [[ ! -f "$UPLOAD_FILE" ]]; then
|
|
|
|
echo "Error: \"$UPLOAD_FILE\" file does not exist"
|
2015-10-20 23:21:03 +00:00
|
|
|
ret=1
|
|
|
|
fi
|
2015-10-27 21:19:04 +00:00
|
|
|
if [[ -z "$SASTOKEN" ]]; then
|
|
|
|
echo "Error: SASTOKEN environment variable not set"
|
2015-10-20 23:21:03 +00:00
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$STORAGE_ACCOUNT" ]]; then
|
|
|
|
echo "Error: STORAGE_ACCOUNT environment variable not set"
|
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
|
2015-10-27 21:19:04 +00:00
|
|
|
if [[ -z "$STORAGE_CONTAINER" ]]; then
|
|
|
|
echo "Error: STORAGE_CONTAINER environment variable not set"
|
2015-10-20 23:21:03 +00:00
|
|
|
ret=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2015-10-27 21:19:04 +00:00
|
|
|
upload_file_to_blob_storage(){
|
|
|
|
|
|
|
|
local filename=$(basename $UPLOAD_FILE)
|
|
|
|
|
|
|
|
if [[ $filename == *.deb || $filename == *.pkg ]]; then
|
|
|
|
FOLDER="Installers"
|
|
|
|
elif [[ $filename == *.tar.gz ]]; then
|
|
|
|
FOLDER="Binaries"
|
|
|
|
fi
|
|
|
|
|
|
|
|
UPLOAD_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$FOLDER/$DOTNET_BUILD_VERSION/$filename$SASTOKEN"
|
|
|
|
|
|
|
|
curl -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" $UPLOAD_URL -T $UPLOAD_FILE
|
|
|
|
result=$?
|
|
|
|
|
|
|
|
if [ "$result" -gt "0" ]; then
|
|
|
|
echo "Error: Uploading the $filename to blob storage - $result"
|
|
|
|
else
|
|
|
|
echo "Successfully uploaded $filename to blob storage."
|
|
|
|
fi
|
2015-10-20 23:21:03 +00:00
|
|
|
|
2015-10-27 21:19:04 +00:00
|
|
|
return $result
|
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
|