github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/build/publish_rpm_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-rpm"
    24  fi
    25  
    26  if [ -z "$PACKAGE" ]; then
    27      PACKAGE="gauge"
    28  fi
    29  
    30  if [ -z "$BINTRAY_PACKAGE" ]; then
    31      PACKAGE="gauge-nightly"
    32  fi
    33  
    34  if [ -z "$USER" ]; then
    35    echo "USER is not set"
    36    exit 1
    37  fi
    38  
    39  if [ -z "$API_KEY" ]; then
    40    echo "API_KEY is not set"
    41    exit 1
    42  fi
    43  
    44  if [ -z "$PASSPHRASE" ]; then
    45    echo "PASSPHRASE is not set"
    46    exit 1
    47  fi
    48  
    49  
    50  PACKAGE_FILE_PREFIX=$(echo "$PACKAGE" | tr '[:upper:]' '[:lower:]');
    51  
    52  setVersion () {
    53      VERSION=$(ls $PACKAGE_FILE_PREFIX*.rpm | head -1 | sed "s/\.[^\.]*$//" | sed "s/$PACKAGE_FILE_PREFIX-//" | sed "s/-[a-z]*\.[a-z0-9_]*$//" | rev | sed "s/^[a-z0-9]*-//" | rev);
    54  }
    55  
    56  getArchFromFileName () {
    57      ARCH=$(echo $1 | sed "s/$PACKAGE_FILE_PREFIX-//" | rev | cut -d '-' -f 1 | rev | cut -d '.' -f 1);
    58      echo $ARCH
    59  }
    60  
    61  setUploadDirPath () {
    62      UPLOADDIRPATH="$BINTRAY_PACKAGE/$PACKAGE/$VERSION"
    63  }
    64  
    65  bintrayUpload () {
    66      for i in `ls $PACKAGE_FILE_PREFIX*.rpm`; do
    67  		ARCH=$( getArchFromFileName $i )
    68          URL="https://api.bintray.com/content/gauge/$REPO/$BINTRAY_PACKAGE/$VERSION/$UPLOADDIRPATH/$i?publish=1&override=1"
    69  
    70          echo "Uploading:"
    71          echo "\tversion: $VERSION"
    72          echo "\tarch: $ARCH"
    73          echo "\tURL: $URL"
    74  
    75          RESPONSE_CODE=$(curl -H "X-GPG-PASSPHRASE: $PASSPHRASE" -T $i -u$USER:$API_KEY "$URL" -I -s -w "%{http_code}" -o /dev/null);
    76          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    77              echo "Unable to upload, HTTP response code: $RESPONSE_CODE"
    78              exit 1
    79          fi
    80          echo "HTTP response code: $RESPONSE_CODE"
    81      done;
    82  }
    83  
    84  bintraySetDownloads () {
    85      for i in `ls *.rpm`; do
    86          ARCH=$( getArchFromFileName $i )
    87          URL="https://api.bintray.com/file_metadata/gauge/$REPO/$UPLOADDIRPATH/$i"
    88  
    89          echo "Putting $i in $PACKAGE's download list"
    90          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);
    91  
    92          if [ "$(echo $RESPONSE_CODE | head -c2)" != "20" ]; then
    93              echo "Unable to put in download list, HTTP response code: $RESPONSE_CODE"
    94              exit 1
    95          fi
    96          echo "HTTP response code: $RESPONSE_CODE"
    97      done
    98  }
    99  
   100  snooze () {
   101      echo "\nSleeping for 30 seconds. Have a coffee..."
   102      sleep 30s;
   103      echo "Done sleeping\n"
   104  }
   105  
   106  printMeta () {
   107      echo "Publishing rpm: $PACKAGE"
   108      echo "Version to be uploaded: $VERSION"
   109  }
   110  
   111  setVersion
   112  printMeta
   113  setUploadDirPath
   114  bintrayUpload
   115  snooze
   116  bintraySetDownloads