Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # see https://gist.github.com/zefie/69dc79494f3321c5a6254fe09eab5ed6 for most updated version
- DEB_TEMPLATE='1.1.1d-0+deb10u3'
- DEB_TEMPLATE_SID='1.1.1a-1'
- SSL_VERS="$(echo "${DEB_TEMPLATE}" | cut -d'-' -f1)"
- DEB_SERVER_SID='http://deb.debian.org/debian/pool/main/o/openssl'
- DEB_SERVER='http://security.debian.org/debian-security/pool/updates/main/o/openssl'
- SSL_SERVER='https://www.openssl.org/source'
- DEBUILD_ARGS=('-b')
- DEBUILD_INT_ARGS=() # ccache stuff needs to go first
- # check options
- while true; do
- case "$1" in
- # distcc implies ccache
- -d | --distcc ) echo " * distcc mode enabled"; Z_USE_DISTCC=1; Z_USE_CCACHE=1; shift ;;
- # ccache only
- -c | --ccache ) echo " * ccache mode enabled"; Z_USE_CCACHE=1; shift ;;
- -- ) shift; break 2; ;;
- * ) break 2; ;;
- esac
- done
- function chkerr() {
- if [ ${1} -ne 0 ]; then
- echo " ! Previous command failed with code ${1}"
- exit "${1}"
- fi
- }
- # check for required build packages. more may be needed
- Z_PACKAGES=''
- Z_REQUIRED=('build-essential' 'cryptodev-linux-dev' 'devscripts' 'curl')
- if [ ! -z "${Z_USE_DISTCC}" ]; then
- Z_USE_CCACHE=1
- Z_REQUIRED+=('distcc')
- fi
- if [ ! -z "${Z_USE_CCACHE}" ]; then
- Z_REQUIRED+=('ccache')
- fi
- for f in "${Z_REQUIRED[@]}"; do
- if ! dpkg --list | grep '^ii' | grep -q "${f}"; then
- Z_PACKAGES="${Z_PACKAGES} ${f}";
- fi
- done
- # install needed packages
- if [ "${Z_PACKAGES}" != '' ]; then
- sudo apt install ${Z_PACKAGES}
- chkerr $?
- fi
- if [ ! -z "${Z_USE_CCACHE}" ]; then
- # forcing full path to compiler can help if using distcc
- CC="$(realpath "$(which ccache)") $(realpath "$(which gcc)")"
- CXX="$(realpath "$(which ccache)") $(realpath "$(which g++)")"
- DEBUILD_INT_ARGS+=('-eCC' '-eCXX')
- fi
- if [ ! -z "${Z_USE_DISTCC}" ]; then
- if [ -z "${DISTCC_HOSTS}" ]; then
- echo " ! Please define DISTCC_HOSTS first, or disable distcc support!"
- exit 1;
- fi
- export CCACHE_PREFIX="distcc"
- export DISTCC_JOBS=$(distcc -j)
- echo " * Testing distcc..."
- # test distcc .. distcc won't distribute stdin so make temp file
- Z_HELLO_C='I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIHByaW50ZigiSGVsbG8gZGlzdGNjIVxuIik7CiAgICByZXR1cm4gMDsKfQo='
- DISTCC_VERBOSE=1
- Z_TMP=$(mktemp --suffix='.c')
- echo "${Z_HELLO_C}" | base64 -d > "${Z_TMP}"
- Z_TEST=$(distcc "$(realpath "$(which gcc)")" -o /dev/null -c "${Z_TMP}" 2>&1)
- rm "${Z_TMP}"
- Z_RES=$(echo "${Z_TEST}" | grep -c 'failed to distribute')
- unset DISTCC_VERBOSE
- if [ ${Z_RES} -gt 0 ]; then
- echo " ! Your distcc host (${DISTCC_HOSTS}) is not working! Please fix or try again with distcc mode"
- echo "${Z_TEST}"
- exit 1;
- fi
- DEBUILD_INT_ARGS+=('-eCCACHE_PREFIX' '-eDISTCC_HOSTS' '-eDISTCC_JOBS')
- fi
- read -r -d '' DEB_PATCH << EOM
- ZGlmZiAtTmF1ciBhL2RlYmlhbi9ydWxlcyBiL2RlYmlhbi9ydWxlcwotLS0gYS9kZWJpYW4vcnVs
- ZXMJMjAxOC0xMS0yNCAyMTo1Nzo0NS4wMDAwMDAwMDAgKzAxMDAKKysrIGIvZGViaWFuL3J1bGVz
- CTIwMTktMDEtMjcgMDQ6NDk6NDYuOTY2OTkyMTY1ICswMTAwCkBAIC0zMSw3ICszMSw3IEBACiAJ
- TUFLRUZMQUdTICs9IC1qJChOVU1KT0JTKQogZW5kaWYKIAotQ09ORkFSR1MgID0gLS1wcmVmaXg9
- L3VzciAtLW9wZW5zc2xkaXI9L3Vzci9saWIvc3NsIC0tbGliZGlyPWxpYi8kKERFQl9IT1NUX01V
- TFRJQVJDSCkgbm8taWRlYSBuby1tZGMyIG5vLXJjNSBuby16bGliIG5vLXNzbDMgZW5hYmxlLXVu
- aXQtdGVzdCBuby1zc2wzLW1ldGhvZCBlbmFibGUtcmZjMzc3OSBlbmFibGUtY21zCitDT05GQVJH
- UyAgPSAtLXByZWZpeD0vdXNyIC0tb3BlbnNzbGRpcj0vdXNyL2xpYi9zc2wgLURIQVZFX0NSWVBU
- T0RFViAtRFVTRV9DUllQVE9ERVZfRElHRVNUUyAtbWFyY2g9YXJtdjctYSAtV2wsLS1lbmFibGUt
- bmV3LWR0YWdzLC1ycGF0aCwvdXNyL2xpYi9zc2wgLS1saWJkaXI9bGliLyQoREVCX0hPU1RfTVVM
- VElBUkNIKSBuby1pZGVhIG5vLW1kYzIgbm8tcmM1IG5vLXpsaWIgbm8tc3NsMyBlbmFibGUtdW5p
- dC10ZXN0IG5vLXNzbDMtbWV0aG9kIGVuYWJsZS1yZmMzNzc5IGVuYWJsZS1jbXMKIE9QVF9hbHBo
- YSA9IGV2NCBldjUKIEFSQ0hPUFRTICA9IE9QVF8kKERFQl9IT1NUX0FSQ0gpCiBPUFRTICAgICAg
- PSAkKCQoQVJDSE9QVFMpKQo=
- EOM
- DEB_TEMPLATE_SID_URL="${DEB_SERVER_SID}/openssl_${DEB_TEMPLATE_SID}.debian.tar.xz"
- DEB_TEMPLATE_URL="${DEB_SERVER}/openssl_${DEB_TEMPLATE}.debian.tar.xz"
- OPENSSL_URL="${SSL_SERVER}/openssl-${SSL_VERS}.tar.gz"
- if [ -d "openssl-${SSL_VERS}" ]; then
- echo " * Cleaning old build directory..."
- rm -rf "openssl-${SSL_VERS}"
- chkerr $?
- fi
- echo " * Getting OpenSSL ${SSL_VERS} source..."
- curl -sL "${OPENSSL_URL}" | tar -xz
- chkerr $?
- echo " * Entering build directory..."
- cd "openssl-${SSL_VERS}"
- chkerr $?
- echo " * Getting debian build rules/patches from ${DEB_TEMPLATE}"
- curl -sL "${DEB_TEMPLATE_URL}" | tar -xJ
- chkerr $?
- echo " * Patching for cryptodev support"
- echo "${DEB_PATCH}" | base64 -d | patch -p1 > /dev/null
- chkerr $?
- echo " * Getting updated changelog and patches from ${DEB_TEMPLATE_SID}"
- rm debian/patches/*
- chkerr $?
- curl -sL "${DEB_TEMPLATE_SID_URL}" | tar -xJ debian/changelog debian/patches
- chkerr $?
- echo -n " * Starting build in"
- for f in $(seq 5 -1 1); do
- echo -n " ${f}.."
- sleep 1;
- done
- echo ''
- if [ ${#DEBUILD_INT_ARGS[@]} -gt 0 ]; then
- DEBUILD_ARGS=("${DEBUILD_INT_ARGS[@]}" "${DEBUILD_ARGS[@]}")
- fi
- debuild "${DEBUILD_ARGS[@]}"
- chkerr $?
Add Comment
Please, Sign In to add comment