#!/bin/bash

BACKUP_TYPE="networkmonitor.*.db|.*.FTP|.*.WEBDAV|.*.HTTP"

search_func()
{
    echo "Searching for files with $BACKUP_TYPE"
    FOUND+=($(ls files/ | grep -E "$BACKUP_TYPE")) 
    echo "Found the following .db files:"
    echo ${FOUND[*]}
}

# Merge the found databases into one
merge_databases()
{
    for a in ${FOUND[*]}; do
        python2.7 merger.py ${a}
    done
}

# Creates the database/functions/views if not created before
($(sqlite3 my_db.db < schema.sql))

# Creates the log file if it does not exists
if [ ! -f log ]; then
    ($(touch log))
fi

search_func
merge_databases

exit
