From 6b16b7f9e19b3e682661278397b5e94d5d3c2529 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 2 Sep 2016 00:42:40 +0100 Subject: [PATCH] dir2sqlite --- bin/dbq-dir2sqlite | 147 ++++++++++++++++++++++++++++++++++++++ etc/vim/templates/bash.tt | 2 +- 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100755 bin/dbq-dir2sqlite diff --git a/bin/dbq-dir2sqlite b/bin/dbq-dir2sqlite new file mode 100755 index 00000000..ab2e5d05 --- /dev/null +++ b/bin/dbq-dir2sqlite @@ -0,0 +1,147 @@ + +#!/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 . + +=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.$$*" diff --git a/etc/vim/templates/bash.tt b/etc/vim/templates/bash.tt index f28d9f46..b9b094f3 100644 --- a/etc/vim/templates/bash.tt +++ b/etc/vim/templates/bash.tt @@ -50,7 +50,7 @@ Long description =head1 SEE ALSO -https://intra.semantico.net/wiki/ +http://blog.nbdom.net/ =head1 LICENSE -- 2.47.3