You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tidy_datadir.sh 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # Copyright (c) 2013 The Starwels developers
  3. # Distributed under the MIT software license, see the accompanying
  4. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. if [ -d "$1" ]; then
  6. cd "$1"
  7. else
  8. echo "Usage: $0 <datadir>" >&2
  9. echo "Removes obsolete Starwels database files" >&2
  10. exit 1
  11. fi
  12. LEVEL=0
  13. if [ -f wallet.dat -a -f addr.dat -a -f blkindex.dat -a -f blk0001.dat ]; then LEVEL=1; fi
  14. if [ -f wallet.dat -a -f peers.dat -a -f blkindex.dat -a -f blk0001.dat ]; then LEVEL=2; fi
  15. if [ -f wallet.dat -a -f peers.dat -a -f coins/CURRENT -a -f blktree/CURRENT -a -f blocks/blk00000.dat ]; then LEVEL=3; fi
  16. if [ -f wallet.dat -a -f peers.dat -a -f chainstate/CURRENT -a -f blocks/index/CURRENT -a -f blocks/blk00000.dat ]; then LEVEL=4; fi
  17. case $LEVEL in
  18. 0)
  19. echo "Error: no Starwels datadir detected."
  20. exit 1
  21. ;;
  22. 1)
  23. echo "Detected old Starwels datadir (before 0.7)."
  24. echo "Nothing to do."
  25. exit 0
  26. ;;
  27. 2)
  28. echo "Detected Starwels 0.7 datadir."
  29. ;;
  30. 3)
  31. echo "Detected Starwels pre-0.8 datadir."
  32. ;;
  33. 4)
  34. echo "Detected Starwels 0.8 datadir."
  35. ;;
  36. esac
  37. FILES=""
  38. DIRS=""
  39. if [ $LEVEL -ge 3 ]; then FILES=$(echo $FILES blk????.dat blkindex.dat); fi
  40. if [ $LEVEL -ge 2 ]; then FILES=$(echo $FILES addr.dat); fi
  41. if [ $LEVEL -ge 4 ]; then DIRS=$(echo $DIRS coins blktree); fi
  42. for FILE in $FILES; do
  43. if [ -f $FILE ]; then
  44. echo "Deleting: $FILE"
  45. rm -f $FILE
  46. fi
  47. done
  48. for DIR in $DIRS; do
  49. if [ -d $DIR ]; then
  50. echo "Deleting: $DIR/"
  51. rm -rf $DIR
  52. fi
  53. done
  54. echo "Done."