mod_files.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. if [[ "$2" = "" ]] || [[ "$3" = "" ]]; then
  3. echo "Usage: $0 BASE_DIRECTORY DEPTH BITS_PER_CHAR"
  4. echo "BASE_DIRECTORY will be created if it doesn't exist"
  5. echo "DEPTH must be an integer number >0"
  6. echo "BITS_PER_CHAR(session.sid_bits_per_character) should be one of 4, 5, or 6."
  7. # http://php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character
  8. exit 1
  9. fi
  10. if [[ "$2" = "0" ]] && [[ ! "$4" = "recurse" ]]; then
  11. echo "Can't create a directory tree with depth of 0, exiting."
  12. fi
  13. if [[ "$2" = "0" ]]; then
  14. exit 0
  15. fi
  16. directory="$1"
  17. depth="$2"
  18. bitsperchar="$3"
  19. hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
  20. if [[ "$bitsperchar" -ge "5" ]]; then
  21. hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
  22. fi
  23. if [[ "$bitsperchar" -ge "6" ]]; then
  24. 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 - ,"
  25. fi
  26. while [[ -d $directory ]] && [[ $( ls $directory ) ]]; do
  27. echo "Directory $directory is not empty! What would you like to do?"
  28. options="\"Delete directory contents\" \"Choose another directory\" \"Quit\""
  29. eval set $options
  30. select opt in "$@"; do
  31. if [[ $opt = "Delete directory contents" ]]; then
  32. echo "Deleting $directory contents... "
  33. rm -rf $directory/*
  34. elif [[ $opt = "Choose another directory" ]]; then
  35. echo "Which directory would you like to choose?"
  36. read directory
  37. elif [[ $opt = "Quit" ]]; then
  38. exit 0
  39. fi
  40. break;
  41. done
  42. done
  43. if [[ ! -d $directory ]]; then
  44. mkdir -p $directory
  45. fi
  46. echo "Creating session path in $directory with a depth of $depth for session.sid_bits_per_character = $bitsperchar"
  47. for i in $hash_chars; do
  48. newpath="$directory/$i"
  49. mkdir $newpath || exit 1
  50. bash $0 $newpath `expr $depth - 1` $bitsperchar recurse
  51. done