gopher rss

This commit is contained in:
James Tomasino 2018-11-30 15:18:32 -05:00
parent 666fc56092
commit 790c4f24ab
1 changed files with 46 additions and 1 deletions

View File

@ -5,6 +5,10 @@ if [ "$run_user" -eq 0 ]; then
file_rss="/var/www/html/rss.xml"
gopher_rss="/var/gopher/rss.xml"
######################################################################
############################# HTML VERSION ###########################
######################################################################
# Add header info to xml output
{
printf '<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>'
@ -40,7 +44,48 @@ if [ "$run_user" -eq 0 ]; then
printf "</channel>\\n"
printf "</rss>\\n"
} >> "${file_rss}"
cp "${file_rss}" "${gopher_rss}"
######################################################################
########################## GOPHER VERSION ###########################
######################################################################
# Add header info to xml output
{
printf '<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>'
printf '<atom:link href="gopher://cosmic.voyage/0/rss.xml" rel="self" type="application/rss+xml" />'
printf "\\n<title>Cosmic Voyage</title>\\n"
printf "<link>gopher://cosmic.voyage</link>\\n"
printf "<description>Messages from the human stellar diaspora</description>\\n"
} > "${gopher_rss}"
# Loop through listings gophermap
while read -r line; do
log=$(printf "%s" "$line" | awk -F'\t' '{print $2}')
title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||')
owner=$(stat -c %U "/var/gopher${log}")
# print item entry for each log
{
printf "<item>\\n"
printf " <title>%s</title>\\n" "$title"
printf " <author>%s@cosmic.voyage (%s)</author>\\n" "$owner" "$owner"
printf " <link>gopher://cosmic.voyage/0/%s</link>\\n" "$log"
printf " <guid>gopher://cosmic.voyage/0/%s</guid>\\n" "$log"
printf " <pubDate>%s GMT</pubDate>\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%a, %d %b %Y %H:%M:%S')"
printf " <description><![CDATA[\\n"
cat "/var/gopher${log}"
printf "]]></description>\\n"
printf "</item>\\n"
} >> "${gopher_rss}"
done < "/var/gopher/listing.gophermap"
# close up the footer
{
printf "</channel>\\n"
printf "</rss>\\n"
} >> "${gopher_rss}"
else
exec sudo "$0" "$@"
fi