github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/build/publish_deb_to_bintray.sh (about)

     1  #!/bin/sh
     2  set -e
     3  
     4  if [ -z "$REPO" ]; then
     5    REPO="gauge-deb"
     6  fi
     7  
     8  if [ -z "$PACKAGE" ]; then
     9      PACKAGE="gauge"
    10  fi
    11  
    12  if [ -z "$DISTRIBUTIONS" ]; then
    13    DISTRIBUTIONS="stable"
    14  fi
    15  
    16  if [ -z "$COMPONENTS" ]; then
    17    COMPONENTS="main"
    18  fi
    19  
    20  if [ -z "$USER" ]; then
    21    echo "USER is not set"
    22    exit 1
    23  fi
    24  
    25  if [ -z "$API_KEY" ]; then
    26    echo "API_KEY is not set"
    27    exit 1
    28  fi
    29  
    30  
    31  PACKAGE_FILE_PREFIX=$(echo "$PACKAGE" | tr '[:upper:]' '[:lower:]');
    32  
    33  setVersion () {
    34      VERSION=$(ls $PACKAGE_FILE_PREFIX*.deb | head -1 | sed "s/\.[^\.]*$//" | sed "s/$PACKAGE_FILE_PREFIX-//" | sed "s/-[a-z]*\.[a-z0-9_]*$//" | rev | sed "s/^[a-z0-9]*-//" | rev);
    35  }
    36  
    37  getArchFromFileName () {
    38      ARCH=$(echo $1 | sed "s/$PACKAGE_FILE_PREFIX-//" | rev | cut -d '-' -f 1 | rev | cut -d '.' -f 1);
    39      echo $ARCH
    40  }
    41  
    42  setUploadDirPath () {
    43      UPLOADDIRPATH="pool/$COMPONENTS/$(echo $PACKAGE | head -c1)"
    44  }
    45  
    46  bintrayUpload () {
    47      for i in `ls $PACKAGE_FILE_PREFIX*.deb`; do
    48  		ARCH=$( getArchFromFileName $i )
    49          URL="https://api.bintray.com/content/gauge/$REPO/$PACKAGE/$VERSION/$UPLOADDIRPATH/$i;deb_distribution=$DISTRIBUTIONS;deb_component=$COMPONENTS;deb_architecture=$ARCH?publish=1&override=1"
    50  
    51          echo "Uploading:"
    52          echo "\tversion: $VERSION"
    53          echo "\tarch: $ARCH"
    54          echo "\tURL: $URL"
    55  
    56          RESPONSE_CODE=$(curl -T $i -u$USER:$API_KEY $URL -I -s -w "%{http_code}" -o /dev/null);
    57          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    58              echo "Unable to upload, HTTP response code: $RESPONSE_CODE"
    59              exit 1
    60          fi
    61          echo "HTTP response code: $RESPONSE_CODE"
    62      done;
    63  }
    64  
    65  bintraySetDownloads () {
    66      for i in `ls *.deb`; do
    67          ARCH=$( getArchFromFileName $i )
    68          URL="https://api.bintray.com/file_metadata/gauge/$REPO/$UPLOADDIRPATH/$i"
    69  
    70          echo "Putting $i in $PACKAGE's download list"
    71          RESPONSE_CODE=$(curl -X PUT -d "{ \"list_in_downloads\": true }" -H "Content-Type: application/json" -u$USER:$API_KEY $URL -s -w "%{http_code}" -o /dev/null);
    72  
    73          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    74              echo "Unable to put in download list, HTTP response code: $RESPONSE_CODE"
    75              exit 1
    76          fi
    77          echo "HTTP response code: $RESPONSE_CODE"
    78      done
    79  }
    80  
    81  snooze () {
    82      echo "\nSleeping for 30 seconds. Have a coffee..."
    83      sleep 30s;
    84      echo "Done sleeping\n"
    85  }
    86  
    87  printMeta () {
    88      echo "Publishing deb: $PACKAGE"
    89      echo "Version to be uploaded: $VERSION"
    90  }
    91  
    92  setVersion
    93  printMeta
    94  setUploadDirPath
    95  bintrayUpload
    96  snooze
    97  bintraySetDownloads