Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #!/bin/bash
  2. ## prune_manifest.sh ##
  3. ## Prune Bitcoin Manifests ##
  4. ## Author: PinkPosixPXE - 11/2014 ##
  5.  
  6. ### Put path to bitcoin dir and chicken dir within these variables ###
  7. bitcoin="${HOME}/bitcoin/bitcoin-bitcoin-a8def6b"
  8. chicken="${HOME}/bitcoin/chicken"
  9.  
  10. #### MANIFESTS AND FILE LISTS ####
  11. chickenManifest="${chicken}/bitcoin-0.5.3-no-crud.sha256.manifest"
  12. ### tmp files created for filelists, comparisons, and pruning ###
  13. newManifest=/tmp/new-bitcoin.manifest
  14. btcManifest=/tmp/bitcoin-a8def6b.manifest
  15. btcFiles=/tmp/bitcoin-a8def6b.files
  16. newFiles=/tmp/new-bitcoin.files
  17. pruneFiles=/tmp/prune-bitcoin.files
  18.  
  19. ### Array to track file varname, for checking before pruning ###
  20. fileArr=(newManifest btcManifest chickenManifest btcFiles newFiles pruneFiles)
  21. #### INIT ####
  22. ### Create required manifests, filelists, and prunelists ###
  23. init() {
  24. cd ${bitcoin}
  25. ### Ensure our src dirs exist ###
  26. if [[ ! -d "${bitcoin}" ]]; then
  27. echo "Error: Can't find bitcoin src path: ${bitcoin}"
  28. exit 1
  29. elif [[ ! -d "${chicken}" ]];then
  30. echo "Error: Can't find chicken src path: ${chicken}"
  31. exit 1
  32. fi
  33. ### clean old tmp files ###
  34. rm -v ${newManifest} ${btcFiles} ${newFiles} ${pruneFiles} 2>/dev/null
  35. ### Create manifest of current bitcoin src ###
  36. find . -xtype f -exec sha256sum {} \; | sort > ${btcManifest}
  37. while read line;
  38. do
  39. mFile=$(echo "${line}" | awk '{print $2}')
  40. grep "${mFile}" ${chickenManifest} >> ${newManifest}
  41. done < ${btcManifest}
  42. ### Manifest parsing ###
  43. awk '{print $2}' ${btcManifest} | sort >> ${btcFiles}
  44. awk '{print $2}' ${chickenManifest} | sort >> ${newFiles}
  45. comm -23 ${btcFiles} ${newFiles} >> ${pruneFiles}
  46. }
  47.  
  48. checkFiles() {
  49. ## Test files exist, and aren't empty ##
  50. for filevar in ${fileArr[*]}
  51. do
  52. file="${!filevar}"
  53. ## Check if file exists, or is mising ##
  54. test ! -e "${file}" || test ! -s "${file}" &&{
  55. echo "Error: Required File Missing, or empty: ${file}"
  56. exit 1
  57. }
  58. done
  59. ### Check files marked for pruning ###
  60. while read file
  61. do
  62. egrep '^'${file}'$' ${newFiles} && {
  63. echo "Check Failed: required file marked for deletion: ${file}"
  64. exit 1
  65. }
  66. done< ${pruneFiles}
  67. return 0
  68. }
  69.  
  70. pruneFiles() {
  71. echo "Checks Passed -> Pruning unneeded files from manifest"
  72. ## Prune manifest, dirs, and tmp files ##
  73. ## If you want it to remove the files quietly, remove the -v ##
  74. rm -fv $( < ${pruneFiles} ) 2>/dev/null
  75. rm -fv ${newManifest} ${btcFiles} ${btcManifest} \
  76. ${newFiles} ${pruneFiles} 2>/dev/null
  77. rm -rfv ./contrib ./doc ./scripts ./share
  78. }
  79.  
  80. init
  81. checkFiles
  82. pruneFiles
  83. ###### EOF ######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement