diff --git a/bin/cosmic-web b/bin/cosmic-web index 36bd2be..5b20668 100755 --- a/bin/cosmic-web +++ b/bin/cosmic-web @@ -2,10 +2,24 @@ run_user=$(id -u) if [ "$run_user" -eq 0 ]; then + SCRIPT=$(readlink -f "$0") + SCRIPTPATH=$(dirname "$SCRIPT") + file_html="/var/www/html/index.html" + web_header_html="${SCRIPTPATH}/../files/web-header.tmpl" + ships_html="/var/www/html/ships/index.html" + error_html="/var/www/html/error.html" + html_dir="/var/www/html" + gopher_dir="/var/gopher" + + # Clear web folder + rm -rf "${html_dir:-/var/www/html}/*" + # Generate RSS + # shellcheck source=cosmic-rss + . "${SCRIPTPATH}/cosmic-rss" # Add standard header - cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${file_html}" + cat "$web_header_html" > "${file_html}" # Custom header elements and body start { printf "Cosmic Voyage" @@ -16,9 +30,9 @@ if [ "$run_user" -eq 0 ]; then printf "
" printf "
"
     # Intro text
-    cat "/var/gopher/intro.gophermap"
+    cat "${gopher_dir}/intro.gophermap"
     # Ship listings
-    printf "\\n🢒 Ships, Colonies, Outposts\\n\\n"
+    printf "\\n>> Ships, Colonies, Outposts\\n\\n"
     # Logs
     printf "Transmission Log:\\n"
   } >> "${file_html}"
@@ -29,22 +43,22 @@ if [ "$run_user" -eq 0 ]; then
     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 "/home/tomasino/cosmic/files/web-header.tmpl" > "${entry_html}"
+    entry_html="${html_dir}${loghtml}.html"
+    mkdir -p "${html_dir}${logdir}"
+    cat "$web_header_html" > "${entry_html}"
     {
       printf "    %s\\n" "$title"
       printf "    \\n" "$loghtml"
       printf "\\n\\n
\\n"
-      printf "<<< BACK TO RELAY ONE\\n\\n\\n"
-      cat "/var/gopher${log}"
+      printf "<< BACK TO RELAY ONE\\n\\n\\n"
+      cat "${gopher_dir}${log}"
       # close up the entry footer
       printf "
" } >> "${entry_html}" - done < "/var/gopher/listing.gophermap" + done < "${gopher_dir}/listing.gophermap" # footer { printf "
\\n" @@ -54,10 +68,9 @@ if [ "$run_user" -eq 0 ]; then } >> "${file_html}" # Generate ship pages - ships_html="/var/www/html/ships/index.html" - mkdir -p "/var/www/html/ships" + mkdir -p "${html_dir}/ships" # Add header info to html output - cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${ships_html}" + cat "$web_header_html" > "${ships_html}" # Custom header elements and body start { printf "Cosmic Voyage - Ships" @@ -66,23 +79,24 @@ if [ "$run_user" -eq 0 ]; then printf "" printf "
" printf "
"
-    ship_intro="/var/gopher/ships/ships.gophermap"
+    printf "<< BACK TO RELAY ONE\\n"
+    ship_intro="${gopher_dir}/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
+  find "${gopher_dir}/" -maxdepth 1 ! -path "${gopher_dir}/" ! -path "${gopher_dir}/ships" ! -path "${gopher_dir}/log" -type d -print | sed 's|/var/gopher/||' | sort | while read -r ship
   do
-    entry_num=$(grep -c "^0${ship}" "/var/gopher/listing.gophermap")
+    entry_num=$(grep -c "^0${ship}" "${gopher_dir}/listing.gophermap")
     if [ "$entry_num" != "0" ]; then
-      printf "🢒 %s (%s)\\n" "$ship" "$ship" "$entry_num" >> "$ships_html"
+      printf ">> %s (%s)\\n" "$ship" "$ship" "$entry_num" >> "$ships_html"
       # Create individual ship log page
-      ship_html="/var/www/html/ships/${ship}/index.html"
-      mkdir -p "/var/www/html/ships/${ship}"
+      ship_html="${html_dir}/ships/${ship}/index.html"
+      mkdir -p "${html_dir}/ships/${ship}"
       # Add header info to html output
-      cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${ship_html}"
+      cat "$web_header_html" > "${ship_html}"
       # Custom header elements and body start
       {
         printf "Cosmic Voyage - %s" "$ship"
@@ -92,14 +106,14 @@ if [ "$run_user" -eq 0 ]; then
         printf "
" printf "
"
         # Contents
-        printf "<<< BACK TO RELAY ONE SHIP LIST\\n\\n\\n"
-        desc="/var/gopher/${ship}/.description"
+        printf "<< BACK TO RELAY ONE SHIP LIST\\n\\n\\n"
+        desc="${gopher_dir}/${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}'
+        grep "^0${ship}" "${gopher_dir}/listing.gophermap" | sed "s|0${ship} - ||" | awk -F"\\t" '{f=$2; gsub(".txt", ".html", f); printf ">> %s\n", f, $1}'
         printf "
" } >> "${ship_html}" fi @@ -112,10 +126,9 @@ if [ "$run_user" -eq 0 ]; then } >> "${ships_html}" # Print error page - error_html="/var/www/html/error.html" - cat "/home/tomasino/cosmic/files/web-header.tmpl" > "${error_html}" + cat "$web_header_html" > "${error_html}" { - printf "
<<< BACK TO RELAY ONE"
+    printf "
<< BACK TO RELAY ONE"
     printf "\\n\\n\\nERROR. TRANSMISSION NOT FOUND.
" } >> "${error_html}" else