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