xref: /PHP-5.5/ext/session/mod_files.sh (revision 9d8b1170)
1#!/usr/bin/env bash
2
3if [[ "$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
9fi
10
11if [[ "$2" = "0" ]] && [[ ! "$4" = "recurse" ]]; then
12       echo "Can't create a directory tree with depth of 0, exiting."
13fi
14
15if [[ "$2" = "0" ]]; then
16       exit 0
17fi
18
19directory="$1"
20depth="$2"
21hashbits="$3"
22
23hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
24
25if [[ "$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"
27fi
28
29if [[ "$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 - ,"
31fi
32
33while [[ -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
52done
53
54if [[ ! -d $directory ]]; then
55       mkdir -p $directory
56fi
57
58
59echo "Creating session path in $directory with a depth of $depth for session.hash_bits_per_character = $hashbits"
60
61for i in $hash_chars; do
62       newpath="$directory/$i"
63       mkdir $newpath || exit 1
64       bash $0 $newpath `expr $depth - 1` $hashbits recurse
65done
66