forked from cosmic/cosmic
114 lines
4.1 KiB
Bash
Executable File
114 lines
4.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
run_user=$(id -u)
|
|
if [ "$run_user" -eq 0 ]; then
|
|
file_html="/var/www/html/index.html"
|
|
|
|
# Add standard header
|
|
cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${file_html}"
|
|
# Custom header elements and body start
|
|
{
|
|
printf "<title>Cosmic Voyage</title>"
|
|
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage\">"
|
|
printf "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"Cosmic Voyage\" href=\"/rss.xml\">"
|
|
printf "</head>"
|
|
printf "<body>"
|
|
printf "<div class=\"page-wrapper\">"
|
|
printf "<pre class=\"inner-wrapper\">"
|
|
# Intro text
|
|
cat "/var/gopher/intro.gophermap"
|
|
# Ship listings
|
|
printf "\\n<a href=\"/ships\">🢒 Ships, Colonies, Outposts</a>\\n\\n"
|
|
# Logs
|
|
printf "Transmission Log:\\n"
|
|
} >> "${file_html}"
|
|
# Loop through listings gophermap
|
|
while read -r line; do
|
|
log=$(printf "%s" "$line" | awk -F'\t' '{print $2}')
|
|
loghtml=$(printf "%s" "$log" | sed 's/\.[^.]*$//')
|
|
logdir=$(dirname "$log")
|
|
title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||')
|
|
# print link in listings
|
|
printf "<a href=\"%s.html\">🢒 %s</a>\\n" "$loghtml" "$title" >> "${file_html}"
|
|
|
|
# create entry
|
|
entry_html="/var/www/html${loghtml}.html"
|
|
mkdir -p "/var/www/html${logdir}"
|
|
cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${entry_html}"
|
|
{
|
|
printf " <title>%s</title>\\n" "$title"
|
|
printf " <link rel=\"canonical\" href=\"https://cosmic.voyage%s.html\">\\n" "$loghtml"
|
|
printf "</head>\\n<body>\\n<div class=\"page-wrapper\"><pre class=\"inner-wrapper\">\\n"
|
|
printf "<a href=\"/\"><<< BACK TO RELAY ONE</a>\\n\\n\\n"
|
|
cat "/var/gopher${log}"
|
|
# close up the entry footer
|
|
printf "</pre></div></body></html>"
|
|
} >> "${entry_html}"
|
|
done < "/var/gopher/listing.gophermap"
|
|
# footer
|
|
{
|
|
printf "</pre>\\n"
|
|
printf "</div>\\n"
|
|
printf "</body>\\n"
|
|
printf "</html>"
|
|
} >> "${file_html}"
|
|
|
|
# Generate ship pages
|
|
ships_html="/var/www/html/ships/index.html"
|
|
mkdir -p "/var/www/html/ships"
|
|
# Add header info to html output
|
|
cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${ships_html}"
|
|
# Custom header elements and body start
|
|
{
|
|
printf "<title>Cosmic Voyage - Ships</title>"
|
|
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/ships\">"
|
|
printf "</head>"
|
|
printf "<body>"
|
|
printf "<div class=\"page-wrapper\">"
|
|
printf "<pre class=\"inner-wrapper\">"
|
|
ship_intro="/var/gopher/ships/ships.gophermap"
|
|
if [ -f "$ship_intro" ]; then
|
|
cat "$ship_intro"
|
|
printf "\\n"
|
|
fi
|
|
} >> "${ships_html}"
|
|
# Add header info to html output
|
|
find "/var/gopher/" -maxdepth 1 ! -path "/var/gopher/" ! -path "/var/gopher/ships" ! -path "/var/gopher/log" -type d -print | sed 's|/var/gopher/||' | sort | while read -r ship
|
|
do
|
|
printf "<a href=\"/ships/%s/\">🢒 %s</a>\\n" "$ship" "$ship" >> "$ships_html"
|
|
# Create individual ship log page
|
|
ship_html="/var/www/html/ships/${ship}/index.html"
|
|
mkdir -p "/var/www/html/ships/${ship}"
|
|
# Add header info to html output
|
|
cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${ship_html}"
|
|
# Custom header elements and body start
|
|
{
|
|
printf "<title>Cosmic Voyage - %s</title>" "$ship"
|
|
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/ships/%s\">" "$ship"
|
|
printf "</head>"
|
|
printf "<body>"
|
|
printf "<div class=\"page-wrapper\">"
|
|
printf "<pre class=\"inner-wrapper\">"
|
|
# Contents
|
|
printf "<a href=\"/ships\"><<< BACK TO RELAY ONE SHIP LIST</a>\\n\\n\\n"
|
|
desc="/var/gopher/${ship}/.description"
|
|
if [ -f "$desc" ]; then
|
|
cat "$desc"
|
|
printf "\\n"
|
|
fi
|
|
printf "%s - Ship Log\\n" "$ship"
|
|
grep "^0${ship}" "/var/gopher/listing.gophermap" | sed "s|0${ship} - ||" | awk -F"\\t" '{f=$2; gsub(".txt", ".html", f); printf "<a href=\"%s\">🢒 %s</a>\n", f, $1}'
|
|
printf "</div></body></html>"
|
|
} >> "${ship_html}"
|
|
done
|
|
# Footer
|
|
{
|
|
printf "</div>\\n"
|
|
printf "</body>\\n"
|
|
printf "</html>"
|
|
} >> "${ships_html}"
|
|
|
|
else
|
|
printf "You must be root to run this script.\\n"
|
|
fi
|