aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_fs
blob: 527a78b007ae0791c4cfc263432d415f08f2b00f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

_ak_fs_return_hash_path(){
    hashpath="$(echo -n "$1" |sed 's/./&\//g;s/\/$//g')"
    echo -n "$hashpath"
}

_ak_fs_return_hash_dir(){
    hashdir="$(echo -n "$1" | sed -e 's/./&\//g' | grep '\(./\)\{128\}' | sed -e 's/..$//')"
    echo -n "$hashdir"
}

_ak_fs_verify_input_is_hash(){
    if [ ! -z "$1" ] && echo "$1" | grep '[0123456789abcdef]\{128\}' > /dev/null 2>&1
    then
        return 0
    else
        echo "no hash?!" >&2
        exit 1
    fi
}

_ak_fs_create_dir_for_hash(){
    _ak_fs_verify_input_is_hash $2
    if [ ! -z $1 ] && [ ! -z $2 ] && [ -n "$1" ] && [ -n "$2" ]
    then
        mkdir -p "$1/$(_ak_fs_return_hash_dir $2)"
    fi
}