Script to post images to gopher [22 May 2020]


I wrote a bash script that will take an image, allow me to name it, and post it
to a directory on a gopher server. It will also update the index file on the
server, so that the images can be browsed, and the link can be easily shared.

I came up with this, so that I have an instant link to an image to share on some
nefarious IRC channels, in which gopher is the only accepted protocol. :)

I am sure that there are many ways to do this, but this script works for me.

To get it working, you need to make a directory called "gopher" in your home
directory, i.e. /home/$USER/gopher/.

You then make another directory, maybe called something like "gopher_img",
i.e. /home/$USER/gopher_img/. Put the script in this directory, as this is where
it will be run.

You can copy an the script to that directory. Next, put an image to that directory,
and run the script. It will ask you what you want to name it, then it will
upload it to the remote server and update the index page there. After that, it
will delete the copied image from your local /home/$USER/gopher directory, so
that you are all set for next time.

A directory called "/img" will need to be set up on the remote directory. This
script assumes that you are using the "index.gph" format, which is used by the
wonderful geomyidae[1] gopher server. If you use something else, like "gophermaps",
you will need to change that.

Direct link to the shell script:

[0] gopher://sdf.org/0/users/developer/PHLOG/gopher_img.sh

[1] http://r-36.net/scm/geomyidae/
[1] gopher://bitreich.org/1/scm/geomyidae

-----------------------------------------------------------------------------

#!/bin/bash
## This is a script that copies and uploads an image from a local directory to a
## remote gopher server directory, and updates that directory's index page.

## NOTE: This script updates "index.gph", which is the file format used by the
## geomyidae gopher server. If you are using another format, such as gophermap,
## the file name will need to be changed.

## You will need to change $YOUR_DOMAIN_NAME, your local $USER name, your
## remote $USER name, and the $PORT_NUMBER, assuming that you are using an
## non-standard port. If not, then you can omit the -p flag and port number.

read -p "Enter File Name: "  name


ls *.{jpg,png,jpeg,gif} | while read filename

do if [ -f "${filename}" ]

then

echo "[I|${name}|/img/${filename}|$YOUR_DOMAIN_NAME|70]" >>/home/$USER/gopher/img/index.gph

fi
done

cp *{jpg,png,jpeg,gif} /home/$USER/gopher/img/

rsync -rvz --delete -e 'ssh -p $PORT_NUMBER' /home/$USER/gopher/ $REMOTE_USER@YOUR_DOMAIN_NAME:/var/gopher/

sleep 2 &&
cd /home/$USER/gopher/img/
exec rm -rf *jpg *jpeg *png *gif
exit