|
1 | 1 | #! /bin/sh
|
2 | 2 |
|
3 |
| -if test "$2" = ""; then |
4 |
| - echo "usage: $0 basedir depth" |
5 |
| - exit 1 |
| 3 | +if [[ "$2" = "" ]] || [[ "$3" = "" ]]; then |
| 4 | + echo "Usage: $0 BASE_DIRECTORY DEPTH HASH_BITS" |
| 5 | + echo "BASE_DIRECTORY will be created if it doesn't exist" |
| 6 | + echo "DEPTH must be an integer number >0" |
| 7 | + echo "HASH_BITS(session.hash_bits_per_charactor) should be one of 4, 5, or 6" |
| 8 | + exit 1 |
6 | 9 | fi
|
7 | 10 |
|
8 |
| -if test "$2" = "0"; then |
9 |
| - exit 0 |
| 11 | +if [[ "$2" = "0" ]] && [[ ! "$4" = "recurse" ]]; then |
| 12 | + echo "Can't create a directory tree with depth of 0, exiting." |
10 | 13 | fi
|
11 | 14 |
|
| 15 | +if [[ "$2" = "0" ]]; then |
| 16 | + exit 0 |
| 17 | +fi |
| 18 | + |
| 19 | +directory="$1" |
| 20 | +depth="$2" |
| 21 | +hashbits="$3" |
| 22 | + |
12 | 23 | hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
|
13 |
| -if test "$3" -a "$3" -ge "5"; then |
14 |
| - hash_chars="$hash_chars g h i j k l m n o p q r s t u v" |
15 |
| - if test "$3" -eq "6"; then |
16 |
| - 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 - ," |
17 |
| - fi |
| 24 | + |
| 25 | +if [[ "$hashbits" -ge "5" ]]; then |
| 26 | + hash_chars="$hash_chars g h i j k l m n o p q r s t u v" |
18 | 27 | fi
|
19 | 28 |
|
| 29 | +if [[ "$hashbits" -ge "6" ]]; then |
| 30 | + 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 - ," |
| 31 | +fi |
| 32 | + |
| 33 | +while [[ -d $directory ]] && [[ $( ls $directory ) ]]; do |
| 34 | + echo "Directory $directory is not empty! What would you like to do?" |
| 35 | + |
| 36 | + options="\"Delete directory contents\" \"Choose another directory\" \"Quit\"" |
| 37 | + eval set $options |
| 38 | + select opt in "$@"; do |
| 39 | + |
| 40 | + if [[ $opt = "Delete directory contents" ]]; then |
| 41 | + echo "Deleting $directory contents... " |
| 42 | + rm -rf $directory/* |
| 43 | + elif [[ $opt = "Choose another directory" ]]; then |
| 44 | + echo "Which directory would you like to choose?" |
| 45 | + read directory |
| 46 | + elif [[ $opt = "Quit" ]]; then |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | + |
| 50 | + break; |
| 51 | + done |
| 52 | +done |
| 53 | + |
| 54 | +if [[ ! -d $directory ]]; then |
| 55 | + mkdir -p $directory |
| 56 | +fi |
| 57 | + |
| 58 | + |
| 59 | +echo "Creating session path in $directory with a depth of $depth for session.hash_bits_per_character = $hashbits" |
| 60 | + |
20 | 61 | for i in $hash_chars; do
|
21 |
| - newpath="$1/$i" |
22 |
| - mkdir $newpath || exit 1 |
23 |
| - sh $0 $newpath `expr $2 - 1` $3 |
| 62 | + newpath="$directory/$i" |
| 63 | + mkdir $newpath || exit 1 |
| 64 | + sh $0 $newpath `expr $depth - 1` $hashbits recurse |
24 | 65 | done
|
0 commit comments