4 CONFIG_FILE="config.ini"
6 # copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed
7 eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
10 -e 's/[[:space:]]*$//' \
11 -e 's/^[[:space:]]*//' \
12 -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
17 dbprefix=${dbprefix//\//\\\/}
23 f-spot-db-reduce.sh <options>
25 The script uses config.ini for most of it's input data.
28 --include=<comma separated taglist> include pictures with these tags
29 --exclude=<comma separated taglist> remove pictures with these tags
30 --hide=<comma separated taglist> remove these tags, but leave pictures
57 # check database version, exit if different from what we expect
58 DBVERSION=`sqlite3 $REMOTEDB 'select data from meta where name="F-Spot Database Version"'`
60 if [ x"$DBVERSION" != "x18" ] ; then
61 echo "The database is from a different F-spot version (database version $DBVERSION) that is not implemented."
62 echo "Check TODO for a newer version or file a bug-report at: TODO"
67 # join tags together in a list of comma seperated quoted strings, so that they can be used in DB queries
68 INCLUDE="'${CL_INCLUDE/,/','}'"
69 EXCLUDE="'${CL_EXCLUDE/,/','}'"
70 HIDE="'${CL_HIDE/,/','}'"
72 if [ "x$INCLUDE" != "x" ] ; then
73 echo "only including pictures with tags: $INCLUDE"
76 if [ "x$EXCLUDE" != "x" ] ; then
77 echo "excluding all pictures with tags: $EXCLUDE"
80 if [ "x$HIDE" != "x" ] ; then
81 echo "removing tags: $HIDE"
84 if [ "x$EXCLUDE" == "x" -a "x$INCLUDE" == "x" ] ; then
85 echo "using all pictures from the database"
88 # test if localdb already exist:
90 # see if photo-db is newer? yes: merge them; no: do nothing
97 if [ "x$EXCLUDE" != "x" ] ; then
98 ExcludeTags="insert into rmphotoids select photo_id from photo_tags where tag_id in (select id from tags where name in ($EXCLUDE));"
102 if [ "x$HIDE" != "x" ] ; then
103 HideTags="delete from photo_tags where tag_id in (select id from tags where name in ($HIDE));
104 delete from tags where name in ($HIDE);"
107 # delete all photo related information that we don't want to keep in case INCLUDE tags were given
108 sqlite3 $LOCALDB <<EOF
109 create temp table rmphotoids as select id from photos where id not in (select photo_id from photo_tags where tag_id in (select id from tags where name in ($INCLUDE)));
114 delete from photos where id in (select * from rmphotoids);
115 delete from photo_tags where photo_id in (select * from rmphotoids);
116 delete from photo_versions where photo_id in (select * from rmphotoids);
118 delete from tags where id not in (select distinct tag_id from photo_tags asc);
119 delete from rolls where id not in (select distinct roll_id from photos asc);
121 drop table rmphotoids;