html-to-other/cluster-to-other.sh

184 lines
8.3 KiB
Bash
Raw Normal View History

2023-02-28 20:00:52 +00: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 20:52:21 +00:00
# scm@sdf.org
2023-02-28 20:00:52 +00: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-16 00:39:20 +00:00
letter="s"
letter_range="ns"
year=$(date '+%Y')
2023-02-28 20:00:52 +00:00
month=$(date '+%m')
2023-02-28 20:00:52 +00:00
finger()
{
2023-03-15 21:01:46 +00:00
echo
echo "Finger conversion"
echo
2023-02-28 20:00:52 +00:00
# Download the index.html and $month.html files
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Convert the index.html file to an index-e01 text file
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Convert the $month.html file to a $month-e01 text file
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the blank lines from the beginning of the index-e01 file
2023-03-16 00:39:20 +00:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/finger/index-e01
2023-02-28 20:00:52 +00:00
# Remove the blank lines from the beginning of the $month-e01 file
2023-03-16 00:39:20 +00:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e01
2023-02-28 20:00:52 +00:00
# Remove the control characters from the index-e01 file and write it as index-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the control characters from the $month-e01 file and write it as $month-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the HTML link reference to previous month posts
2023-03-15 21:01:46 +00:00
if [ $last_month -lt 10 ]; then
2023-03-16 00:39:20 +00:00
sed -i "s/0$last_month//" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02
else
2023-03-16 00:39:20 +00:00
sed -i "s/$last_month//" /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02
fi
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Write a header file from index-e02
2023-03-16 00:39:20 +00:00
head -n 5 /sdf/arpa/$letter_range/$letter/$USER/finger/index-e02 > /sdf/arpa/$letter_range/$letter/$USER/finger/header
2023-02-28 20:00:52 +00:00
# Write a footer file from index-e02
2023-03-16 00:39:20 +00:00
tail -n 15 /sdf/arpa/$letter_range/$letter/$USER/finger/index-e02 > /sdf/arpa/$letter_range/$letter/$USER/finger/footer
2023-02-28 20:00:52 +00:00
# Write a dotplan file from the header
2023-03-16 00:39:20 +00:00
cat /sdf/arpa/$letter_range/$letter/$USER/finger/header > /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan
2023-02-28 20:00:52 +00:00
# Write the appended data from the $month-e02 file to dotplan
2023-03-16 00:39:20 +00:00
cat /sdf/arpa/$letter_range/$letter/$USER/finger/$month-e02 >> /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan
2023-02-28 20:00:52 +00:00
# Write the appended data from the footer file to dotplan
2023-03-16 00:39:20 +00:00
cat /sdf/arpa/$letter_range/$letter/$USER/finger/footer >> /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan
2023-02-28 20:00:52 +00:00
2023-03-16 22:11:31 +00:00
# Write the .plan file to the SDF cluster from dotplan
2023-03-16 00:39:20 +00:00
cp /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan /sdf/arpa/$letter_range/$letter/$USER/.plan
2023-02-28 20:00:52 +00:00
2023-03-16 22:11:31 +00:00
# Write the .plan file to the SDF meta array from dotplan
2023-03-16 00:39:20 +00:00
scp /sdf/arpa/$letter_range/$letter/$USER/finger/dotplan $USER@ma.sdf.org:/meta/$letter/$USER/.plan
2023-02-28 20:00:52 +00:00
}
gopher()
{
2023-03-15 21:01:46 +00:00
echo
echo "Gopher conversion"
echo
2023-03-15 18:38:26 +00:00
# If the year has changed, and a new year directory does not already
# exist, create it
2023-02-28 20:00:52 +00:00
# Download the index.html and $month.html files
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Convert the index.html file to an index-e01 text file
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Convert the $month.html file to a $month-e01 text file
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the blank lines from the beginning of the index-e01 file
2023-03-16 00:39:20 +00:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e01
2023-02-28 20:00:52 +00:00
# Remove the blank lines from the beginning of the $month-e01 file
2023-03-16 00:39:20 +00:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e01
2023-02-28 20:00:52 +00:00
# Remove the control characters from the index-e01 file and write it as index-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the control characters from the $month-e01 file and write it as $month-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
2023-03-16 00:39:20 +00:00
sed -i "7d;8d;9d;10d;11d;12d" /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e02
2023-02-28 20:00:52 +00:00
# From the index-e02 file write the index
2023-03-16 00:39:20 +00:00
cp /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/index-e02 /ftp/pub/users/$USER/index
2023-02-28 20:00:52 +00:00
# From the $month-e02 file write the $month
2023-03-16 00:39:20 +00:00
cp /sdf/arpa/$letter_range/$letter/$USER/gopher-prep/$month-e02 /ftp/pub/users/$USER/posts/$year/$month
2023-02-28 20:00:52 +00:00
2023-03-16 22:11:31 +00:00
# Set the correct permissions on the Gopher directory and files
2023-02-28 20:00:52 +00:00
chmod -R 754 /ftp/pub/users/$USER
}
gemini()
{
2023-03-15 21:01:46 +00:00
echo
echo "Gemini conversion"
echo
2023-03-15 18:38:26 +00:00
# If the year has changed, and a new year directory does not already
# exist, create it
2023-02-28 20:00:52 +00:00
# Download the index.html and $month.html files
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Convert the index.html file to an index-e01 text file
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Convert the $month.html file to a $month-e01 text file
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the blank lines from the beginning of the index-e01 file
2023-03-16 00:39:20 +00:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e01
2023-02-28 20:00:52 +00:00
# Remove the blank lines from the beginning of the $month-e01 file
2023-03-16 00:39:20 +00:00
sed -i "1d;2d;3d" /sdf/arpa/$letter_range/$letter/$USER/gemini/$month-e01
2023-02-28 20:00:52 +00:00
# Remove the control characters from the index-e01 file and write it as index-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the control characters from the $month-e01 file and write it as $month-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
# Remove the extra blank lines above and below the posts year
2023-03-16 00:39:20 +00:00
sed -i "9d;12d" /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e02
2023-02-28 20:00:52 +00:00
2023-03-16 22:11:31 +00:00
# Write a blank line between the source and copyright information
2023-02-28 20:00:52 +00:00
# Write the index.gmi file to the Meta Array from index-e02
2023-03-16 00:39:20 +00:00
scp /sdf/arpa/$letter_range/$letter/$USER/gemini/index-e02 $USER@ma.sdf.org:/meta/gemini/$USER/index.gmi
2023-02-28 20:00:52 +00:00
# Write the $month.gmi file to the Meta Array from $month-e02
2023-03-16 00:39:20 +00: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 20:00:52 +00:00
}
2023-11-24 19:04:25 +00:00
ma()
{
mosh scm@ma.sdf.org sh /meta/s/scm/html-to-other/ma-to-other.sh
}
2023-02-28 20:00:52 +00:00
finger
gopher
gemini
2023-11-24 19:04:25 +00:00
ma
2023-02-28 20:00:52 +00:00
exit 0