<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <SdkInstallerFileItemGroup Include="$(SdkInstallerFile)" />
  </ItemGroup>

  <PropertyGroup>
    <SdkDebianUploadUrl>$(DotnetBlobRootUrl)/$(Product)/$(FullNugetVersion)/%(SdkInstallerFileItemGroup.Filename)%(SdkInstallerFileItemGroup.Extension)</SdkDebianUploadUrl>
    <DebianUploadJsonFile>$(SdkDebianIntermediateDirectory)/package_upload.json</DebianUploadJsonFile>
    <DebianRevisionNumber>1</DebianRevisionNumber>

    <DebianUploadJsonContent>
      {
      "name":"$(SdkDebianPackageName)",
      "version":"$(NugetVersion)-$(DebianRevisionNumber)",
      "repositoryId":"$(REPO_ID)",
      "sourceUrl": "$(SdkDebianUploadUrl)"
      }
    </DebianUploadJsonContent>
  </PropertyGroup>

  <Target Name="PublishDebFilesToDebianRepo" Condition=" '$(OSName)' == 'ubuntu' AND '$(SkipPublishToDebianRepo)' != 'true' ">
    <Error Condition="'$(REPO_ID)' == ''" Text="REPO_ID must be set as an environment variable for debian publishing." />
    <Error Condition="'$(REPO_USER)' == ''" Text="REPO_USER must be set as an environment variable for debian publishing." />
    <Error Condition="'$(REPO_PASS)' == ''" Text="REPO_PASS must be set as an environment variable for debian publishing." />
    <Error Condition="'$(REPO_SERVER)' == ''" Text="REPO_SERVER must be set as an environment variable for debian publishing." />

    <Delete Files="$(DebianUploadJsonFile)" />
    <WriteLinesToFile File="$(DebianUploadJsonFile)" Lines="$(DebianUploadJsonContent)" />

    <Exec Command="$(RepoRoot)/scripts/publish/repoapi_client.sh -addpkg $(DebianUploadJsonFile)" />
  </Target>
</Project>
