#!/usr/pkg/bin/bash # cluster-to-other.sh # Converts an index and posts HTML file to forms suitable for Finger, Gopher # and Gemini and writes them to their proper locations. # Copyright (C) 2023 Scott C. MacCallum # scm@sdf.org # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . letter="s" letter_range="ns" year=$(date '+%Y') month=$(date '+%m') one=1 last_month=$(($month - $one)) finger() { echo echo "Finger conversion" echo # Download the index.html and $month.html files sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/index.html /sdf/arpa/$letter_range/$letter/$USER/finger sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/posts/$year/$month.html /sdf/arpa/$letter_range/$letter/$USER/finger # Convert the index.html file to an index-e01 text file html2text -o /sdf/arpa/$letter_range/$letter/$USER/finger/index-e01 -ascii -style pretty /sdf/arpa/$letter_range/$letter/$USER/finger/index.html # Convert the $month.html file to a $month-e01 text file html2text -o /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e01 -ascii -style pretty /sdf/arpa/$letter_range/$letter/$USER/finger/$month.html # Remove the blank lines from the beginning of the index-e01 file sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/finger/index-e01 # Remove the blank lines from the beginning of the $month-e01 file sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e01 # Remove the control characters from the index-e01 file and write it as index-e02 cat /sdf/arpa/$letter_range/$letter/$USER/finger/index-e01 | col -b -x > /sdf/arpa/$letter_range/$letter/$USER/finger/index-e02 # Remove the control characters from the $month-e01 file and write it as $month-e02 cat /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e01 | col -b -x > /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02 # Remove the HTML link reference to previous month posts if [ $last_month -lt 10 ]; then sed -i "s/0$last_month//" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02 else sed -i "s/$last_month//" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02 fi # Remove the extra blank line from the end of the post sed -i "9d" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02 # Write a header file from index-e02 head -n 5 /sdf/arpa/$letter_range/$letter/$USER/finger/index-e02 > /sdf/arpa/$letter_range/$letter/$USER/finger/header # Write a footer file from index-e02 tail -n 15 /sdf/arpa/$letter_range/$letter/$USER/finger/index-e02 > /sdf/arpa/$letter_range/$letter/$USER/finger/footer # Write a dotplan file from the header cat /sdf/arpa/$letter_range/$letter/$USER/finger/header > /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan # Write the appended data from the $month-e02 file to dotplan cat /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02 >> /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan # Write the appended data from the footer file to dotplan cat /sdf/arpa/$letter_range/$letter/$USER/finger/footer >> /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan # Write the .plan file to the SDF cluster from dotplan cp /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan /sdf/arpa/$letter_range/$letter/$USER/.plan # Write the .plan file to the SDF meta array from dotplan scp /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan $USER@ma.sdf.org:/meta/$letter/$USER/.plan } gopher() { echo echo "Gopher conversion" echo # If the year has changed, and a new year directory does not already # exist, create it # Download the index.html and $month.html files sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/index.html /sdf/arpa/$letter_range/$letter/$USER/gopher-prep sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/posts/$year/$month.html /sdf/arpa/$letter_range/$letter/$USER/gopher-prep # Convert the index.html file to an index-e01 text file html2text -o /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e01 -ascii -style pretty /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index.html # Convert the $month.html file to a $month-e01 text file html2text -o /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e01 -ascii -style pretty /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month.html # Remove the blank lines from the beginning of the index-e01 file sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e01 # Remove the blank lines from the beginning of the $month-e01 file sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e01 # Remove the control characters from the index-e01 file and write it as index-e02 cat /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e01 | col -b -x > /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e02 # Remove the control characters from the $month-e01 file and write it as $month-e02 cat /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e01 | col -b -x > /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e02 sed -i "7d;8d;9d;10d;11d;12d" /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e02 # From the index-e02 file write the index cp /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e02 /ftp/pub/users/$USER/index # From the $month-e02 file write the $month cp /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e02 /ftp/pub/users/$USER/posts/$year/$month # Set the correct permissions on the Gopher directory and files chmod -R 754 /ftp/pub/users/$USER } gemini() { echo echo "Gemini conversion" echo # If the year has changed, and a new year directory does not already # exist, create it # Download the index.html and $month.html files sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/index.html /sdf/arpa/$letter_range/$letter/$USER/gemini sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/posts/$year/$month.html /sdf/arpa/$letter_range/$letter/$USER/gemini # Convert the index.html file to an index-e01 text file html2text -o /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e01 -ascii -style pretty /sdf/arpa/$letter_range/$letter/$USER/gemini/index.html # Convert the $month.html file to a $month-e01 text file html2text -o /sdf/arpa/$letter_range/$letter/$USER/gemini/$month-e01 -ascii -style pretty /sdf/arpa/$letter_range/$letter/$USER/gemini/$month.html # Remove the blank lines from the beginning of the index-e01 file sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e01 # Remove the blank lines from the beginning of the $month-e01 file sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gemini/$month-e01 # Remove the control characters from the index-e01 file and write it as index-e02 cat /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e01 | col -b -x > /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e02 # Remove the control characters from the $month-e01 file and write it as $month-e02 cat /sdf/arpa/$letter_range/$letter/$USER/gemini/$month-e01 | col -b -x > /sdf/arpa/$letter_range/$letter/$USER/gemini/$month-e02 # Remove the extra blank lines above and below the posts year sed -i "9d;12d" /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e02 # Write a blank line between the source and copyright information # Write the index.gmi file to the Meta Array from index-e02 scp /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e02 $USER@ma.sdf.org:/meta/gemini/$USER/index.gmi # Write the $month.gmi file to the Meta Array from $month-e02 scp /sdf/arpa/$letter_range/$letter/$USER/gemini/$month-e02 $USER@ma.sdf.org:/meta/gemini/$USER/posts/$year/$month.gmi } finger gopher gemini exit 0