#!/bin/bash - #=============================================================================== # # FILE: show_queue # # USAGE: ./show_queue # # DESCRIPTION: Show the pending queue, expanding each album's details from # the database. # # / This version calls sqlite3 repeatedly in a loop / # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com # VERSION: 0.1.1 # CREATED: 2020-09-15 12:38:03 # REVISION: 2020-09-15 12:38:11 # #=============================================================================== set -o nounset # Treat unset variables as an error SCRIPT=${0##*/} #DIR=${0%/*} VERSION='0.1.1' #=== FUNCTION ================================================================ # NAME: cleanup_temp # DESCRIPTION: Cleanup temporary files when a 'trap' command is triggered # PARAMETERS: * - names of temporary files to delete # RETURNS: Nothing #=============================================================================== function cleanup_temp { for tmp in "$@"; do [ -e "$tmp" ] && rm --force "$tmp" done exit 0 } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STDOUT="/dev/fd/2" # # Files and directories # BASEDIR="$HOME/MusicDownloads" DATADIR="$BASEDIR/Magnatune_Data" SCRIPTDIR="$BASEDIR/magnatune-downloader" QUEUE="$SCRIPTDIR/pending" DB="$DATADIR/sqlite_normalized.db" # # Sanity checks # [ -e "$QUEUE" ] || { echo "$QUEUE not found"; exit 1; } # # Check the queue contains data # if [[ ! -s $QUEUE ]]; then echo "$SCRIPT($VERSION): there is nothing in the queue" exit fi # # Make temporary files and set traps to delete them # TMP1=$(mktemp) || { echo "$SCRIPT: creation of temporary file failed!" >$STDOUT; exit 1; } trap 'cleanup_temp $TMP1' SIGHUP SIGINT SIGPIPE SIGTERM EXIT RE='^http://magnatune.com/artists/albums/([A-Za-z0-9-]+)/?$' # # Add a partial SQL query that counts the feeds that match the regex. Store it # in a temporary file # cat > "$TMP1" <