#!/bin/sh # ..::[ The Bitcoin Foundation ]::.. # Who: mod6 0x721705A8B71EADAF # What: Script to Automate Bitcoin v0.5.3 Patching & Compiling # When: 20150118 # Version: v0.0.2 # NOTE: If you don't have the dependencies already plugged in on # Debian 6 (squeeze), you'll want to run following commands: # # sudo apt-get update && sudo apt-get -y upgrade # sudo apt-get install -y build-essential libssl-dev libdb4.8-dev \ # libdb4.8++-dev libboost-all-dev wget git curl gnupg # Bitcoin Dev Home # XXX Make sure that you set HOME ! HOME="/set/this/to/where/you/want/to/build/bitcoind" SHA256="/usr/bin/sha256sum" mod6_fp="027A 8D7C 0FB8 A166 4372 0F40 7217 05A8 B71E ADAF" v053="https://codeload.github.com/bitcoin/bitcoin/legacy.tar.gz/v0.5.3" v053_hash="aab1f8ea8c7f131ff69dfa3b9437ba35531018be760132dd6373f41a591f6382" chicken="http://thebitcoin.foundation/chicken.tar.gz" chicken_hash="63164ea54f042226a6aa8768b98b0f323d66f08693c6fd271a850c00308517ad" upnp="http://thebitcoin.foundation/rm_rf_upnp.tar.gz" upnp_hash="f5f27b806b90b0ffd3d2d73e240eba02f13c5dec3d693b37e08686d04164861a" https="http://thebitcoin.foundation/https-snipsnip.tar.gz" https_hash="047844a601bc575d7660826b02f0d640f02ae84cd641f45552c825b72bc116f4" alert="http://thebitcoin.foundation/turdmeister-alert-snip.tar.gz" alert_hash="39b5aac2b6de016eda23a96fe6f9a565dbbe4f4aa46e8584c102ee71fa4fe7f4" win32="http://thebitcoin.foundation/goodbye-win32.tar.gz" win32_hash="5149a481629e0f10b659d38fee0736e0b6e631ab3bbeb6cde449aa61226cdbb3" ppp_fp="3DAE 5385 2AF4 7432 CE3C 9318 FF23 EAA3 D815 427F" dbconfig="http://thebitcoin.foundation/db_config.tar.gz" dbconfig_hash="b315dc1494334d24606622b7bd3a2569b53e5ad970971ee666ae7adc28fc7d65" # Change dir to $HOME cd $HOME # Get bitcoin-v0.5.3.tar.gz base code & verify checksum hash curl $v053 -s -o bitcoin-v0.5.3.tar.gz hash=`$SHA256 bitcoin-v0.5.3.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' | tr -d ' '` if [ "$hash" != "$v053_hash" ]; then echo "Error! bitcoin-v0_5_3.tar.gz hash did not match!\n"; echo "hash: |$hash|"; echo "v053_hash: |$v053_hash|"; exit 1; fi # Unpack the Bitcoin v0.5.3 code: tar -xf bitcoin-v0.5.3.tar.gz # Download Patch Tarballs: curl $chicken -s -o chicken.tar.gz curl $upnp -s -o rm_rf_upnp.tar.gz curl $https -s -o https-snipsnip.tar.gz curl $alert -s -o turdmeister-alert-snip.tar.gz curl $win32 -s -o goodbye-win32.tar.gz curl $dbconfig -s -o db_config.tar.gz # Check SHA256 Hashes of Patch Tarballs: hash=`$SHA256 chicken.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' | tr -d ' '` if [ "$hash" != "$chicken_hash" ]; then echo "Error! chicken.tar.gz checksum did not match!\n"; echo "hash: |$hash|"; echo "chicken_hash: |$chicken_hash|"; exit 1; fi hash=`$SHA256 rm_rf_upnp.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' | tr -d ' '` if [ "$hash" != "$upnp_hash" ]; then echo "Error! rm_rf_upnp.tar.gz checksum did not match!\n"; echo "hash: |$hash|"; echo "upnp_hash: |$upnp_hash|"; exit 1; fi hash=`$SHA256 https-snipsnip.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' | tr -d ' '` if [ "$hash" != "$https_hash" ]; then echo "Error! https-snipsnip.tar.gz checksum did not match!\n"; echo "hash: |$hash|"; echo "https_hash: |$https_hash|"; exit 1; fi hash=`$SHA256 turdmeister-alert-snip.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' \ | tr -d ' '` if [ "$hash" != "$alert_hash" ]; then echo "Error! turdmeister-alert-snip.tar.gz checksum did not match!\n"; echo "hash: |$hash|"; echo "alert_hash: |$alert_hash|"; exit 1; fi hash=`$SHA256 goodbye-win32.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' | tr -d ' '` if [ "$hash" != "$win32_hash" ]; then echo "Error! goodbye-win32.tar.gz checksum did not match!\n"; echo "hash: |$hash|"; echo "win32_hash: |$win32_hash|"; exit 1; fi hash=`$SHA256 db_config.tar.gz | sed -n 's/^\(.*\) .*$/\1/p' | tr -d ' '` if [ "$hash" != "$dbconfig_hash" ]; then echo "Error! db_config.tar.gz checksum did not match!\n"; echo "hash: |$hash|"; echo "dbconfig_hash: |$dbconfig_hash|"; exit 1; fi # Unpack Patches: mkdir -p chicken && tar -xf chicken.tar.gz -C chicken tar -xf rm_rf_upnp.tar.gz mkdir -p https-snipsnip && tar -xf https-snipsnip.tar.gz -C https-snipsnip mkdir -p alert-snip && tar -xf turdmeister-alert-snip.tar.gz -C alert-snip mkdir -p goodbye-win32 && tar -xf goodbye-win32.tar.gz -C goodbye-win32 tar -xf db_config.tar.gz # Load PubKeys: mkdir -p pubkeys curl -s "http://pgp.mit.edu/pks/lookup?op=get&search=0x2AFA1A9FD2D031DA" \ | sed -n \ "/-----BEGIN PGP PUBLIC KEY BLOCK-----/,/-----END PGP PUBLIC KEY BLOCK-----/p" \ > pubkeys/ben_vulpes.pub.asc curl -s "http://pgp.mit.edu/pks/lookup?op=get&search=0x721705A8B71EADAF" \ | sed -n \ "/-----BEGIN PGP PUBLIC KEY BLOCK-----/,/-----END PGP PUBLIC KEY BLOCK-----/p" \ > pubkeys/mod6.pub.asc curl -s "http://pgp.mit.edu/pks/lookup?op=get&search=0xB98228A001ABFFC7" \ | sed -n \ "/-----BEGIN PGP PUBLIC KEY BLOCK-----/,/-----END PGP PUBLIC KEY BLOCK-----/p" \ > pubkeys/asciilifefrm.pub.asc # Verify GPG PubKey import gpg --logger-file gpgout.log --import pubkeys/*.asc imported=`cat gpgout.log | sed -n 's/.*imported: \([0-9]\).*/\1/p'` rm gpgout.log if [ "$imported" != 3 ]; then echo "Error! GnuPG did not import 3 keys!\n"; echo "imported: $imported"; exit 1; fi # Verify Patch Signatures: gpg --logger-file chicken.sig.log --homedir .gnupg \ --verify chicken/bitcoin-asciilifeform.1.patch.sig sig=`cat chicken.sig.log | sed -n 's/.*\(Good signature\).*/\1/p'` if [ "$sig" != "Good signature" ]; then echo "Error! Possible bad signature on:\n chicken/bitcoin-asciilifeform.1.patch.sig\n Check: chicken.sig.log"; echo "sig: $sig"; exit 1; fi gpg --logger-file rm_rf_upnp.sig.log --homedir .gnupg \ --verify rm_rf_upnp/rm_rf_upnp.patch.sig sig=`cat rm_rf_upnp.sig.log | sed -n 's/.*\(Good signature\).*/\1/p'` if [ "$sig" != "Good signature" ]; then echo "Error! Possible bad signature on:\n rm_rf_upnp/rm_rf_upnp.patch.sig\n Check: rm_rf_upnp.sig.log" echo "sig: $sig"; exit 1; fi gpg --logger-file https_snipsnip.sig.log --homedir .gnupg \ --verify https-snipsnip/bitcoin-asciilifeform.2-https_snipsnip.patch.sig sig=`cat https_snipsnip.sig.log | sed -n 's/.*\(Good signature\).*/\1/p'` if [ "$sig" != "Good signature" ]; then echo "Error! Possible bad signature on:\n https-snipsnip/bitcoin-asciilifeform.2-https_snipsnip.patch.sig\n Check: https_snipsnip.sig.log" echo "sig: $sig"; exit 1; fi gpg --logger-file alert-snip.sig.log --homedir .gnupg \ --verify alert-snip/bitcoin-asciilifeform.3-turdmeister-alert-snip.patch.sig sig=`cat alert-snip.sig.log | sed -n 's/.*\(Good signature\).*/\1/p'` if [ "$sig" != "Good signature" ]; then echo "Error! Possible bad signature on:\n alert-snip/bitcoin-asciilifeform.3-turdmeister-alert-snip.patch.sig\n Check: alert-snip.sig.log" echo "sig: $sig"; exit 1; fi gpg --logger-file goodbye-win32.sig.log --homedir .gnupg \ --verify goodbye-win32/bitcoin-asciilifeform.4-goodbye-win32.patch.sig sig=`cat goodbye-win32.sig.log | sed -n 's/.*\(Good signature\).*/\1/p'` if [ "$sig" != "Good signature" ]; then echo "Error! Possible bad signature on:\n goodbye-win32/bitcoin-asciilifeform.4-goodbye-win32.patch.sig\n Check: goodbye-win32.sig.log" echo "sig: $sig"; exit 1; fi gpg --logger-file db_config.sig.log --homedir .gnupg \ --verify db_config/bitcoin-v0_5_3-db_config.6.patch.sig sig=`cat db_config.sig.log | sed -n 's/.*\(Good signature\).*/\1/p'` if [ "$sig" != "Good signature" ]; then echo "Error! Possible bad signature on:\n db_config/bitcoin-v0_5_3-db_config.6.patch.sig\n Check: db_config.sig.log" echo "sig: $sig"; exit 1; fi # Clean Source Base with PinkPosixPXE's prune-manifest.sh (bash) script: prune_manifest=`cat << 'EOF' #!/bin/bash ## prune_manifest.sh ## ## Prune Bitcoin Manifests ## ## Author: PinkPosixPXE - 11/2014 ## ### Put path to bitcoin dir and chicken dir within these variables ### bitcoin="${HOME}/bitcoin-bitcoin-a8def6b" chicken="${HOME}/chicken" #### MANIFESTS AND FILE LISTS #### chickenManifest="${chicken}/bitcoin-0.5.3-no-crud.sha256.manifest" ### tmp files created for filelists, comparisons, and pruning ### newManifest=/tmp/new-bitcoin.manifest btcManifest=/tmp/bitcoin-a8def6b.manifest btcFiles=/tmp/bitcoin-a8def6b.files newFiles=/tmp/new-bitcoin.files pruneFiles=/tmp/prune-bitcoin.files ### Array to track file varname, for checking before pruning ### fileArr=(newManifest btcManifest chickenManifest btcFiles newFiles pruneFiles) #### INIT #### ### Create required manifests, filelists, and prunelists ### init() { cd ${bitcoin} ### Ensure our src dirs exist ### if [[ ! -d "${bitcoin}" ]]; then echo "Error: Can't find bitcoin src path: ${bitcoin}" exit 1 elif [[ ! -d "${chicken}" ]];then echo "Error: Can't find chicken src path: ${chicken}" exit 1 fi ### clean old tmp files ### rm -v ${newManifest} ${btcFiles} ${newFiles} ${pruneFiles} 2>/dev/null ### Create manifest of current bitcoin src ### find . -xtype f -exec sha256sum {} \; | sort > ${btcManifest} while read line; do mFile=$(echo "${line}" | awk '{print $2}') grep "${mFile}" ${chickenManifest} >> ${newManifest} done < ${btcManifest} ### Manifest parsing ### awk '{print $2}' ${btcManifest} | sort >> ${btcFiles} awk '{print $2}' ${chickenManifest} | sort >> ${newFiles} comm -23 ${btcFiles} ${newFiles} >> ${pruneFiles} } checkFiles() { ## Test files exist, and arent empty ## for filevar in ${fileArr[*]} do file="${!filevar}" ## Check if file exists, or is mising ## test ! -e "${file}" || test ! -s "${file}" &&{ echo "Error: Required File Missing, or empty: ${file}" exit 1 } done ### Check files marked for pruning ### while read file do egrep '^'${file}'$' ${newFiles} && { echo "Check Failed: required file marked for deletion: ${file}" exit 1 } done< ${pruneFiles} return 0 } pruneFiles() { echo "Checks Passed -> Pruning unneeded files from manifest" ## Prune manifest, dirs, and tmp files ## ## If you want it to remove the files quietly, remove the -v ## rm -fv $( < ${pruneFiles} ) 2>/dev/null rm -fv ${newManifest} ${btcFiles} ${btcManifest} \ ${newFiles} ${pruneFiles} 2>/dev/null rm -rfv ./contrib ./doc ./scripts ./share } init checkFiles pruneFiles EOF` echo "$prune_manifest" > prune_manifest.sh /bin/bash prune_manifest.sh count1=`find bitcoin-bitcoin-a8def6b \ -xtype f -print0 | xargs -0 sha256sum | wc -l` count2=`cat chicken/bitcoin-0.5.3-no-crud.sha256.manifest | wc -l` if [ "$count1" != "$count2" ]; then echo "Error! The resulting file count after pruning did not match\n the file count from the manifest."; echo "post-pruning: $count1"; echo "manifest: $count2"; exit 1; fi # Patch Bitcoin v0.5.3 Source Base & Clean Up: cd bitcoin-bitcoin-a8def6b cp ../chicken/bitcoin-asciilifeform.1.patch . patch -p1 < bitcoin-asciilifeform.1.patch cp ../rm_rf_upnp/rm_rf_upnp.patch . patch -p1 < rm_rf_upnp.patch cp ../https-snipsnip/bitcoin-asciilifeform.2-https_snipsnip.patch . patch -p1 < bitcoin-asciilifeform.2-https_snipsnip.patch cp ../alert-snip/bitcoin-asciilifeform.3-turdmeister-alert-snip.patch . patch -p1 < bitcoin-asciilifeform.3-turdmeister-alert-snip.patch cp ../goodbye-win32/bitcoin-asciilifeform.4-goodbye-win32.patch . patch -p1 < bitcoin-asciilifeform.4-goodbye-win32.patch cp ../db_config/bitcoin-v0_5_3-db_config.6.patch . patch -p1 < bitcoin-v0_5_3-db_config.6.patch # [ CLEAN-UP ]: rm bitcoin-asciilifeform.1.patch rm rm_rf_upnp.patch rm bitcoin-asciilifeform.2-https_snipsnip.patch rm bitcoin-asciilifeform.3-turdmeister-alert-snip.patch rm bitcoin-asciilifeform.4-goodbye-win32.patch rm bitcoin-v0_5_3-db_config.6.patch # Compile Patched Source: cd src make -f makefile.unix echo "Done!" ### EOF ###