blob: 16d7683ae74b7003e8f9bd7ac757c1eb0094ed80 (
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
30
31
32
33
34
35
36
|
#!/usr/bin/env bash
set -e
if [[ -n "$AUTOMV_DIR" ]]; then
automvdir=$AUTOMV_DIR
else
automvdir=$(dirname "$0")/automv.d
fi
function extract {
local file=$1
local prop=$2
grep "^${prop}=.*$" $file | cut -d '=' -f2
}
function automv {
local query=$1
local source=$2
local target=$3
echo "Moving files in $source that match '$query' to $target"
find $source -type f \( -regex "${query}" ! -iname ".*" \) | xargs -I '{}' mv {} $target/
}
echo "Executing automv functions from $automvdir"
for file in $automvdir/*.conf
do
echo "found $file"
if [[ -f $file ]]; then
# Extract file configs
query=$(extract $file "query")
sourced=$(extract $file "source")
target=$(extract $file "target")
automv $query $sourced $target
fi
done
|