libraryoferis/lentry.sh

180 lines
13 KiB
Bash
Executable File

#!/bin/bash
echo -n "Enter Title: "
read title
echo -n "Enter Category Number(Books[1], Documents[2], Periodicals[3], Posters[4], Miscellaneous[5]): "
read category
echo -n "Enter Author Name: "
read author
echo -n "Enter Catalog Number: "
read cnumber
echo -n "Enter Description: "
read descrip
echo -n "Enter Date(format: 15 June 2005): "
read date
mkdir /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber
mv $1 /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber
touch /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
touch /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
# html header
echo "<!DOCTYPE html>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo "<html>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <head>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <title>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " Library of Eris" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </title>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <link rel="stylesheet" href="https://www.libraryoferis.org/stylesheet.css">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <link rel="apple-touch-icon" sizes="180x180" href="https://www.libraryoferis.org/apple-touch-icon.png">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <link rel="icon" type="image/png" sizes="32x32" href="https://www.libraryoferis.org/favicon-32x32.png">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <link rel="icon" type="image/png" sizes="16x16" href="https://www.libraryoferis.org/favicon-16x16.png">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <link rel="manifest" href="https://www.libraryoferis.org/site.webmanifest">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </head>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <body>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div id="header">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <img src="https://www.libraryoferis.org/LOE.png">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div id="menu">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/">Home</a> ⋄ " >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/about.html">About</a> ⋄ " >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/links.html">Links</a> ⋄ " >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/contact.html">Contact</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div id="catalog">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div id="catalog-menu" class="fisrstDiv"> " >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/catalog.html">Main Catalog</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " ⋄" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/books.html">Books</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " ⋄" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/documents.html">Documents</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " ⋄" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/periodicals.html">Periodicals</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " ⋄" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/posters.html">Posters</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " ⋄" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <a href="https://www.libraryoferis.org/miscellaneous.html">Miscellaneous</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div id="catalog-list" class="secondDiv">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
# Generate Html Content
echo " <b>Title:</b> $title</p>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <b>Author:</b> $author</p>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <b>Catalog Number:</b> $cnumber</p>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <b>Description:</b> $descrip</p>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <b>Date Published:</b> $date</p>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
# Generate Gopher Content
echo "Title: $title" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "Author: $author" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "Catalog Number: $cnumber" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
# This section ensures that the description is kept to 67 lines and adds an extra t due to escape character
whole_title="Description: $descrip"
touch fold.tmp
echo "$whole_title" >> fold.tmp
fold_title="$(fold -w 67 -s fold.tmp)"
rm fold.tmp
echo "$fold_title" >> sed.tmp
final_title="$(sed 's/^t/tt/g' sed.tmp)"
rm sed.tmp
echo "$final_title" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "Date Published: $date" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo "" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
# Determine link type
lastchars=${1: -3}
if [[ "$lastchars" == "txt" ]]; then
echo "[0|TXT|/library/catalog/$cnumber/$1|server|port]" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo " <b>Formats:</b> <a href="$1">TXT</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
elif [[ "$lastchars" == "pdf" ]]; then
echo "[9|PDF|/library/catalog/$cnumber/$1|server|port]" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo " <b>Formats:</b> <a href="$1">PDF</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
elif [[ "$lastchars" == "jpg" ]]; then
echo "[I|JPG|/library/catalog/$cnumber/$1|server|port]" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo " <b>Formats:</b> <a href="$1">JPG</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
elif [[ "$lastchars" == "gif" ]]; then
echo "[g|GIF|/library/catalog/$cnumber/$1|server|port]" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo " <b>Formats:</b> <a href="$1">GIF</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
else
echo "[0|TXT|/library/catalog/$cnumber/$1|server|port]" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.gph
echo " <b>Formats:</b> <a href="$1">TXT</a>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
fi
# Html footer
echo " </div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div class="clear"></div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <div id="footer">" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <object type="text/html" width="900" height="32" data="https://www.libraryoferis.org/cgi-bin/ddate.cgi"/></object>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <br>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " <img src="https://www.libraryoferis.org/kopyleft.png"> All Rights Reversed" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </div>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo " </body>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
echo "</html>" >> /var/lib/nethserver/vhost/libraryoferis/catalog/$cnumber/index.html
# Update catalog for gopher and html
echo "[1|$cnumber $title|/library/catalog/$cnumber|server|port]" >> /var/lib/nethserver/vhost/libraryoferis/catalog/index.gph
count=$(cat /var/lib/nethserver/vhost/libraryoferis/.counter)
sed -i "${count}i <a href=\"https://www.libraryoferis.org/catalog/${cnumber}/index.html\">${cnumber} - ${title}</a>" /var/lib/nethserver/vhost/libraryoferis/catalog.html
sed -i "${count}i <br>" /var/lib/nethserver/vhost/libraryoferis/catalog.html
ad_num=$((count + 2))
echo "$ad_num" > /var/lib/nethserver/vhost/libraryoferis/.counter
# Determines filenames based on category selection.
if [[ "$category" == "1" ]]; then
catlist="books.lst"
catgph="books.gph"
cathtm="books.html"
htmhed="books.hed"
cat_title="Discordian Books"
elif [[ "$category" == "2" ]]; then
catlist="documents.lst"
catgph="documents.gph"
cathtm="documents.html"
htmhed="documents.hed"
cat_title="Discordian Documents"
elif [[ "$category" == "3" ]]; then
catlist="periodicals.lst"
catgph="periodicals.gph"
cathtm="periodicals.html"
htmhed="periodicals.hed"
cat_title="Discordian Magazines and Newsletters"
elif [[ "$category" == "4" ]]; then
catlist="posters.lst"
catgph="posters.gph"
cathtm="posters.html"
htmhed="posters.hed"
cat_title="A collection of Discordian posters\n Note: Some of these are individual posters and others are a\n collection."
elif [[ "$category" == "5" ]]; then
catlist="miscellaneous.lst"
catgph="miscellaneous.gph"
cathtm="miscellaneous.html"
htmhed="miscellaneous.hed"
cat_title="Here's everything else"
fi
# Updates gopher and html categories
echo "[1|$title|/library/catalog/$cnumber|server|port]" >> /var/gopher/library/lists/$catlist
echo "<a href=\"https://www.libraryoferis.org/catalog/$cnumber/index.html\">$title</a><br>" >> /var/lib/nethserver/vhost/libraryoferis/lists/$catlist
echo "" >> /var/gopher/library/$catgph | echo "$cat_title" > /var/gopher/library/$catgph
cat /var/gopher/library/lists/$catlist | cut -c 4- | sed -e 's/^The \(.*\)/\1, The/' | sort | sed -e 's/\(.*\), The$/The \1/' | sed 's/^/\[1\|/' >> /var/gopher/library/$catgph
sort --key=1.68 -o /var/lib/nethserver/vhost/libraryoferis/lists/$catlist /var/lib/nethserver/vhost/libraryoferis/lists/$catlist
cat /var/lib/nethserver/vhost/libraryoferis/lists/$htmhed /var/lib/nethserver/vhost/libraryoferis/lists/$catlist /var/lib/nethserver/vhost/libraryoferis/lists/footer > /var/lib/nethserver/vhost/libraryoferis/$cathtm