mod_files.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. if [[ "$2" = "" ]] || [[ "$3" = "" ]]; then
  3. echo "Usage: $0 BASE_DIRECTORY DEPTH HASH_BITS"
  4. echo "BASE_DIRECTORY will be created if it doesn't exist"
  5. echo "DEPTH must be an integer number >0"
  6. echo "HASH_BITS(session.hash_bits_per_character) should be one of 4, 5, or 6"
  7. exit 1
  8. fi
  9. if [[ "$2" = "0" ]] && [[ ! "$4" = "recurse" ]]; then
  10. echo "Can't create a directory tree with depth of 0, exiting."
  11. fi
  12. if [[ "$2" = "0" ]]; then
  13. exit 0
  14. fi
  15. directory="$1"
  16. depth="$2"
  17. hashbits="$3"
  18. hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
  19. if [[ "$hashbits" -ge "5" ]]; then
  20. hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
  21. fi
  22. if [[ "$hashbits" -ge "6" ]]; then
  23. hash_chars="$hash_chars w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - ,"
  24. fi
  25. while [[ -d $directory ]] && [[ $( ls $directory ) ]]; do
  26. echo "Directory $directory is not empty! What would you like to do?"
  27. options="\"Delete directory contents\" \"Choose another directory\" \"Quit\""
  28. eval set $options
  29. select opt in "$@"; do
  30. if [[ $opt = "Delete directory contents" ]]; then
  31. echo "Deleting $directory contents... "
  32. rm -rf $directory/*
  33. elif [[ $opt = "Choose another directory" ]]; then
  34. echo "Which directory would you like to choose?"
  35. read directory
  36. elif [[ $opt = "Quit" ]]; then
  37. exit 0
  38. fi
  39. break;
  40. done
  41. done
  42. if [[ ! -d $directory ]]; then
  43. mkdir -p $directory
  44. fi
  45. echo "Creating session path in $directory with a depth of $depth for session.hash_bits_per_character = $hashbits"
  46. for i in $hash_chars; do
  47. newpath="$directory/$i"
  48. mkdir $newpath || exit 1
  49. bash $0 $newpath `expr $depth - 1` $hashbits recurse
  50. done