From f28e5ea9263e31005ee6cf245e33b25afd5052e4 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 25 Aug 2021 17:46:48 -0400 Subject: lib/gajim/settings-*: New scripts bin/sqlite3-git-* were more general-purpose scripts in the vcsh dotfiles repository. These scripts are specific for Gajim and use sqlite3 and jq to clean settings.sqlite. --- (limited to 'lib/gajim/settings-clean') diff --git a/lib/gajim/settings-clean b/lib/gajim/settings-clean new file mode 100755 index 0000000..c906ff6 --- /dev/null +++ b/lib/gajim/settings-clean @@ -0,0 +1,75 @@ +#!/bin/sh + +set -eu + +input_to_db() +{ + local input= + local db= + + input="$(mktemp)" || return 1 + cat - 1>"${input}" || { rm -f "${input}"; return 1; } + if file "${input}" | grep -Fq SQLite; then + # Input still a database: use it directly. + db="${input}" + else + # Input already dumped to SQL: enter it into temporary database. + db="$(mktemp)" || { rm -f "${input}"; return 1; } + sqlite3 "${db}" 0<"${input}" || { rm -f "${input}"; return 1; } + rm -f "${input}" || { rm -f "${db}"; return 1; } + fi + + printf '%s' "${db}" + return 0 +} + +clean() +{ + local db="${1}" + shift 1 + + sqlite3 "${db}" "UPDATE account_settings SET $(: \ + )settings = edit(settings, \"${0}-sub-account-settings\");" || \ + return 1 + + return 0 +} + +db_to_sql() +{ + local db="${1}" + shift 1 + + sqlite3 "${db}" '.dump' || return 1 + + return 0 +} + +usage() +{ + printf 'Usage: %s [.= ...]\n' "${0}" + + return 0 +} + +main() +{ + local arg= + local db= + + for arg in "${@}"; do + case "${arg}" in + ?*.?*=?*);; + *) usage 1>&2; return 1;; + esac + done + + db="$(input_to_db)" || return 1 + clean "${db}" || { rm -f "${db}"; return 1; } + db_to_sql "${db}" || { rm -f "${db}"; return 1; } + rm -f "${db}" || return 1 + + return 0 +} + +main "${@}" -- cgit v0.9.1