check.sh 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/bin/bash +x
set -euo pipefail

rm -rf work
mkdir -p work/mac
mkdir -p work/windows


SIGN_SERVICE_URL_MAC=
SIGN_SERVICE_URL_WINDOWS=


function sign() {
  local url=$1
  local inputFile=$2
  local output=$3

  echo "Signing $inputFile..."
  echo "URL=$url"
  local http_code=$(curl -sS -w '%{http_code}' --request POST -o $output -F exeFile=@$inputFile $url;)
  if [[ $http_code -ne 200 ]]; then
    echo "Sign failed and returned http ${http_code}"
    echo "Server message: $(cat $output)" # in this case, the output is plain text
    exit 22
  fi
  
  echo "Sign done"
}

function checkConnectivity() {
  local url=$1

  echo "Checking connectivity with ${url}"
  local response=$(curl -sS --request GET ${url})
  echo "Response: ${response}"
  
  #  {"timestamp":"2018-12-21T15:40:21.943+0000","status":405,"error":"Method Not Allowed","message":"Request method 'GET' not supported","path":"/sign"}
  local http_code=`echo ${response} | jq --raw-output '.status'`
  if [[ $http_code -ne 405 ]]; then
    echo "Connectivity failed and returned http code: ${http_code}"
    exit 21
  fi
  
  echo "Connectivity check done"
}

function checkWindowsService() {
    local url=$1

    checkConnectivity ${url}

    echo "Testing the Windows codesign"
    cp helloworld.exe work/windows/input.exe
    sign ${SIGN_SERVICE_URL_WINDOWS} work/windows/input.exe work/windows/output.exe
    echo "Windows codesign OK"
}

function checkMacService() {
    local url=$1

    checkConnectivity ${url}
    echo "Testing the Mac codesign"
63 64
    cp helloworld.app.zip work/mac/helloworld.app.zip
    sign ${SIGN_SERVICE_URL_MAC} work/mac/helloworld.app.zip work/mac/output.app
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    echo "Mac codesign OK"
}



function usage() {
  launch_command=`basename ${0}`
  echo "Usage: ${launch_command}"
  echo "        --mac-sign-url <url>        url of the mac sign service"
  echo "        --windows-sign-url <url>    url of the windows sign service"
  echo "        --help                      display this help"
  exit 1
}


 while [[ $# -gt 0 ]]; do
    case $1 in
        --mac-sign-url )          shift
                                  SIGN_SERVICE_URL_MAC=$1
                                  ;;
        --windows-sign-url )      shift
                                  SIGN_SERVICE_URL_WINDOWS=$1
                                  ;;
        --help )                  usage
                                  exit
                                  ;;
        * )                       echo "Unknown option: $1"
                                  usage
                                  exit 1
    esac
    shift
done

if [[ -n "${SIGN_SERVICE_URL_WINDOWS}" ]]; then
    checkWindowsService ${SIGN_SERVICE_URL_WINDOWS}
fi
if [[ -n "${SIGN_SERVICE_URL_MAC}" ]]; then
    checkMacService ${SIGN_SERVICE_URL_MAC}
fi