-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_file.sh
executable file
·53 lines (34 loc) · 1.43 KB
/
add_file.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
# Globale Variablen
SCRIPTNAME=$(basename $0 .sh)
EXIT_SUCCESS=0
EXIT_FAILURE=1
EXIT_ERROR=2
EXIT_BUG=10
#usage
#add_file [name] [Kategorien ...]
source ${0%/*}/config
inode=`find "$1" -maxdepth 0 -type f -printf '%i\n'`
#um discsource automatisch zu bestimmen
disksource=`echo "$1" | awk -F'/' '//{printf "/%s/%s/.diskinfo",$2,$3}' | xargs head -n1`
mediatype=`file -F',' --mime-type "$1" | grep -v application/x-directory | cut -f2 -d','`
mediatype_trim=`sqlite3 $database "select trim('$mediatype')"`
if [[ $VERBOSE = y ]] ; then
echo "mediatype_trim: $mediatype_trim"
fi
filename=`basename "$1"`
next_id=`sqlite3 $database "select coalesce ( (select id from files where name='' order by id limit 1),(select max(id)+1 from files),1 ); "`
sqlite3 $database "delete from files where id=$next_id; "
sqlite3 $database "insert into files (id,name,mediatype,disksource,inode,zone) values ('$next_id','$filename','$mediatype_trim','$disksource',$inode,$zones);"
echo "inserted id: $next_id"
categorys=""
num_categorys=0
categorys="${*:2} `echo ${1%%.*} | sed 's;/; ;g'`" # {1%%.*} file without extension
if [[ $VERBOSE = y ]] ; then
echo -e "\E[35mcategorys: $categorys"; tput sgr0
fi
# 20111115 tag_file wird verwendet um Kategorien oberhalb zu löschen
tag_file "$next_id" $categorys
# 20111115 Abfrage entfernt um es besser in andere Skripte einbauen zu können
#read -n 1 -p "Give custom rating and votes? (Y/n) " choice #
echo ""