--- /dev/null
+
+#!/usr/bin/env bash
+#################################################################################
+#
+# NB 01.09.16 - (C) 2016 Nicolas Boisselier
+# /Users/nico/ownCloud/var/lib/sqlite/update.sh
+#
+#################################################################################
+
+#set -o errexit
+#set -o nounset
+#set -o pipefail
+#set -o xtrace
+# disable shell expansion so * is passed to each command
+#set -f
+#declare -r NAME="${0##*/}"
+declare -r NAME="$(basename "${0}")"
+declare -r DIR_NAME="$(cd "$(dirname "${0}")"; echo $(pwd))"
+declare -r FILE_NAME="${DIR_NAME}/${NAME}"
+
+################################################################################
+#
+# Default value options
+#
+#################################################################################
+VERBOSE=0
+DEBUG=0
+
+################################################################################
+#
+# Functions
+#
+#################################################################################
+usage() {
+echo "
+=head1 NAME
+
+${NAME}
+
+=head1 SYNOPSIS
+
+Update all sqlite *.db files in the current directory
+
+ -v, --verbose Print verbose mode
+ -d, --debug Print debug messages
+ -h, --help Print this help (alternatives: --man, --help2man)
+
+=head1 LICENSE
+
+Copyright (C) 2016 Nicolas Boisselier
+
+This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+See <http://www.gnu.org/licenses/>.
+
+=head1 AUTHOR
+
+Nicolas Boisselier nicolas.boisselier@gmail.com
+"
+}
+
+err() {
+ exit_code=$1
+ msg=$2
+ echo "ERR: $msg" >&2
+ exit $exit_code
+}
+
+warn() {
+ msg=$1
+ echo "WARN: $msg" >&2
+}
+
+verbose() {
+ msg=$1
+
+ level=$2
+ [ -z "$level" ] && level=1
+ level=$(($level-1))
+
+ [ "$VERBOSE" -gt "$level" ] || return
+
+ echo "VERBOSE: $msg" >&2
+}
+
+#################################################################################
+#
+# Args
+#
+#################################################################################
+#shopt -s extglob
+while [ $# -gt 0 ]; do
+
+ case "$1" in
+
+ -*help|-h) usage | pod2text --width 250; exit 0 ;;
+ --man) usage | pod2man | man -l -; exit 0 ;;
+ --help2man) usage | pod2man; exit 0 ;;
+
+ --verbose|-v) VERBOSE=$(($VERBOSE+1)) ;;
+
+ --debug|-d) DEBUG=$(($DEBUG+1)) ;;
+
+ *) echo "Unknow option: $1 at $0!"; exit -1; ;;
+
+ esac
+ shift
+
+done
+
+#################################################################################
+#
+# Main
+#
+#################################################################################
+. "$NB_ROOT/etc/profile" || exit
+cd "$DIR_NAME" || exit
+
+TMP_DIR="/tmp"
+[ -w "/dev/shm" ] && TMP_DIR="/dev/shm"
+TMP_DB="$TMP_DIR/$NAME.$$"
+
+IFS=$'\n'
+for vars in $(dbq a=ls type='!sqlite' out=sh); do
+ eval "$vars"
+ [ -z "$id" ] && continue
+
+ [ -w "$id.db" ] || continue
+ [ "$VERBOSE" -gt 0 ] && printf '%s : ' "$id"
+
+ dbq2sqlite db="$id" > "$TMP_DB" || continue
+
+ [ "$VERBOSE" -gt 0 -a ! -s "$TMP_DB" ] && echo "failed"
+ [ -s "$TMP_DB" ] || continue
+
+ if [ -z "$(diff -qs "$id.db" "$TMP_DB" &> /dev/null)" ] ; then
+ [ "$VERBOSE" -gt 0 ] && echo "already"
+ continue
+ fi
+
+ mv "$TMP_DB" "$id.db"
+ echo "done - $( du -sh "$id.db" | awk '{print $1}' )"
+done
+
+rm -f "$TMP_DIR/$NAME.$$*"