github.com/stevenmatthewt/agent@v3.5.4+incompatible/scripts/publish-debian-package.sh (about)

     1  #!/bin/bash
     2  
     3  set -o errexit
     4  
     5  if [[ ${#} -ne 2 ]]
     6  then
     7    echo "Usage: ${0} [debian-package] [codename]" >&2
     8    exit 1
     9  fi
    10  
    11  function info {
    12    echo -e "\033[35m$1\033[0m"
    13  }
    14  
    15  PACKAGE=${1}
    16  CODENAME=${2}
    17  COMPONENT="main"
    18  
    19  # Some validations
    20  if [ -z "$GPG_SIGNING_KEY" ]; then
    21    echo "Error: Missing ENV variable GPG_SIGNING_KEY"
    22    exit 1
    23  fi
    24  
    25  if [ -z "$GPG_PASSPHRASE_PASSWORD" ]; then
    26    echo "Error: Missing ENV variable GPG_PASSPHRASE_PASSWORD"
    27    exit 1
    28  fi
    29  
    30  if [ -z "$GPG_PASSPHRASE_PATH" ]; then
    31    echo "Error: Missing ENV variable GPG_PASSPHRASE_PATH"
    32    exit 1
    33  fi
    34  
    35  if [ -z "$DEB_S3_BUCKET" ]; then
    36    echo "Error: Missing ENV variable DEB_S3_BUCKET"
    37    exit 1
    38  fi
    39  
    40  if [ -z "$DEB_S3_ACCESS_KEY_ID" ]; then
    41    echo "Error: Missing ENV variable DEB_S3_ACCESS_KEY_ID"
    42    exit 1
    43  fi
    44  
    45  if [ -z "$DEB_S3_SECRET_ACCESS_KEY_ID" ]; then
    46    echo "Error: Missing ENV variable DEB_S3_SECRET_ACCESS_KEY_ID"
    47    exit 1
    48  fi
    49  
    50  info "Uploading $PACKAGE to $DEB_S3_BUCKET ($CODENAME $COMPONENT)"
    51  
    52  # Decrpyt the GPG_PASSPHRASE with our GPG_PASSPHRASE_PASSWORD
    53  GPG_PASSPHRASE=`openssl aes-256-cbc -k "$GPG_PASSPHRASE_PASSWORD" -in "$GPG_PASSPHRASE_PATH" -d`
    54  
    55  deb_s3_args=(
    56    --preserve-versions
    57    --sign "$GPG_SIGNING_KEY"
    58    --gpg-options "\-\-digest-algo SHA512 \-\-passphrase $GPG_PASSPHRASE"
    59    --codename "$CODENAME"
    60    --component "$COMPONENT"
    61    "--access-key-id=$DEB_S3_ACCESS_KEY_ID"
    62    "--secret-access-key=$DEB_S3_SECRET_ACCESS_KEY_ID"
    63  )
    64  
    65  # Older versions were ok with prefix and bucket in the same parameter, but we now need to split them
    66  
    67  echo "Parsing DEB_S3_BUCKET=$DEB_S3_BUCKET"
    68  DEB_S3_BUCKET_ARRAY=(${DEB_S3_BUCKET//\// })
    69  
    70  if [[ ${#DEB_S3_BUCKET_ARRAY[@]} -gt 2 ]] ; then
    71    echo "Expected $DEB_S3_BUCKET to have at most 1 path component"
    72  fi
    73  
    74  if [[ ${#DEB_S3_BUCKET_ARRAY[@]} -gt 1 ]] ; then
    75    deb_s3_args+=(
    76      --bucket "${DEB_S3_BUCKET_ARRAY[0]}"
    77      --prefix "${DEB_S3_BUCKET_ARRAY[1]}"
    78    )
    79  else
    80    deb_s3_args+=(
    81      --bucket "$DEB_S3_BUCKET_PREFIX"
    82    )
    83  fi
    84  
    85  # Uploads to s3 and signs with the default key on the system
    86  
    87  bundle exec deb-s3 upload "${deb_s3_args[@]}" "$PACKAGE"
    88  
    89  echo "✅ All done! To install this package:"
    90  echo ""
    91  echo "    # Login as root"
    92  echo "    $ sudo su"
    93  echo ""
    94  echo "    # Add the repository to your APT sources"
    95  echo "    $ echo deb http://$DEB_S3_BUCKET $CODENAME $COMPONENT > /etc/apt/sources.list.d/buildkite-agent.list"
    96  echo ""
    97  echo "    # Then import the repository key"
    98  echo "    $ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 32A37959C2FA5C3C99EFBC32A79206696452D198"
    99  echo ""
   100  echo "    # Install the agent"
   101  echo "    $ apt-get update"
   102  echo "    $ apt-get install -y buildkite-agent"
   103  echo ""