zefie

build cryptodev openssl armada375 debian proper deb

Jan 26th, 2019 (edited)
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.92 KB | None | 0 0
  1. #!/bin/bash
  2. # see https://gist.github.com/zefie/69dc79494f3321c5a6254fe09eab5ed6 for most updated version
  3. DEB_TEMPLATE='1.1.1d-0+deb10u3'
  4. DEB_TEMPLATE_SID='1.1.1a-1'
  5. SSL_VERS="$(echo "${DEB_TEMPLATE}" | cut -d'-' -f1)"
  6. DEB_SERVER_SID='http://deb.debian.org/debian/pool/main/o/openssl'
  7. DEB_SERVER='http://security.debian.org/debian-security/pool/updates/main/o/openssl'
  8. SSL_SERVER='https://www.openssl.org/source'
  9. DEBUILD_ARGS=('-b')
  10. DEBUILD_INT_ARGS=() # ccache stuff needs to go first
  11.  
  12. # check options
  13. while true; do
  14.     case "$1" in
  15.         # distcc implies ccache
  16.         -d | --distcc ) echo " * distcc mode enabled"; Z_USE_DISTCC=1; Z_USE_CCACHE=1; shift ;;
  17.         # ccache only
  18.         -c | --ccache ) echo " * ccache mode enabled"; Z_USE_CCACHE=1; shift ;;
  19.         -- ) shift; break 2; ;;
  20.         * ) break 2; ;;
  21.     esac
  22. done
  23.  
  24.  
  25. function chkerr() {
  26.     if [ ${1} -ne 0 ]; then
  27.         echo " ! Previous command failed with code ${1}"
  28.         exit "${1}"
  29.     fi
  30. }
  31.  
  32. # check for required build packages. more may be needed
  33. Z_PACKAGES=''
  34. Z_REQUIRED=('build-essential' 'cryptodev-linux-dev' 'devscripts' 'curl')
  35. if [ ! -z "${Z_USE_DISTCC}" ]; then
  36.     Z_USE_CCACHE=1
  37.     Z_REQUIRED+=('distcc')
  38. fi
  39.  
  40. if [ ! -z "${Z_USE_CCACHE}" ]; then
  41.     Z_REQUIRED+=('ccache')
  42. fi
  43.  
  44. for f in "${Z_REQUIRED[@]}"; do
  45.     if ! dpkg --list | grep '^ii' | grep -q "${f}"; then
  46.         Z_PACKAGES="${Z_PACKAGES} ${f}";
  47.     fi
  48. done
  49.  
  50. # install needed packages
  51. if [ "${Z_PACKAGES}" != '' ]; then
  52.     sudo apt install ${Z_PACKAGES}
  53.     chkerr $?
  54. fi
  55.  
  56. if [ ! -z "${Z_USE_CCACHE}" ]; then
  57.     # forcing full path to compiler can help if using distcc
  58.     CC="$(realpath "$(which ccache)") $(realpath "$(which gcc)")"
  59.     CXX="$(realpath "$(which ccache)") $(realpath "$(which g++)")"
  60.     DEBUILD_INT_ARGS+=('-eCC' '-eCXX')
  61. fi
  62. if [ ! -z "${Z_USE_DISTCC}" ]; then
  63.     if [ -z "${DISTCC_HOSTS}" ]; then
  64.         echo " ! Please define DISTCC_HOSTS first, or disable distcc support!"
  65.         exit 1;
  66.     fi
  67.  
  68.     export CCACHE_PREFIX="distcc"
  69.     export DISTCC_JOBS=$(distcc -j)
  70.     echo " * Testing distcc..."
  71.  
  72.     # test distcc .. distcc won't distribute stdin so make temp file
  73.     Z_HELLO_C='I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIHByaW50ZigiSGVsbG8gZGlzdGNjIVxuIik7CiAgICByZXR1cm4gMDsKfQo='
  74.  
  75.     DISTCC_VERBOSE=1
  76.     Z_TMP=$(mktemp --suffix='.c')
  77.     echo "${Z_HELLO_C}" | base64 -d > "${Z_TMP}"
  78.     Z_TEST=$(distcc "$(realpath "$(which gcc)")" -o /dev/null -c "${Z_TMP}" 2>&1)
  79.     rm "${Z_TMP}"
  80.     Z_RES=$(echo "${Z_TEST}" | grep -c 'failed to distribute')
  81.     unset DISTCC_VERBOSE
  82.  
  83.     if [ ${Z_RES} -gt 0 ]; then
  84.         echo " ! Your distcc host (${DISTCC_HOSTS}) is not working! Please fix or try again with distcc mode"
  85.         echo "${Z_TEST}"
  86.         exit 1;
  87.     fi
  88.  
  89.     DEBUILD_INT_ARGS+=('-eCCACHE_PREFIX' '-eDISTCC_HOSTS' '-eDISTCC_JOBS')
  90. fi
  91.  
  92. read -r -d ''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oQVJDSE9QVFMpKQo=
  107. EOM
  108.  
  109. DEB_TEMPLATE_SID_URL="${DEB_SERVER_SID}/openssl_${DEB_TEMPLATE_SID}.debian.tar.xz"
  110. DEB_TEMPLATE_URL="${DEB_SERVER}/openssl_${DEB_TEMPLATE}.debian.tar.xz"
  111. OPENSSL_URL="${SSL_SERVER}/openssl-${SSL_VERS}.tar.gz"
  112.  
  113. if [ -d "openssl-${SSL_VERS}" ]; then
  114.     echo " * Cleaning old build directory..."
  115.     rm -rf "openssl-${SSL_VERS}"
  116.     chkerr $?
  117. fi
  118.  
  119. echo " * Getting OpenSSL ${SSL_VERS} source..."
  120. curl -sL "${OPENSSL_URL}" | tar -xz
  121. chkerr $?
  122.  
  123. echo " * Entering build directory..."
  124. cd "openssl-${SSL_VERS}"
  125. chkerr $?
  126.  
  127. echo " * Getting debian build rules/patches from ${DEB_TEMPLATE}"
  128. curl -sL "${DEB_TEMPLATE_URL}" | tar -xJ
  129. chkerr $?
  130.  
  131. echo " * Patching for cryptodev support"
  132. echo "${DEB_PATCH}" | base64 -d | patch -p1 > /dev/null
  133. chkerr $?
  134.  
  135. echo " * Getting updated changelog and patches from ${DEB_TEMPLATE_SID}"
  136. rm debian/patches/*
  137. chkerr $?
  138.  
  139. curl -sL "${DEB_TEMPLATE_SID_URL}" | tar -xJ debian/changelog debian/patches
  140. chkerr $?
  141.  
  142. echo -n " * Starting build in"
  143. for f in $(seq 5 -1 1); do
  144.     echo -n " ${f}.."
  145.     sleep 1;
  146. done
  147. echo ''
  148. if [ ${#DEBUILD_INT_ARGS[@]} -gt 0 ]; then
  149.     DEBUILD_ARGS=("${DEBUILD_INT_ARGS[@]}" "${DEBUILD_ARGS[@]}")
  150. fi
  151. debuild "${DEBUILD_ARGS[@]}"
  152. chkerr $?
Add Comment
Please, Sign In to add comment