162 lines
7.6 KiB
Bash
Executable File
162 lines
7.6 KiB
Bash
Executable File
#!/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 <https://www.gnu.org/licenses/>.
|
|
|
|
month=$(date '+%m')
|
|
let prevmonth=$month-1
|
|
year=$(date '+%Y')
|
|
# Change this to the first letter of your login name
|
|
letter="s"
|
|
|
|
finger()
|
|
{
|
|
# Download the index.html and $month.html files
|
|
sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/index.html /sdf/arpa/ns/$letter/$USER/finger
|
|
sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/posts/$year/$month.html /sdf/arpa/ns/$letter/$USER/finger
|
|
|
|
# Convert the index.html file to an index-e01 text file
|
|
html2text -o /sdf/arpa/ns/$letter/$USER/finger/index-e01 -ascii -style pretty /sdf/arpa/ns/$letter/$USER/finger/index.html
|
|
|
|
# Convert the $month.html file to a $month-e01 text file
|
|
html2text -o /sdf/arpa/ns/$letter/$USER/finger/$month-e01 -ascii -style pretty /sdf/arpa/ns/$letter/$USER/finger/$month.html
|
|
|
|
# Remove the blank lines from the beginning of the index-e01 file
|
|
sed -i "1d;2d;3d" /sdf/arpa/ns/$letter/$USER/finger/index-e01
|
|
|
|
# Remove the blank lines from the beginning of the $month-e01 file
|
|
sed -i "1d;2d;3d" /sdf/arpa/ns/$letter/$USER/finger/$month-e01
|
|
|
|
# Remove the control characters from the index-e01 file and write it as index-e02
|
|
cat /sdf/arpa/ns/$letter/$USER/finger/index-e01 | col -b -x > /sdf/arpa/ns/$letter/$USER/finger/index-e02
|
|
|
|
# Remove the control characters from the $month-e01 file and write it as $month-e02
|
|
cat /sdf/arpa/ns/$letter/$USER/finger/$month-e01 | col -b -x > /sdf/arpa/ns/$letter/$USER/finger/$month-e02
|
|
|
|
# Remove the HTML link reference to previous month posts
|
|
if [ $prevmonth -lt 10 ]; then
|
|
sed -i "s/0$prevmonth//" /sdf/arpa/ns/$letter/$USER/finger/$month-e02
|
|
else
|
|
sed -i "s/$prevmonth//" /sdf/arpa/ns/$letter/$USER/finger/$month-e02
|
|
fi
|
|
|
|
# Write a header file from index-e02
|
|
head -n 5 /sdf/arpa/ns/$letter/$USER/finger/index-e02 > /sdf/arpa/ns/$letter/$USER/finger/header
|
|
|
|
# Write a footer file from index-e02
|
|
tail -n 15 /sdf/arpa/ns/$letter/$USER/finger/index-e02 > /sdf/arpa/ns/$letter/$USER/finger/footer
|
|
|
|
# Write a dotplan file from the header
|
|
cat /sdf/arpa/ns/$letter/$USER/finger/header > /sdf/arpa/ns/$letter/$USER/finger/dotplan
|
|
|
|
# Write the appended data from the $month-e02 file to dotplan
|
|
cat /sdf/arpa/ns/$letter/$USER/finger/$month-e02 >> /sdf/arpa/ns/$letter/$USER/finger/dotplan
|
|
|
|
# Write the appended data from the footer file to dotplan
|
|
cat /sdf/arpa/ns/$letter/$USER/finger/footer >> /sdf/arpa/ns/$letter/$USER/finger/dotplan
|
|
|
|
# Write the .plan file to the Cluster from dotplan
|
|
cp /sdf/arpa/ns/$letter/$USER/finger/dotplan /sdf/arpa/ns/$letter/$USER/.plan
|
|
|
|
# Write the .plan file to the Meta Array from dotplan
|
|
scp /sdf/arpa/ns/$letter/$USER/finger/dotplan $USER@ma.sdf.org:/meta/$letter/$USER/.plan
|
|
}
|
|
|
|
gopher()
|
|
{
|
|
# Download the index.html and $month.html files
|
|
sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/index.html /sdf/arpa/ns/$letter/$USER/gopher-prep
|
|
sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/posts/$year/$month.html /sdf/arpa/ns/$letter/$USER/gopher-prep
|
|
|
|
# Convert the index.html file to an index-e01 text file
|
|
html2text -o /sdf/arpa/ns/$letter/$USER/gopher-prep/index-e01 -ascii -style pretty /sdf/arpa/ns/$letter/$USER/gopher-prep/index.html
|
|
|
|
# Convert the $month.html file to a $month-e01 text file
|
|
html2text -o /sdf/arpa/ns/$letter/$USER/gopher-prep/$month-e01 -ascii -style pretty /sdf/arpa/ns/$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/ns/$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/ns/$letter/$USER/gopher-prep/$month-e01
|
|
|
|
# Remove the control characters from the index-e01 file and write it as index-e02
|
|
cat /sdf/arpa/ns/$letter/$USER/gopher-prep/index-e01 | col -b -x > /sdf/arpa/ns/$letter/$USER/gopher-prep/index-e02
|
|
|
|
# Remove the control characters from the $month-e01 file and write it as $month-e02
|
|
cat /sdf/arpa/ns/$letter/$USER/gopher-prep/$month-e01 | col -b -x > /sdf/arpa/ns/$letter/$USER/gopher-prep/$month-e02
|
|
|
|
sed -i "7d;8d;9d;10d;11d;12d" /sdf/arpa/ns/$letter/$USER/gopher-prep/index-e02
|
|
|
|
# From the index-e02 file write the index
|
|
cp /sdf/arpa/ns/$letter/$USER/gopher-prep/index-e02 /ftp/pub/users/$USER/index
|
|
|
|
# From the $month-e02 file write the $month
|
|
cp /sdf/arpa/ns/$letter/$USER/gopher-prep/$month-e02 /ftp/pub/users/$USER/posts/$year/$month
|
|
|
|
chmod -R 754 /ftp/pub/users/$USER
|
|
}
|
|
|
|
gemini()
|
|
{
|
|
# Download the index.html and $month.html files
|
|
sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/index.html /sdf/arpa/ns/$letter/$USER/gemini
|
|
sftp $USER@ma.sdf.org:/meta/$letter/$USER/html/posts/$year/$month.html /sdf/arpa/ns/$letter/$USER/gemini
|
|
|
|
# Convert the index.html file to an index-e01 text file
|
|
html2text -o /sdf/arpa/ns/$letter/$USER/gemini/index-e01 -ascii -style pretty /sdf/arpa/ns/$letter/$USER/gemini/index.html
|
|
|
|
# Convert the $month.html file to a $month-e01 text file
|
|
html2text -o /sdf/arpa/ns/$letter/$USER/gemini/$month-e01 -ascii -style pretty /sdf/arpa/ns/$letter/$USER/gemini/$month.html
|
|
|
|
# Remove the blank lines from the beginning of the index-e01 file
|
|
sed -i "1d;2d;3d" /sdf/arpa/ns/$letter/$USER/gemini/index-e01
|
|
|
|
# Remove the blank lines from the beginning of the $month-e01 file
|
|
sed -i "1d;2d;3d" /sdf/arpa/ns/$letter/$USER/gemini/$month-e01
|
|
|
|
# Remove the control characters from the index-e01 file and write it as index-e02
|
|
cat /sdf/arpa/ns/$letter/$USER/gemini/index-e01 | col -b -x > /sdf/arpa/ns/$letter/$USER/gemini/index-e02
|
|
|
|
# Remove the control characters from the $month-e01 file and write it as $month-e02
|
|
cat /sdf/arpa/ns/$letter/$USER/gemini/$month-e01 | col -b -x > /sdf/arpa/ns/$letter/$USER/gemini/$month-e02
|
|
|
|
# Remove the extra blank lines above and below the posts year
|
|
sed -i "9d;12d" /sdf/arpa/ns/$letter/$USER/gemini/index-e02
|
|
|
|
# Substitute the posts year with a Gemini link to the posts
|
|
sed -i "s/$year/=> gemini\:\/\/gem.sdf.org\/$USER\/posts\/$year\/$month.gmi $year/" /sdf/arpa/ns/$letter/$USER/gemini/index-e02
|
|
|
|
# Substitute the Gopher text with a Gopher Gemini link
|
|
sed -i "s/Gopher e.g. gopher gopher\:\/\/sdf.org\:70\/1\/users\/$USER\/./=> gopher\:\/\/sdf.org\:70\/1\/users\/$USER\/ Gopher/" /sdf/arpa/ns/$letter/$USER/gemini/index-e02
|
|
|
|
# Write the index.gmi file to the Meta Array from index-e02
|
|
scp /sdf/arpa/ns/$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/ns/$letter/$USER/gemini/$month-e02 $USER@ma.sdf.org:/meta/gemini/$USER/posts/$year/$month.gmi
|
|
}
|
|
|
|
# Comment out the service that you're not using, or to aid in getting one to display correctly at a time
|
|
finger
|
|
gopher
|
|
gemini
|
|
|
|
exit 0
|