2023-02-28 15:00:52 -05:00
#!/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
2023-02-28 15:52:21 -05:00
# scm@sdf.org
2023-02-28 15:00:52 -05:00
# 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 <https://www.gnu.org/licenses/>.
2023-03-15 20:39:20 -04:00
letter = "s"
letter_range = "ns"
year = $( date '+%Y' )
2023-02-28 15:00:52 -05:00
month = $( date '+%m' )
2023-03-15 17:01:46 -04:00
one = 1
last_month = $(( $month - $one ))
2023-02-28 15:00:52 -05:00
finger( )
{
2023-03-15 17:01:46 -04:00
echo
echo "Finger conversion"
echo
2023-02-28 15:00:52 -05:00
# Download the index.html and $month.html files
2023-03-15 20:39:20 -04:00
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
2023-02-28 15:00:52 -05:00
# Convert the index.html file to an index-e01 text file
2023-03-15 20:39:20 -04:00
html2text -o /sdf/arpa/$letter_range /$letter /$USER /finger/index-e01 -ascii -style pretty /sdf/arpa/$letter_range /$letter /$USER /finger/index.html
2023-02-28 15:00:52 -05:00
# Convert the $month.html file to a $month-e01 text file
2023-03-15 20:39:20 -04:00
html2text -o /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e01 -ascii -style pretty /sdf/arpa/$letter_range /$letter /$USER /finger/$month .html
2023-02-28 15:00:52 -05:00
# Remove the blank lines from the beginning of the index-e01 file
2023-03-15 20:39:20 -04:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range /$letter /$USER /finger/index-e01
2023-02-28 15:00:52 -05:00
# Remove the blank lines from the beginning of the $month-e01 file
2023-03-15 20:39:20 -04:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e01
2023-02-28 15:00:52 -05:00
# Remove the control characters from the index-e01 file and write it as index-e02
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /finger/index-e01 | col -b -x > /sdf/arpa/$letter_range /$letter /$USER /finger/index-e02
2023-02-28 15:00:52 -05:00
# Remove the control characters from the $month-e01 file and write it as $month-e02
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e01 | col -b -x > /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e02
2023-02-28 15:00:52 -05:00
2023-03-02 16:05:39 -05:00
# Remove the HTML link reference to previous month posts
2023-03-15 17:01:46 -04:00
if [ $last_month -lt 10 ] ; then
2023-03-15 20:39:20 -04:00
sed -i " s/0 $last_month // " /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e02
2023-03-02 16:05:39 -05:00
else
2023-03-15 20:39:20 -04:00
sed -i " s/ $last_month // " /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e02
2023-03-02 16:05:39 -05:00
fi
2023-03-15 20:39:20 -04:00
# Remove the extra blank line from the end of the post
sed -i "9d" /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e02
2023-02-28 15:00:52 -05:00
# Write a header file from index-e02
2023-03-15 20:39:20 -04:00
head -n 5 /sdf/arpa/$letter_range /$letter /$USER /finger/index-e02 > /sdf/arpa/$letter_range /$letter /$USER /finger/header
2023-02-28 15:00:52 -05:00
# Write a footer file from index-e02
2023-03-15 20:39:20 -04:00
tail -n 15 /sdf/arpa/$letter_range /$letter /$USER /finger/index-e02 > /sdf/arpa/$letter_range /$letter /$USER /finger/footer
2023-02-28 15:00:52 -05:00
# Write a dotplan file from the header
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /finger/header > /sdf/arpa/$letter_range /$letter /$USER /finger/dotplan
2023-02-28 15:00:52 -05:00
# Write the appended data from the $month-e02 file to dotplan
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /finger/$month -e02 >> /sdf/arpa/$letter_range /$letter /$USER /finger/dotplan
2023-02-28 15:00:52 -05:00
# Write the appended data from the footer file to dotplan
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /finger/footer >> /sdf/arpa/$letter_range /$letter /$USER /finger/dotplan
2023-02-28 15:00:52 -05:00
# Write the .plan file to the Cluster from dotplan
2023-03-15 20:39:20 -04:00
cp /sdf/arpa/$letter_range /$letter /$USER /finger/dotplan /sdf/arpa/$letter_range /$letter /$USER /.plan
2023-02-28 15:00:52 -05:00
# Write the .plan file to the Meta Array from dotplan
2023-03-15 20:39:20 -04:00
scp /sdf/arpa/$letter_range /$letter /$USER /finger/dotplan $USER @ma.sdf.org:/meta/$letter /$USER /.plan
2023-02-28 15:00:52 -05:00
}
gopher( )
{
2023-03-15 17:01:46 -04:00
echo
echo "Gopher conversion"
echo
2023-03-15 14:38:26 -04:00
# If the year has changed, and a new year directory does not already
# exist, create it
2023-02-28 15:00:52 -05:00
# Download the index.html and $month.html files
2023-03-15 20:39:20 -04:00
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
2023-02-28 15:00:52 -05:00
# Convert the index.html file to an index-e01 text file
2023-03-15 20:39:20 -04:00
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
2023-02-28 15:00:52 -05:00
# Convert the $month.html file to a $month-e01 text file
2023-03-15 20:39:20 -04:00
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
2023-02-28 15:00:52 -05:00
# Remove the blank lines from the beginning of the index-e01 file
2023-03-15 20:39:20 -04:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/index-e01
2023-02-28 15:00:52 -05:00
# Remove the blank lines from the beginning of the $month-e01 file
2023-03-15 20:39:20 -04:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/$month -e01
2023-02-28 15:00:52 -05:00
# Remove the control characters from the index-e01 file and write it as index-e02
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/index-e01 | col -b -x > /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/index-e02
2023-02-28 15:00:52 -05:00
# Remove the control characters from the $month-e01 file and write it as $month-e02
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/$month -e01 | col -b -x > /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/$month -e02
2023-02-28 15:00:52 -05:00
2023-03-15 20:39:20 -04:00
sed -i "7d;8d;9d;10d;11d;12d" /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/index-e02
2023-02-28 15:00:52 -05:00
# From the index-e02 file write the index
2023-03-15 20:39:20 -04:00
cp /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/index-e02 /ftp/pub/users/$USER /index
2023-02-28 15:00:52 -05:00
2023-03-02 16:05:39 -05:00
# From the $month-e02 file write the $month
2023-03-15 20:39:20 -04:00
cp /sdf/arpa/$letter_range /$letter /$USER /gopher-prep/$month -e02 /ftp/pub/users/$USER /posts/$year /$month
2023-02-28 15:00:52 -05:00
chmod -R 754 /ftp/pub/users/$USER
}
gemini( )
{
2023-03-15 17:01:46 -04:00
echo
echo "Gemini conversion"
echo
2023-03-15 14:38:26 -04:00
# If the year has changed, and a new year directory does not already
# exist, create it
2023-02-28 15:00:52 -05:00
# Download the index.html and $month.html files
2023-03-15 20:39:20 -04:00
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
2023-02-28 15:00:52 -05:00
# Convert the index.html file to an index-e01 text file
2023-03-15 20:39:20 -04:00
html2text -o /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e01 -ascii -style pretty /sdf/arpa/$letter_range /$letter /$USER /gemini/index.html
2023-02-28 15:00:52 -05:00
# Convert the $month.html file to a $month-e01 text file
2023-03-15 20:39:20 -04:00
html2text -o /sdf/arpa/$letter_range /$letter /$USER /gemini/$month -e01 -ascii -style pretty /sdf/arpa/$letter_range /$letter /$USER /gemini/$month .html
2023-02-28 15:00:52 -05:00
# Remove the blank lines from the beginning of the index-e01 file
2023-03-15 20:39:20 -04:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e01
2023-02-28 15:00:52 -05:00
# Remove the blank lines from the beginning of the $month-e01 file
2023-03-15 20:39:20 -04:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range /$letter /$USER /gemini/$month -e01
2023-02-28 15:00:52 -05:00
# Remove the control characters from the index-e01 file and write it as index-e02
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e01 | col -b -x > /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e02
2023-02-28 15:00:52 -05:00
# Remove the control characters from the $month-e01 file and write it as $month-e02
2023-03-15 20:39:20 -04:00
cat /sdf/arpa/$letter_range /$letter /$USER /gemini/$month -e01 | col -b -x > /sdf/arpa/$letter_range /$letter /$USER /gemini/$month -e02
2023-02-28 15:00:52 -05:00
# Remove the extra blank lines above and below the posts year
2023-03-15 20:39:20 -04:00
sed -i "9d;12d" /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e02
2023-02-28 15:00:52 -05:00
# Substitute the posts year with a Gemini link to the posts
2023-03-15 20:39:20 -04:00
sed -i " s/ $year /=> gemini\:\/\/gem.sdf.org\/ $USER \/posts\/ $year \/ $month .gmi $year / " /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e02
2023-02-28 15:00:52 -05:00
# Substitute the Gopher text with a Gopher Gemini link
2023-03-15 20:39:20 -04:00
sed -i " s/Gopher e.g. gopher gopher\:\/\/sdf.org\:70\/1\/users\/ $USER \/./=> gopher\:\/\/sdf.org\:70\/1\/users\/ $USER \/ Gopher/ " /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e02
2023-02-28 15:00:52 -05:00
# Write the index.gmi file to the Meta Array from index-e02
2023-03-15 20:39:20 -04:00
scp /sdf/arpa/$letter_range /$letter /$USER /gemini/index-e02 $USER @ma.sdf.org:/meta/gemini/$USER /index.gmi
2023-02-28 15:00:52 -05:00
# Write the $month.gmi file to the Meta Array from $month-e02
2023-03-15 20:39:20 -04:00
scp /sdf/arpa/$letter_range /$letter /$USER /gemini/$month -e02 $USER @ma.sdf.org:/meta/gemini/$USER /posts/$year /$month .gmi
2023-02-28 15:00:52 -05:00
}
finger
gopher
gemini
exit 0