#!/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