Cron automations

This commit is contained in:
2025-09-21 19:19:20 +02:00
parent 8efc6459c3
commit d19fe2e4bf
5 changed files with 131 additions and 17 deletions

26
workflow/check_feeds.bash Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
feed_dir="$HOME/tmp/hpr/rss"
wget https://hackerpublicradio.org/hpr_opus_rss.php -O "${feed_dir}/2_opus.xml"
wget https://hackerpublicradio.org/hpr_ogg_rss.php -O "${feed_dir}/2_ogg.xml"
wget https://hackerpublicradio.org/hpr_rss.php -O "${feed_dir}/2_mp3.xml"
wget https://hackerpublicradio.org/hpr_total_opus_rss.php -O "${feed_dir}/f_opus.xml"
wget https://hackerpublicradio.org/hpr_total_ogg_rss.php -O "${feed_dir}/f_ogg.xml"
wget https://hackerpublicradio.org/hpr_total_rss.php -O "${feed_dir}/f_mp3.xml"
wget https://hackerpublicradio.org/rss-future.php -O "${feed_dir}/ff.xml"
wget https://hackerpublicradio.org/comments.rss -O "${feed_dir}/comments.xml"
cd "${feed_dir}"
for feed in *.xml
do
echo "Checking ${feed}"
xmllint --format "${feed}" >/dev/null 2>&1
if [ "${?}" -ne "0" ]
then
echo "Error: The rss feed \"${feed}\" is not correct"
xmllint --format "${feed}"
exit 1
fi
done

View File

@@ -0,0 +1,8 @@
#!/bin/bash
# 6,21,36,51 * * * * /docker/users/hpr/userfiles/bin/export-jsons-stats.bash > /dev/null 2>&1 &
net_rc="$HOME/userfiles/.netrc"
output_file="$HOME/hub.hackerpublicradio.org/public_html/stats.json"
curl --silent --netrc-file ${net_rc} https://hub.hackerpublicradio.org/cms/stats.php --output "${output_file}"

View File

@@ -2,16 +2,80 @@
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
#============================================================
git_dir="$HOME/tmp/hpr/hpr_generator/sourcecode"
if [ ! -d "${git_dir}/.git" ]
working_dir="$HOME/tmp/hpr/hpr_generator/sourcecode"
hpr_sql_rss="${working_dir}/hpr_sql_rss.xml"
previous_update_txt="${working_dir}/last_update.txt"
if [ ! -d "${working_dir}/.git" ]
then
git clone gitea@repo.anhonesthost.net:HPR/hpr_generator.git "${git_dir}"
mkdir --parents --verbose "${working_dir}"
git clone gitea@repo.anhonesthost.net:HPR/hpr_generator.git "${working_dir}"
fi
cd "${git_dir}"
cd "${working_dir}"
git pull
function get_latest_update_time() {
if [ "$( curl --silent --netrc-file ${HOME}/.netrc --write-out '%{http_code}' https://hackerpublicradio.org/hpr.sql.rss --output "${hpr_sql_rss}" )" != 200 ]
then
echo "Could not get a list of the queue status from \"https://hackerpublicradio.org/hpr.sql.rss\""
fi
if [[ ! -s "${hpr_sql_rss}" || -z "${hpr_sql_rss}" ]]
then
echo "The \"hpr_sql_rss\" variable/file is missing."
exit
fi
if [ "$( file --brief --mime-type "${hpr_sql_rss}" | grep --count 'text/xml' )" -ne "1" ]
then
echo "The \"hpr_sql_rss\" variable has not a valid \"text/xml\" mime type."
exit
fi
xmllint --format "${hpr_sql_rss}" >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "The file \"${hpr_sql_rss}\" is not valid xml."
exit
fi
current_update_iso8601="$( \date --utc --date="$( xmlstarlet sel --text --template --match '/rss/channel/pubDate' --value-of '.' --nl "${hpr_sql_rss}" )" +%Y-%m-%dT%H:%M:%SZ )"
if [ -z "${current_update_iso8601}" ]
then
echo "The \"current_update_iso8601\" variable is missing."
exit
fi
current_update_epoch="$( \date --utc --date="${current_update_iso8601}" +%s )"
if [ -z "${current_update_epoch}" ]
then
echo "The \"current_update_epoch\" variable/file is missing."
exit
fi
echo -e "Current update time is\t${current_update_iso8601} (${current_update_epoch})"
if [ -s "${previous_update_txt}" ]
then
#echo "Found the last update file \"${previous_update_txt}\""
previous_update_iso8601="$( \date --utc --date="$( cat "${previous_update_txt}" )" +%Y-%m-%dT%H:%M:%SZ )"
previous_update_epoch="$( \date --utc --date="$( cat "${previous_update_txt}" )" +%s )"
else
#echo "Did not find the last update file \"${previous_update_txt}\""
previous_update_iso8601=""
previous_update_epoch="0"
fi
echo -e "Previous update time is\t${previous_update_iso8601} (${previous_update_epoch})"
echo "${current_update_iso8601}" > "${previous_update_txt}"
}
get_latest_update_time
# if [ "${current_update_epoch}" -eq "previous_update_epoch"
# exit
# ssh hpr -t "ls -al /home/hpr/www/hpr.sql;md5sum /home/hpr/www/hpr.sql"
# ssh hpr -t "/home/hpr/bin/hpr_db_backup.bash"
# ssh hpr -t "ls -al /home/hpr/www/hpr.sql;md5sum /home/hpr/www/hpr.sql"
@@ -30,15 +94,30 @@ then
exit 1
fi
rsync -av --partial --progress "${git_dir}/public_html/" hpr:hackerpublicradio.org/public_html
#rsync -av --partial --progress "${git_dir}/public_html/" hobbypublicradio.org:hobbypublicradio.org/
cd "${working_dir}/public_html"
cd $HOME/sourcecode/hpr/hpr_hub/
git pull
cd $HOME/sourcecode/hpr/hpr_hub/sql
split --hex-suffixes --lines=1000 --additional-suffix=.sql hpr.sql hpr-db-part-
cd $HOME/sourcecode/hpr/hpr_hub/
git add $HOME/sourcecode/hpr/hpr_hub/sql/hpr*sql
git commit -m "$(\date -u +%Y-%m-%d_%H-%M-%SZ_%A ) database changed"
git push
#xdg-open https://hackerpublicradio.org/
for feed in comments.rss
do
xmllint --format "${feed}" >/dev/null 2>&1
if [ "${?}" -ne "0" ]
then
echo "Error: The rss feed \"${feed}\" is not correct"
xmllint --format "${feed}"
exit 1
fi
done
cd "${working_dir}"
rsync -av --partial --progress "${working_dir}/public_html/" hpr:hackerpublicradio.org/public_html
#rsync -av --partial --progress "${working_dir}/public_html/" hobbypublicradio.org:hobbypublicradio.org/
# # # cd $HOME/sourcecode/hpr/hpr_hub/
# # # git pull
# # # cd $HOME/sourcecode/hpr/hpr_hub/sql
# # # split --hex-suffixes --lines=1000 --additional-suffix=.sql hpr.sql hpr-db-part-
# # # cd $HOME/sourcecode/hpr/hpr_hub/
# # # git add $HOME/sourcecode/hpr/hpr_hub/sql/hpr*sql
# # # git commit -m "$(\date -u +%Y-%m-%d_%H-%M-%SZ_%A ) database changed"
# # # git push
# # # #xdg-open https://hackerpublicradio.org/

View File

@@ -2,6 +2,8 @@
# 5,20,35,50 * * * * $HOME/userfiles/sql/hpr_db_backup.bash >> $HOME/userfiles/sql/cron.log 2>&1 &
# https://hackerpublicradio.org/hpr.sql.rss
#TODO
#add a rss feed with the latest updates. Linking to the changes on gittea.
# run that every 5 minutes and then if there is a change sleep 5 and confirm there has been no change since.

View File

@@ -719,7 +719,6 @@ function get_working_dir() {
}
#################################################
# Once the working_dir is known, set the other variables