#!/bin/bash # parse ini file CONFIG_FILE="config.ini" # copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \ -e 's/;.*$//' \ -e 's/\[.*\]//' \ -e 's/[[:space:]]*$//' \ -e 's/^[[:space:]]*//' \ -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \ < $CONFIG_FILE ` LOCALDB=$fspotdb REMOTEDB=$origdb dbprefix=${dbprefix//\//\\\/} # end parsing function usage () { echo "TODO: use comma seperate tags for --include=... and/or --exclude=..." } # parse command line CL_INCLUDE="" CL_EXCLUDE="" for i in "$@"; do case $i in --include=*) CL_INCLUDE=${i#*=} ;; --exclude=*) CL_EXCLUDE=${i#*=} ;; -h|--help) usage ;; esac done # check database version, exit if different from what we expect DBVERSION=`sqlite3 $REMOTEDB 'select data from meta where name="F-Spot Database Version"'` if [ x"$DBVERSION" != "x18" ] ; then echo "The database is from a different F-spot version (database version $DBVERSION) that is not implemented." echo "Check TODO for a newer version or file a bug-report at: TODO" exit 2 fi # join tags together in a list of comma seperated quoted strings, so that they can be used in DB queries INCLUDE="'${CL_INCLUDE/,/','}'" EXCLUDE="'${CL_EXCLUDE/,/','}'" if [ "x$INCLUDE" != "x" ] ; then echo "only including pictures with tags: $INCLUDE" fi if [ "x$EXCLUDE" != "x" ] ; then echo "excluding all pictures with tags: $EXCLUDE" fi if [ "x$EXCLUDE" == "x" -a "x$INCLUDE" == "x" ] ; then echo "using all pictures from the database" fi # test if localdb already exist: # yes: # see if photo-db is newer? yes: merge them; no: do nothing # no: # create it cp $REMOTEDB $LOCALDB ExcludeTags="" if [ "x$EXCLUDE" != "x" ] ; then ExcludeTags="insert into rmphotoids select photo_id from photo_tags where tag_id in (select id from tags where name in ($EXCLUDE));" fi # delete all photo related information that we don't want to keep in case INCLUDE tags were given sqlite3 $LOCALDB <