github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/build/publish_deb_to_bintray.sh (about)

     1  #!/bin/sh
     2  
     3  # Copyright 2015 ThoughtWorks, Inc.
     4  
     5  # This file is part of Gauge.
     6  
     7  # Gauge is free software: you can redistribute it and/or modify
     8  # it under the terms of the GNU General Public License as published by
     9  # the Free Software Foundation, either version 3 of the License, or
    10  # (at your option) any later version.
    11  
    12  # Gauge is distributed in the hope that it will be useful,
    13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  # GNU General Public License for more details.
    16  
    17  # You should have received a copy of the GNU General Public License
    18  # along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    19  
    20  set -e
    21  
    22  if [ -z "$REPO" ]; then
    23    REPO="gauge-deb"
    24  fi
    25  
    26  if [ -z "$PACKAGE" ]; then
    27      PACKAGE="gauge"
    28  fi
    29  
    30  if [ -z "$DISTRIBUTIONS" ]; then
    31    DISTRIBUTIONS="stable"
    32  fi
    33  
    34  if [ -z "$COMPONENTS" ]; then
    35    COMPONENTS="main"
    36  fi
    37  
    38  if [ -z "$USER" ]; then
    39    echo "USER is not set"
    40    exit 1
    41  fi
    42  
    43  if [ -z "$API_KEY" ]; then
    44    echo "API_KEY is not set"
    45    exit 1
    46  fi
    47  
    48  if [ -z "$PASSPHRASE" ]; then
    49    echo "PASSPHRASE is not set"
    50    exit 1
    51  fi
    52  
    53  PACKAGE_FILE_PREFIX=$(echo "$PACKAGE" | tr '[:upper:]' '[:lower:]');
    54  
    55  setVersion () {
    56      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);
    57  }
    58  
    59  getArchFromFileName () {
    60      ARCH=$(echo $1 | sed "s/$PACKAGE_FILE_PREFIX-//" | rev | cut -d '-' -f 1 | rev | cut -d '.' -f 1);
    61      echo $ARCH
    62  }
    63  
    64  setUploadDirPath () {
    65      UPLOADDIRPATH="pool/$COMPONENTS/$(echo $PACKAGE | head -c1)"
    66  }
    67  
    68  bintrayUpload () {
    69      for i in `ls $PACKAGE_FILE_PREFIX*.deb`; do
    70  		ARCH=$( getArchFromFileName $i )
    71          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"
    72  
    73          echo "Uploading:"
    74          echo "\tversion: $VERSION"
    75          echo "\tarch: $ARCH"
    76          echo "\tURL: $URL"
    77  
    78          RESPONSE_CODE=$(curl -H "X-GPG-PASSPHRASE: $PASSPHRASE" -T $i -u$USER:$API_KEY $URL -I -s -w "%{http_code}" -o /dev/null);
    79          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    80              echo "Unable to upload, HTTP response code: $RESPONSE_CODE"
    81              exit 1
    82          fi
    83          echo "HTTP response code: $RESPONSE_CODE"
    84      done;
    85  }
    86  
    87  bintraySetDownloads () {
    88      for i in `ls *.deb`; do
    89          ARCH=$( getArchFromFileName $i )
    90          URL="https://api.bintray.com/file_metadata/gauge/$REPO/$UPLOADDIRPATH/$i"
    91  
    92          echo "Putting $i in $PACKAGE's download list"
    93          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);
    94  
    95          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    96              echo "Unable to put in download list, HTTP response code: $RESPONSE_CODE"
    97              exit 1
    98          fi
    99          echo "HTTP response code: $RESPONSE_CODE"
   100      done
   101  }
   102  
   103  snooze () {
   104      echo "\nSleeping for 30 seconds. Have a coffee..."
   105      sleep 30s;
   106      echo "Done sleeping\n"
   107  }
   108  
   109  printMeta () {
   110      echo "Publishing deb: $PACKAGE"
   111      echo "Version to be uploaded: $VERSION"
   112  }
   113  
   114  setVersion
   115  printMeta
   116  setUploadDirPath
   117  bintrayUpload
   118  snooze
   119  bintraySetDownloads