3 # make sure public root and link dirs are declared
4 [[ -z "$PUBLIC_ROOT_DIR" ]] && echo Expected PUBLIC_ROOT_DIR && exit 1
5 [[ -z "$PUBLIC_LINK_DIR" ]] && echo Expected PUBLIC_LINK_DIR && exit 1
7 [[ -z "$1" ]] && echo Expected pattern && exit 1
9 # if pattern matches files from storage,
10 # create nonce directory
11 # create symlinks to matching files
12 nonce=$(head /dev/urandom | sha1sum -b | awk '{print $1}')
13 symlink_dir=$PUBLIC_LINK_DIR/$nonce
15 find $PUBLIC_ROOT_DIR -type f -name "*$1*" | while read fname
17 [[ -d $symlink_dir ]] || mkdir -p $symlink_dir
18 new_fname=$symlink_dir/$(echo $fname | sed 's|^.*/||')
19 ln -s "$fname" "$new_fname"
22 # if nonce directory has been created,
24 # else no links generated, print nothing
25 if [[ -d "$symlink_dir" ]]