From 083f323af1e774b1f5d664c5398b52f373f31496 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Mon, 26 Nov 2018 20:56:38 -0500 Subject: [PATCH] expanded upon and cleaned up web script --- bin/cosmic-web | 180 +++++++++++++++++------------------------- files/web-header.tmpl | 42 ++++++++++ 2 files changed, 113 insertions(+), 109 deletions(-) create mode 100644 files/web-header.tmpl diff --git a/bin/cosmic-web b/bin/cosmic-web index 9cd598d..d58ebd1 100755 --- a/bin/cosmic-web +++ b/bin/cosmic-web @@ -4,140 +4,102 @@ run_user=$(id -u) if [ "$run_user" -eq 0 ]; then file_html="/var/www/html/index.html" - # Add header info to html output + # Add standard header + cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${file_html}" + # Custom header elements and body start { - cat > /dev/stdout << END - - - - - - - - - Cosmic Voyage - - - - - - -
-
-END
-  } > "${file_html}"
-
-  # Add intro text
-  cat "/var/gopher/intro.gophermap" >> "${file_html}"
-
+    printf "Cosmic Voyage"
+    printf ""
+    printf ""
+    printf ""
+    printf ""
+    printf "
" + printf "
"
+    # Intro text
+    cat "/var/gopher/intro.gophermap"
+    # Ship listings
+    printf "\\n\\n🢒 Ships, Outposts, and Colonies\\n"
+    # Logs
+    printf "\\nTransmission log (newest first):\\n"
+  } >> "${file_html}"
   # Loop through listings gophermap
-  printf "\\n\\nTransmission log (newest first):\\n" >> "${file_html}"
   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 "%s\\n" "$loghtml" "$title" >> "${file_html}"
+    printf "🢒 %s\\n" "$loghtml" "$title" >> "${file_html}"
 
     # create entry
     entry_html="/var/www/html${loghtml}.html"
     mkdir -p "/var/www/html${logdir}"
-    {
-      cat > /dev/stdout << ENTRY
-
-
-  
-    
-    
-    
-    
-    
-     
-    
-ENTRY
-    } > "${entry_html}"
-
+    cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${entry_html}"
     {
       printf "    %s\\n" "$title"
       printf "    \\n" "$loghtml"
-
       printf "\\n\\n
\\n"
-      printf "<<< BACK TO RELAY ONE\\n\\n\\n"
+      printf "<<< BACK TO RELAY ONE\\n\\n\\n"
       cat "/var/gopher${log}"
       # close up the entry footer
       printf "
" } >> "${entry_html}" - done < "/var/gopher/listing.gophermap" printf "
" >> "${file_html}" - - # close up the footer + # footer { printf "
" } >> "${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 "Cosmic Voyage - Ships" + printf "" + printf "" + printf "" + printf "
" + printf "
"
+  } >> "${ships_html}"
+  # Add header info to html output
+  find "/var/gopher/" -maxdepth 1 ! -path "/var/gopher/" ! -path "/var/gopher/ships" -type d -print | sed 's|/var/gopher/||' | sort | while read -r ship
+  do
+    printf "🢒 %s\\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 "Cosmic Voyage - %s" "$ship"
+      printf "" "$ship"
+      printf ""
+      printf ""
+      printf "
" + printf "
"
+      # Contents
+      printf "<<< BACK TO RELAY ONE SHIP LIST\\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 "🢒 %s\n", f, $1}'
+      printf "
" + } >> "${ship_html}" + + done + # Footer + { + printf "
" + } >> "${ships_html}" + else printf "You must be root to run this script.\\n" fi diff --git a/files/web-header.tmpl b/files/web-header.tmpl new file mode 100644 index 0000000..1c643d7 --- /dev/null +++ b/files/web-header.tmpl @@ -0,0 +1,42 @@ + + + + + + + + + + +