From 1d14028ba0b958d32f4d6f1e3d347ebb8e86abd0 Mon Sep 17 00:00:00 2001 From: Ken Fallon Date: Tue, 24 Dec 2024 13:12:28 +0100 Subject: [PATCH] Add two untracked scripts --- bin/hpr-assets.bash | 51 +++++++++++++++++++++++++++++++++++++++++ bin/hpr_ccdn_stats.bash | 4 ++++ 2 files changed, 55 insertions(+) create mode 100755 bin/hpr-assets.bash create mode 100644 bin/hpr_ccdn_stats.bash diff --git a/bin/hpr-assets.bash b/bin/hpr-assets.bash new file mode 100755 index 0000000..f1b2bdf --- /dev/null +++ b/bin/hpr-assets.bash @@ -0,0 +1,51 @@ +#!/bin/bash + +file_dir="/var/IA/uploads" + +#$allowed_extensions = "flac", "opus", "ogg", "spx", "mp3", "jpg", "png", "json", "srt", "tsv", "txt", "vtt"; + +if [ -d "${file_dir}" ] +then + cd "${file_dir}" + echo '"episode_id","filename","extension","size", "sha1sum", "mime_type", "file_type"' | tee "${file_dir}/assets.csv" + find "${file_dir}" -type f \( -iname "hpr*.wav" -o -iname "hpr*.flac" -o -iname "hpr*.opus" -o -iname "hpr*.ogg" -o -iname "hpr*.spx" -o -iname "hpr*.mp3" -o -iname "hpr*.jpg" -o -iname "hpr*.png" -o -iname "hpr*.json" -o -iname "hpr*.srt" -o -iname "hpr*.tsv" -o -iname "hpr*.txt" -o -iname "hpr*.vtt" \) | while read this_file + do + this_file_basename=$( basename "${this_file}" ) + this_file_dirname=$( dirname "${this_file}" ) + this_file_prefix="${this_file_basename%.*}" + this_file_extension="${this_file_basename##*.}" + if [ "$( echo "${this_file_prefix}" | grep -Ec '^hpr[0-9]{4}' )" -ne "1" ] + then + continue + fi + + this_file_episode_id="$( echo "${this_file_prefix}" | sed 's/hpr//g' | awk -F '_' '{print $1}' )" + if [ "${this_file_episode_id}" -lt "1" ] + then + continue + fi + + if [ "${this_file_episode_id}" -gt "99999" ] + then + continue + fi + + this_file_size="$( ls -al "${this_file}" | awk '{print $5}' )" + this_file_sha1sum="$( sha1sum "${this_file}" | awk '{print $1}' )" + this_file_mime_type=$( file --dereference --brief --mime "${this_file}" ) + this_file_file_type=$( file --dereference --brief "${this_file}" ) + + echo "${this_file_episode_id},\"${this_file_basename}\",\"${this_file_extension}\",\"${this_file_size}\",\"${this_file_sha1sum}\",\"${this_file_mime_type}\",\"${this_file_file_type}\"" | tee --append "${file_dir}/assets.csv" + + done +fi + +if [ -s "${file_dir}/assets.csv" ] +then + cat "${file_dir}/assets.csv" | csvtojson | jq '{"assets":[.[]]}' | tee "${file_dir}/assets.json" +fi + +if [ -s "${file_dir}/assets.json" ] +then + curl --netrc-file $HOME/.netrc --verbose --request POST https://hub.hackerpublicradio.org/cms/assets.php --data-ascii @"${file_dir}/assets.json" --header "Content-Type: application/json" +fi diff --git a/bin/hpr_ccdn_stats.bash b/bin/hpr_ccdn_stats.bash new file mode 100644 index 0000000..bbab7af --- /dev/null +++ b/bin/hpr_ccdn_stats.bash @@ -0,0 +1,4 @@ +#!/bin/bash + +yesterday="$( \date -u +%Y-%m-%d -d yesterday)" +echo -e "${yesterday}\t$( grep -Ec "${yesterday}T.*Sending request to" /home/hpr/logs/naughty-ip.txt )" >> /home/hpr/hub/hpr_ccdn_stats.tsv