From 9b1e044be71786550eb18e1592e07a9896241716 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 5 Jul 2019 16:32:16 -0500 Subject: [PATCH] Combine Mac and Linux build scripts --- create_dist.sh | 78 ++++++++++++++++++++++++++++------------------ create_dist_mac.sh | 60 ----------------------------------- 2 files changed, 48 insertions(+), 90 deletions(-) delete mode 100755 create_dist_mac.sh diff --git a/create_dist.sh b/create_dist.sh index eeeb5a4..7e3de3c 100755 --- a/create_dist.sh +++ b/create_dist.sh @@ -1,17 +1,30 @@ #!/bin/sh +beginsWith() { case $2 in "$1"*) true;; *) false;; esac; } + PATH=$(pwd)/bin:$PATH export PATH -DISTRO_LIST="arch centos7 debian9 fedora28 fedora29 fedora30 solus ubuntu18.04 ubuntu18.10 ubuntu19.04" +ENABLE_UPLOAD=$1 +BITBUCKET_AUTH=$2 PRIVATE_KEY=../../blockstorage_dev_private.pem -PUBLIC_KEY=./blockstorage_dev_public.pem - +PUBLIC_KEY=../blockstorage_dev_public.pem APP_VER=$(grep -m1 -a version package.json|sed -e "s/\"//g" -e "s/version: //g" -e "s/,//g" -e "s/ //g") -OUT_FILE=repertory-ui_${APP_VER}_linux_x86_64.AppImage -BITBUCKET_AUTH=$1 +if beginsWith darwin "$OSTYPE"; then + DISTRO_LIST="darwin" + OUT_FILE=repertory-ui_${APP_VER}_mac.dmg + BASE64_EXEC=base64 + JQ_EXEC=jq-osx-amd64 + SHA256_EXEC="shasum -a 256 -b" +else + DISTRO_LIST="arch centos7 debian9 fedora28 fedora29 fedora30 opensuse15 opensuse15.1 solus ubuntu18.04 ubuntu18.10 ubuntu19.04" + OUT_FILE=repertory-ui_${APP_VER}_linux_x86_64.AppImage + BASE64_EXEC="base64 -w0" + JQ_EXEC=jq-linux64 + SHA256_EXEC="sha256sum -b" +fi exit_script() { echo $1 @@ -23,39 +36,44 @@ upload_to_bitbucket() { curl --fail -u "${BITBUCKET_AUTH}" -X POST https://api.bitbucket.org/2.0/repositories/blockstorage/repertory/downloads -F files=@${SOURCE_FILE} > upload_response.json || exit_script "Upload to Bitbucket failed: ${SOURCE_FILE}" } +chmod +x "bin/${JQ_EXEC}" || exit_script "chmod +x ${JQ_EXEC} failed" + if npm run dist; then cd dist - sha256sum -b ${OUT_FILE} > ${OUT_FILE}.sha256 || exit_script "Create sha256 failed" + ${SHA256_EXEC} ${OUT_FILE} > ${OUT_FILE}.sha256 || exit_script "Create sha256 failed" openssl dgst -sha256 -sign "${PRIVATE_KEY}" -out "${OUT_FILE}.sig" "${OUT_FILE}" || exit_script "Create signature failed" - base64 -w0 "${OUT_FILE}.sig" > "${OUT_FILE}.sig.b64" || exit_script "Create base64 failed" + openssl dgst -sha256 -verify "${PUBLIC_KEY}" -signature "${OUT_FILE}.sig" "${OUT_FILE}" || exit_script "Verify signature failed" + ${BASE64_EXEC} "${OUT_FILE}.sig" > "${OUT_FILE}.sig.b64" || exit_script "Create base64 failed" - APP_SIG=$(cat ${OUT_FILE}.sig.b64) - APP_SHA256=$(cat ${OUT_FILE}.sha256 | awk '{print $1;}') + if [ "$ENABLE_UPLOAD" = "1" ]; then + APP_SIG=$(cat ${OUT_FILE}.sig.b64) + APP_SHA256=$(cat ${OUT_FILE}.sha256 | awk '{print $1;}') - rm -f upload_response.json 1>/dev/null 2>&1 - curl -F name="${OUT_FILE}" -F anonymous=true -F file="@${OUT_FILE}" https://pixeldrain.com/api/file > upload_response.json || exit_script "Upload to Pixeldrain failed" + rm -f upload_response.json 1>/dev/null 2>&1 + curl --fail -F name="${OUT_FILE}" -F anonymous=true -F file="@${OUT_FILE}" https://pixeldrain.com/api/file > upload_response.json || exit_script "Upload to Pixeldrain failed" - PIXEL_SUCCESS=$(jq-linux64 .success upload_response.json) - if [ "${PIXEL_SUCCESS}" = "false" ]; then - PIXEL_MESSAGE=$(jq-linux64 .message upload_response.json) - exit_script "${PIXEL_MESSAGE}" - else - PIXEL_ID=$(jq-linux64 .id upload_response.json|sed s/\"//g) - PIXEL_LOCATION=https://pixeldrain.com/api/file/${PIXEL_ID} + PIXEL_SUCCESS=$(${JQ_EXEC} .success upload_response.json) + if [ "${PIXEL_SUCCESS}" = "false" ]; then + PIXEL_MESSAGE=$(${JQ_EXEC} .message upload_response.json) + exit_script "${PIXEL_MESSAGE}" + else + PIXEL_ID=$(${JQ_EXEC} .id upload_response.json|sed s/\"//g) + PIXEL_LOCATION=https://pixeldrain.com/api/file/${PIXEL_ID} - upload_to_bitbucket "${OUT_FILE}" - upload_to_bitbucket "${OUT_FILE}.sha256" - upload_to_bitbucket "${OUT_FILE}.sig" - BITBUCKET_LOCATION=https://bitbucket.org/blockstorage/repertory/downloads/${OUT_FILE} + upload_to_bitbucket "${OUT_FILE}" + upload_to_bitbucket "${OUT_FILE}.sha256" + upload_to_bitbucket "${OUT_FILE}.sig" + BITBUCKET_LOCATION=https://bitbucket.org/blockstorage/repertory/downloads/${OUT_FILE} - cp -f ../releases.json ./releases.json - for DISTRONAME in ${DISTRO_LIST}; do - jq-linux64 ".Versions[\"${DISTRONAME}\"]|=(.+ [\"${APP_VER}\"]|unique)" releases.json > releases_temp.json || exit_script "Update releases.json Versions failed" - jq-linux64 ".Locations[\"${DISTRONAME}\"].\"${APP_VER}\".sig=\"${APP_SIG}\"" releases_temp.json > releases.json || exit_script "Update releases.json sig failed" - jq-linux64 ".Locations[\"${DISTRONAME}\"].\"${APP_VER}\".sha256=\"${APP_SHA256}\"" releases.json > releases_temp.json || exit_script "Update releases.json sha256 failed" - jq-linux64 ".Locations[\"${DISTRONAME}\"].\"${APP_VER}\".urls=[\"${PIXEL_LOCATION}\",\"${BITBUCKET_LOCATION}\"]" releases_temp.json > releases.json || exit_script "Update releases.json URL failed" - done - rm -f releases_temp.json + cp -f ../releases.json ./releases.json + for DISTRONAME in ${DISTRO_LIST}; do + ${JQ_EXEC} ".Versions[\"${DISTRONAME}\"]|=(.+ [\"${APP_VER}\"]|unique)" releases.json > releases_temp.json || exit_script "Update releases.json Versions failed" + ${JQ_EXEC} ".Locations[\"${DISTRONAME}\"].\"${APP_VER}\".sig=\"${APP_SIG}\"" releases_temp.json > releases.json || exit_script "Update releases.json sig failed" + ${JQ_EXEC} ".Locations[\"${DISTRONAME}\"].\"${APP_VER}\".sha256=\"${APP_SHA256}\"" releases.json > releases_temp.json || exit_script "Update releases.json sha256 failed" + ${JQ_EXEC} ".Locations[\"${DISTRONAME}\"].\"${APP_VER}\".urls=[\"${PIXEL_LOCATION}\",\"${BITBUCKET_LOCATION}\"]" releases_temp.json > releases.json || exit_script "Update releases.json URL failed" + done + rm -f releases_temp.json + fi fi cd - else diff --git a/create_dist_mac.sh b/create_dist_mac.sh deleted file mode 100755 index 8fce24e..0000000 --- a/create_dist_mac.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -PATH=$(pwd)/bin:$PATH -export PATH - -PRIVATE_KEY=../../blockstorage_dev_private.pem -PUBLIC_KEY=./blockstorage_dev_public.pem - -APP_VER=$(grep -m1 -a version package.json|sed -e "s/\"//g" -e "s/version: //g" -e "s/,//g" -e "s/ //g") -OUT_FILE=repertory-ui_${APP_VER}_mac.dmg - -BITBUCKET_AUTH=$1 - -exit_script() { - echo $1 - exit 1 -} - -upload_to_bitbucket() { - SOURCE_FILE=$1 - curl --fail -u "${BITBUCKET_AUTH}" -X POST https://api.bitbucket.org/2.0/repositories/blockstorage/repertory/downloads -F files=@${SOURCE_FILE} > upload_response.json || exit_script "Upload to Bitbucket failed: ${SOURCE_FILE}" -} - -if npm run dist; then - cd dist - shasum -a 256 -b ${OUT_FILE} > ${OUT_FILE}.sha256 || exit_script "Create sha256 failed" - openssl dgst -sha256 -sign "${PRIVATE_KEY}" -out "${OUT_FILE}.sig" "${OUT_FILE}" || exit_script "Create signature failed" - base64 "${OUT_FILE}.sig" > "${OUT_FILE}.sig.b64" || exit_script "Create base64 failed" - - APP_SIG=$(cat ${OUT_FILE}.sig.b64) - APP_SHA256=$(cat ${OUT_FILE}.sha256 | awk '{print $1;}') - - rm -f upload_response.json 1>/dev/null 2>&1 - curl -F name="${OUT_FILE}" -F anonymous=true -F file="@${OUT_FILE}" https://pixeldrain.com/api/file > upload_response.json || exit_script "Upload to Pixeldrain failed" - - PIXEL_SUCCESS=$(jq-osx-amd64 .success upload_response.json) - if [ "${PIXEL_SUCCESS}" = "false" ]; then - PIXEL_MESSAGE=$(jq-osx-amd64 .message upload_response.json) - exit_script "${PIXEL_MESSAGE}" - else - PIXEL_ID=$(jq-osx-amd64 .id upload_response.json|sed s/\"//g) - PIXEL_LOCATION=https://pixeldrain.com/api/file/${PIXEL_ID} - - upload_to_bitbucket "${OUT_FILE}" - upload_to_bitbucket "${OUT_FILE}.sha256" - upload_to_bitbucket "${OUT_FILE}.sig" - BITBUCKET_LOCATION=https://bitbucket.org/blockstorage/repertory/downloads/${OUT_FILE} - - cp -f ../releases.json ./releases.json - jq-osx-amd64 ".Versions[\"darwin\"]|=(.+ [\"${APP_VER}\"]|unique)" releases.json > releases_temp.json || exit_script "Update releases.json Versions failed" - jq-osx-amd64 ".Locations[\"darwin\"].\"${APP_VER}\".sig=\"${APP_SIG}\"" releases_temp.json > releases.json || exit_script "Update releases.json sig failed" - jq-osx-amd64 ".Locations[\"darwin\"].\"${APP_VER}\".sha256=\"${APP_SHA256}\"" releases.json > releases_temp.json || exit_script "Update releases.json sha256 failed" - jq-osx-amd64 ".Locations[\"darwin\"].\"${APP_VER}\".urls=[\"${PIXEL_LOCATION}\"]" releases_temp.json > releases.json || exit_script "Update releases.json URL failed" - - rm -f releases_temp.json - fi - cd - -else - exit_script "Create dist failed" -fi