-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_category_dirs.sh
executable file
·54 lines (41 loc) · 2.75 KB
/
add_category_dirs.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
source ${0%/*}/config
#GROUP_CONCAT(name, '/') AS path could be an alternative
sqlite3 -separator '/' $database "select * from (select distinct a.name,b.name,c.name,d.name from category as a inner join category as b on a.id=b.parent inner join category as c on b.id=c.parent inner join category as d on c.id=d.parent where a.parent=0 and a.zone in (select zone from zones where zones=$zones) and b.zone in (select zone from zones where zones=$zones) and c.zone in (select zone from zones where zones=$zones) and d.zone in (select zone from zones where zones=$zones) union select distinct a.name,b.name,c.name,'' from category as a inner join category as b on a.id=b.parent inner join category as c on b.id=c.parent where a.parent=0 and a.zone in (select zone from zones where zones=$zones) and b.zone in (select zone from zones where zones=$zones) and c.zone in (select zone from zones where zones=$zones) union select distinct a.name,b.name,'','' from category as a inner join category as b on a.id=b.parent where a.parent=0 and a.zone in (select zone from zones where zones=$zones) and b.zone in (select zone from zones where zones=$zones) union select distinct a.name,'','','' from category as a where a.parent=0 and a.zone in (select zone from zones where zones=$zones)) order by 1,2,3,4;" > $ramdisk/category_dirs
sqlite3 -separator ' ' $database "select category.name, category_alias.name from category, category_alias where category.id=category_alias.category_id and category.zone in (select zone from zones where zones=$zones);" > $ramdisk/category_dir_alias
rm -r $ramdisk/category/* 2> /dev/null
mkdir $ramdisk/category 2> /dev/null
cd $ramdisk/category || exit
if [[ $category_flat_mode != 1 ]] ; then
while read line
do
mkdir -p ./"$line" 2> /dev/null
done < $ramdisk/category_dirs
while read line
do
cd `echo $line | awk '{printf "%s ",$1 }' | xargs find -name`/.. >> /dev/null || exit #landet eine Ebene unter der Kategorie
ln -s $line 2> /dev/null
cd - >> /dev/null || exit
done < $ramdisk/category_dir_alias
fi
if [[ $category_flat_mode > 0 ]] ; then
cd $ramdisk/category || exit
while read line
do
touch "`basename $line`" 2> /dev/null
done < $ramdisk/category_dirs
while read line
do
ln -s $line 2> /dev/null
done < $ramdisk/category_dir_alias
fi
# Systemkategorien in zone=0 anlegen (sollen sonst nicht angezeigt werden)
#touch $ramdisk/category/done
touch $ramdisk/category/use_clipboard
# clean up dead links
find $ramdisk/category -type l -! -exec test -e {} \; -print | xargs rm #TODO prevent creation of dead links
cd $ramdisk/
ln -s ${0%/*}/config config 2> /dev/null
ln -s ${0%/*}/tag_items_in_folder tag_items_in_folder.sh 2> /dev/null
ln -s ${0%/*}/update_infos update_infos.sh 2> /dev/null
ln -s ${0%/*}/update_files update_files.sh 2> /dev/null