#!/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; 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; 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