63 lines
2.4 KiB
Bash
Executable File
63 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
run_user=$(id -u)
|
|
if [ "$run_user" -eq 0 ]; then
|
|
gopher_atom="/var/gopher/atom.xml"
|
|
|
|
######################################################################
|
|
########################## GOPHER VERSION ###########################
|
|
######################################################################
|
|
|
|
# Add header info to xml output
|
|
{
|
|
printf "<?xml version=\"1.0\" encoding=\"utf-8\"?>\\n"
|
|
printf "<feed xmlns=\"http://www.w3.org/2005/Atom\">\\n"
|
|
printf "<title>Cosmic Voyage</title>\\n"
|
|
printf "<subtitle>Messages from the human stellar diaspora</subtitle>\\n"
|
|
printf "<link rel=\"alternate\" href=\"gopher://cosmic.voyage/\"/>\\n"
|
|
printf "<link rel=\"self\" href=\"gopher://cosmic.voyage/atom.xml\" />\\n"
|
|
firstlog=$(head -n1 "/var/gopher/listing.gophermap" | awk -F'\t' '{print $2}')
|
|
printf "<updated>%s</updated>\\n" "$(date -d "$(stat -c %y "/var/gopher${firstlog}")" +'%Y-%m-%dT%H:%M:%SZ')"
|
|
printf "<rights>©2021 All rights reserved</rights>\\n"
|
|
printf "<id>gopher://cosmic.voyage/</id>\\n"
|
|
} > "${gopher_atom}"
|
|
|
|
xml_escape_script='s/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
|
|
|
|
# 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 -e 's|^.||' -e "$xml_escape_script")
|
|
owner=$(stat -c %U "/var/gopher${log}")
|
|
|
|
# print item entry for each log
|
|
{
|
|
printf "<entry>\\n"
|
|
printf " <title>%s</title>\\n" "$title"
|
|
printf " <author>\\n"
|
|
printf " <name>%s</name>\\n" "$owner"
|
|
printf " </author>\\n"
|
|
printf " <link rel=\"alternate\" href=\"gopher://cosmic.voyage/0%s\"/>\\n" "$(printf "%s" "$log" | sed 's|\ |%20|g')"
|
|
printf " <id>gopher://cosmic.voyage/0%s</id>\\n" "$(printf "%s" "$log" | sed 's|\ |%20|g')"
|
|
printf " <updated>%s</updated>\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%Y-%m-%dT%H:%M:%SZ')"
|
|
printf " <content type=\"html\"><![CDATA[<pre>\\n"
|
|
sed "$xml_escape_script" "/var/gopher${log}"
|
|
printf "</pre>]]></content>\\n"
|
|
printf "</entry>\\n"
|
|
|
|
} >> "${gopher_atom}"
|
|
fi
|
|
done < "/var/gopher/listing.gophermap"
|
|
|
|
# close up the footer
|
|
{
|
|
printf "</feed>\\n"
|
|
} >> "${gopher_atom}"
|
|
|
|
else
|
|
exec sudo "$0" "$@"
|
|
fi
|