2729 |
toxygen |
1 |
#!/usr/bin/env bash |
|
|
2 |
# |
|
|
3 |
# tidyup.sh |
|
|
4 |
# |
|
|
5 |
# This script will sort create organized directory structure |
|
|
6 |
# from observation files in one directory. |
|
|
7 |
# |
|
|
8 |
# Takes one argument: path to the directory |
|
|
9 |
# |
|
|
10 |
# Returns 0 if sorting succeeds |
|
|
11 |
# Returns 1 if there are no files to sort |
|
|
12 |
# Returns >1 in case of error |
|
|
13 |
# |
|
|
14 |
# before: |
|
|
15 |
# |
|
|
16 |
# | |
|
|
17 |
# | meteor_uflu_130128_0010.jpg |
|
|
18 |
# | meteor_uflu_130128_0011.jpg |
|
|
19 |
# | meteor_uflu_130128_1310.jpg |
|
|
20 |
# | meteor_uflu_130129_1112.jpg |
|
|
21 |
# | meteor_uflu_130129_1113.jpg |
|
|
22 |
# | . |
|
|
23 |
# | . |
|
|
24 |
# | . |
|
|
25 |
# |
|
|
26 |
# after: |
|
|
27 |
# |
|
|
28 |
# | |
|
|
29 |
# |- uflu <- observatory |
|
|
30 |
# | |- 2013 <- year |
|
|
31 |
# | |- 01 <- month |
|
|
32 |
# | |- 28 <- day |
|
|
33 |
# | | |- 00 <- hour |
|
|
34 |
# | | | |- meteor_uflu_130128_0010.jpg |
|
|
35 |
# | | | |- meteor_uflu_130128_0011.jpg |
|
|
36 |
# | | | |
|
|
37 |
# | | |- 13 |
|
|
38 |
# | | |- meteor_uflu_130128_1310.jpg |
|
|
39 |
# | | |
|
|
40 |
# | |- 29 |
|
|
41 |
# | | |- 11 |
|
|
42 |
# | |- meteor_uflu_130129_0012.jpg |
|
|
43 |
# | |- meteor_uflu_130129_0012.jpg |
|
|
44 |
# . |
|
|
45 |
# . |
|
|
46 |
# . |
|
|
47 |
# |
|
|
48 |
# |
|
|
49 |
# filename format must be as meteor_uflu_130128_0010.jpg |
|
|
50 |
|
|
|
51 |
EXT=jpg |
|
|
52 |
DELIM="_" |
|
|
53 |
SLASH="/" |
|
|
54 |
LAST="" |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
# turn on debug |
|
|
58 |
set -x |
|
|
59 |
|
|
|
60 |
# none or 1 argument allowed |
|
|
61 |
[[ "$#" -ne 1 ]] && echo "Wrong number of arguments ($#)" && exit 1 |
|
|
62 |
|
|
|
63 |
# directory in which to sort must exists |
|
|
64 |
[[ ! -d "$1" ]] && echo "Directory doesn't exist" && exit 1 |
|
|
65 |
cd $1 |
|
|
66 |
|
|
|
67 |
# if there are no files with $EXT extension in the directory then quit |
|
|
68 |
ls -f *.$EXT > /dev/null 2>&1 |
2730 |
toxygen |
69 |
if [ "$?" -eq 0 ]; then |
|
|
70 |
for i in *.$EXT; do |
|
|
71 |
echo "processing " $i |
|
|
72 |
PREFIX=`echo $i | cut -d $DELIM -f1,2` |
|
|
73 |
OBSERVATORY=`echo $PREFIX | cut -d $DELIM -f2` |
|
|
74 |
POSTFIX=`echo $i | cut -d $DELIM -f4` |
|
|
75 |
|
|
|
76 |
TIMESTAMP=`echo "$i" | cut -d $DELIM -f3` |
|
|
77 |
YEAR=20`echo "$TIMESTAMP" | cut -c 1-2` |
|
|
78 |
MONTH=`echo "$TIMESTAMP" | cut -c 3-4` |
|
|
79 |
DAY=`echo "$TIMESTAMP" | cut -c 5-6` |
|
|
80 |
HOUR=`echo "$POSTFIX" | cut -c 1-2` |
|
|
81 |
|
2729 |
toxygen |
82 |
# observatory / year / month / day / hour |
2730 |
toxygen |
83 |
DAYDIR="$OBSERVATORY$SLASH$YEAR$SLASH$MONTH$SLASH$DAY$SLASH$HOUR" |
|
|
84 |
|
2729 |
toxygen |
85 |
# create directory with observatory name, year, month and day if hasn't existed before |
2730 |
toxygen |
86 |
[[ -d "$DAYDIR" ]] || mkdir -p "$DAYDIR" |
|
|
87 |
|
|
|
88 |
mv "$i" "$DAYDIR" |
|
|
89 |
done |
2729 |
toxygen |
90 |
|
2730 |
toxygen |
91 |
echo -n "$OBSERVATORY$SLASH$YEAR$SLASH$MONTH$SLASH$DAY" > LAST |
|
|
92 |
else |
|
|
93 |
echo "No image files to sort" |
|
|
94 |
fi |
2729 |
toxygen |
95 |
|
2730 |
toxygen |
96 |
DIR="bolids" |
2729 |
toxygen |
97 |
|
2730 |
toxygen |
98 |
ls -f *.wav > /dev/null 2>&1 |
|
|
99 |
if [ "$?" -eq 0 ]; then |
|
|
100 |
for i in bolid_*.wav; do |
|
|
101 |
echo "processing bolid " $i |
|
|
102 |
|
|
|
103 |
PREFIX=`echo $i | cut -d $DELIM -f1,2` |
|
|
104 |
OBSERVATORY=`echo $PREFIX | cut -d $DELIM -f2` |
|
|
105 |
TIMESTAMP=`echo "$i" | cut -d $DELIM -f3` |
|
|
106 |
YEAR=20`echo "$TIMESTAMP" | cut -c 1-2` |
|
|
107 |
OUTDIR="$OBSERVATORY$SLASH$DIR$SLASH$YEAR" |
|
|
108 |
|
|
|
109 |
[[ -d "$OUTDIR" ]] || mkdir -p "$OUTDIR" |
|
|
110 |
mv $i "$OUTDIR" |
|
|
111 |
done |
|
|
112 |
else |
|
|
113 |
echo "No wav files to sort" |
|
|
114 |
fi |
|
|
115 |
|
|
|
116 |
ls -f *.aux > /dev/null 2>&1 |
|
|
117 |
if [ "$?" -eq 0 ]; then |
|
|
118 |
for i in bolid_*.aux; do |
|
|
119 |
echo "processing bolid metadata " $i |
|
|
120 |
|
|
|
121 |
PREFIX=`echo $i | cut -d $DELIM -f1,2` |
|
|
122 |
OBSERVATORY=`echo $PREFIX | cut -d $DELIM -f2` |
|
|
123 |
TIMESTAMP=`echo "$i" | cut -d $DELIM -f3` |
|
|
124 |
YEAR=20`echo "$TIMESTAMP" | cut -c 1-2` |
|
|
125 |
OUTDIR="$OBSERVATORY$SLASH$DIR$SLASH$YEAR" |
|
|
126 |
|
|
|
127 |
[[ -d "$OUTDIR" ]] || mkdir -p "$OUTDIR" |
|
|
128 |
mv $i "$OUTDIR" |
|
|
129 |
done |
|
|
130 |
else |
|
|
131 |
echo "No aux files to sort" |
|
|
132 |
fi |
|
|
133 |
|
2729 |
toxygen |
134 |
exit 0 |
|
|
135 |
|
|
|
136 |
|
2730 |
toxygen |
137 |
|