From 57b63f7e4683e3e0cedb143cf07a1859c2082ef7 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Sat, 6 Mar 2021 11:47:28 +0000 Subject: [PATCH] atom feed added in addition to rss in all environments --- bin/atom | 112 +++++++++++++++++++++++++++++++++++++ bin/gemini | 3 +- bin/rss | 41 ++++++++------ bin/web | 10 +++- templates/geminiintro.tmpl | 1 + 5 files changed, 146 insertions(+), 21 deletions(-) create mode 100755 bin/atom diff --git a/bin/atom b/bin/atom new file mode 100755 index 0000000..9e3bd3b --- /dev/null +++ b/bin/atom @@ -0,0 +1,112 @@ +#!/bin/sh + +run_user=$(id -u) +if [ "$run_user" -eq 0 ]; then + file_atom="/var/www/html/atom.xml" + gopher_atom="/var/gopher/atom.xml" + + ###################################################################### + ############################# HTML VERSION ########################### + ###################################################################### + + # Add header info to xml output + { + printf "\\n" + printf "\\n" + printf "Cosmic Voyage\\n" + printf "Messages from the human stellar diaspora\\n" + printf "\\n" + printf "\\n" + firstlog=$(head -n1 "/var/gopher/listing.gophermap" | awk -F'\t' '{print $2}') + printf "%s\\n" "$(date -d "$(stat -c %y "/var/gopher${firstlog}")" +'%Y-%m-%dT%H:%M:%SZ')" + printf "©2021 All rights reserved\\n" + printf "https://cosmic.voyage/\\n" + } > "${file_atom}" + + # Loop through listings gophermap + loop=0 + while read -r line; do + loop=$((loop+1)) + if [ "$loop" -lt 20 ]; then + 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 "\\n" + printf " %s\\n" "$title" + printf " \\n" + printf " %s\\n" "$owner" + printf " \\n" + printf " \\n" "$(printf "%s" "$log" | sed 's|.txt$|.html|' | sed 's|\ |%20|g')" + printf " https://cosmic.voyage%s\\n" "$(printf "%s" "$log" | sed 's|.txt$|.html|' | sed 's|\ |%20|g')" + printf " %s\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%Y-%m-%dT%H:%M:%SZ')" + printf " \\n" + sed 's/&/\&/g; s//\>/g; s/"/\"/g; s/'"'"'/\'/g' "/var/gopher${log}" + printf "]]>\\n" + printf "\\n" + + } >> "${file_atom}" + fi + done < "/var/gopher/listing.gophermap" + + # close up the footer + { + printf "\\n" + } >> "${file_atom}" + + ###################################################################### + ########################## GOPHER VERSION ########################### + ###################################################################### + + # Add header info to xml output + { + printf "\\n" + printf "\\n" + printf "Cosmic Voyage\\n" + printf "Messages from the human stellar diaspora\\n" + printf "\\n" + printf "\\n" + firstlog=$(head -n1 "/var/gopher/listing.gophermap" | awk -F'\t' '{print $2}') + printf "%s\\n" "$(date -d "$(stat -c %y "/var/gopher${firstlog}")" +'%Y-%m-%dT%H:%M:%SZ')" + printf "©2021 All rights reserved\\n" + printf "gopher://cosmic.voyage/\\n" + } > "${gopher_atom}" + + # Loop through listings gophermap + loop=0 + while read -r line; do + loop=$((loop+1)) + if [ "$loop" -lt 20 ]; then + 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 "\\n" + printf " %s\\n" "$title" + printf " \\n" + printf " %s\\n" "$owner" + printf " \\n" + printf " \\n" "$(printf "%s" "$log" | sed 's|\ |%20|g')" + printf " gopher://cosmic.voyage/0%s\\n" "$(printf "%s" "$log" | sed 's|\ |%20|g')" + printf " %s\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%Y-%m-%dT%H:%M:%SZ')" + printf " \\n" + sed 's/&/\&/g; s//\>/g; s/"/\"/g; s/'"'"'/\'/g' "/var/gopher${log}" + printf "]]>\\n" + printf "\\n" + + } >> "${gopher_atom}" + fi + done < "/var/gopher/listing.gophermap" + + # close up the footer + { + printf "\\n" + } >> "${gopher_atom}" + +else + exec sudo "$0" "$@" +fi diff --git a/bin/gemini b/bin/gemini index bca3947..b4c6b4a 100755 --- a/bin/gemini +++ b/bin/gemini @@ -16,6 +16,7 @@ if [ "$run_user" = "gemini" ]; then curl -s gopher://localhost/1/log | /var/cosmic/awk/gophermap2gemini.awk > /var/gemini/log/index.gmi curl -s gopher://localhost/1/ships | /var/cosmic/awk/gophermap2gemini.awk > /var/gemini/ships/index.gmi sed 's?gopher://cosmic.voyage/0/?gemini://cosmic.voyage/?' /var/gopher/rss.xml | sed 's?gopher://cosmic.voyage?gemini://cosmic.voyage?' > /var/gemini/rss.xml + sed 's?gopher://cosmic.voyage/0/?gemini://cosmic.voyage/?' /var/gopher/atom.xml | sed 's?gopher://cosmic.voyage?gemini://cosmic.voyage?' > /var/gemini/atom.xml # create ship directories find "/var/gopher/" -maxdepth 1 ! -path "/var/gopher/" ! -path "/var/gopher/ships" ! -path "/var/gopher/log" -type d | sed 's|/var/gopher/||' | sort | while read -r ship @@ -23,7 +24,7 @@ if [ "$run_user" = "gemini" ]; then curl -s "gopher://localhost/1/ships/${ship}" | /var/cosmic/awk/gophermap2gemini.awk > "/var/gemini/ships/${ship}/index.gmi" done # Let user's know it's done - printf "Gemini and gemini RSS rebuilt successfully.\\n" + printf "Gemini and gemini feeds rebuilt successfully.\\n" else exec sudo -u gemini "$0" "$@" fi diff --git a/bin/rss b/bin/rss index 4f32fdd..545c25d 100755 --- a/bin/rss +++ b/bin/rss @@ -64,25 +64,30 @@ if [ "$run_user" -eq 0 ]; then printf "Messages from the human stellar diaspora\\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 "\\n" - printf " %s\\n" "$title" - printf " %s@cosmic.voyage (%s)\\n" "$owner" "$owner" - printf " gopher://cosmic.voyage/0%s\\n" "$log" - printf " gopher://cosmic.voyage/0%s\\n" "$log" - printf " %s GMT\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%a, %d %b %Y %H:%M:%S')" - printf " \\n" - cat "/var/gopher${log}" - printf "]]>\\n" - printf "\\n" - } >> "${gopher_rss}" + # Loop through listings gophermap + loop=0 + while read -r line; do + loop=$((loop+1)) + if [ "$loop" -lt 20 ]; then + 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 "\\n" + printf " %s\\n" "$title" + printf " %s@cosmic.voyage (%s)\\n" "$owner" "$owner" + printf " gopher://cosmic.voyage/0%s\\n" "$log" + printf " gopher://cosmic.voyage/0%s\\n" "$log" + printf " %s GMT\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%a, %d %b %Y %H:%M:%S')" + printf " \\n" + cat "/var/gopher${log}" + printf "]]>\\n" + printf "\\n" + } >> "${gopher_rss}" + fi done < "/var/gopher/listing.gophermap" # close up the footer diff --git a/bin/web b/bin/web index 1253400..356403c 100755 --- a/bin/web +++ b/bin/web @@ -67,6 +67,10 @@ if [ "$run_user" = "root" ] || [ "$run_user" = "publish" ]; then # shellcheck source=rss # shellcheck disable=SC1091 . "${SCRIPTPATH}/rss" + # Generate RSS + # shellcheck source=atom + # shellcheck disable=SC1091 + . "${SCRIPTPATH}/atom" # prep directories mkdir -p "$(dirname "${log_html}")" @@ -78,6 +82,7 @@ if [ "$run_user" = "root" ] || [ "$run_user" = "publish" ]; then printf "Cosmic Voyage - Messages from Humanity's Stellar Diaspora" printf "" printf "" + printf "" printf "" cat "$web_styles_html" printf "" @@ -90,7 +95,8 @@ if [ "$run_user" = "root" ] || [ "$run_user" = "publish" ]; then printf "\\n>> How to Join Cosmic Voyage\\n" printf ">> Complete Transmission Log\\n" printf ">> Ships, Colonies, Outposts\\n" - printf ">> RSS Feed\\n\\n" + printf ">> RSS Feed\\n" + printf ">> Atom Feed\\n\\n" # Logs printf "Most recent log entries:\\n" } >> "${root_index_html}" @@ -318,7 +324,7 @@ if [ "$run_user" = "root" ] || [ "$run_user" = "publish" ]; then printf '{"name": "cosmic.voyage", "url": "https://cosmic.voyage", "signup_url": "https://cosmic.voyage/join.html", "user_count": %s, "want_users": true, "admin_email": "james@tomasino.org", "description": "Cosmic Voyage is a public-access unix system and tilde community based around a collaborative science-fiction universe. Users write stories as the people aboard ships, colonies, and outposts, using the only remaining free, interconnected network that unites the dispersed peoples of the stars.", "users": [%s]}' "$(grep -E '1[0-9]{3}' "/etc/passwd" | grep -c 'home')" "${userlist%?}" > "${html_dir}/tilde.json" # Let user's know it's done - printf "Web and RSS rebuilt.\\n" + printf "Web and Feeds rebuilt.\\n" else exec sudo -u publish "$0" "$@" fi diff --git a/templates/geminiintro.tmpl b/templates/geminiintro.tmpl index 829802a..c77aa47 100644 --- a/templates/geminiintro.tmpl +++ b/templates/geminiintro.tmpl @@ -28,6 +28,7 @@ Cosmic Voyage is a tilde community based around a collaborative science-fiction => gemini://cosmic.voyage/log/ Complete Transmission Log => gemini://cosmic.voyage/ships/ Ships, Colonies, and Outposts => gemini://cosmic.voyage/rss.xml RSS Feed +=> gemini://cosmic.voyage/atom.xml Atom Feed ## Most recent (20) log entries