#!/bin/bash # Title......: gmap # Description: gophermap generator # Author.....: Mitchell Johnston - uid 0 # Contact....: mitch@crn.hopto.org # Updated....: Thu 16 May 2024 05:59:22 AM CDT #---------------------------------- # variables #---------------------------------- [ "$1" == "-D" ] && DEBUG=1 && shift 1 # -D to turn on debug mode PS4='$SECONDS $LINENO: ' # debug prompt DOW=$(date +%a) # day of week: Thu TODAY=$(date +%m/%d) # month/day: 03/25 DOM=$(date +%d) # day of month: 25 OS=$(uname -s) # OS type: SunOS Linux NAME=${0##*/} # name of the script ROOT=/var/gopher # base gopher directory SITE="Christian Remnant Now" # Default name of site DIR=${PWD##*/} # Current directory TITLE="$(echo $DIR|sed -e 's/[-_]/ /g' -e 's/.*/\L&/' -e 's/[a-z]*/\u&/g')" # functions #---------------------------------- html(){ ## mark up code vim -f +"syn on" +"colorscheme pablo" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1 } log(){ ## creates a basic log entry $LOG must be defined # Use: log {entry} [ "$DEBUG" == "1" ] && set -x logger -i -t "$NAME" "$*" } # setup #---------------------------------- # this provides a quick way to edit all my scripts on the fly if [ "$1" == "-E" ] then vim $0 sed -i -e "7s/.*/# Updated....: $(date)/" $0 log "Updated $0" html $0 cp $0 /var/www/unix mv $0.html /var/www/unix cp $0 /var/gopher/scripts exit fi # display help if needed if [ "$1" == "-h" ] || [ "$1" == "--help" ] then fmt -s -w $(tput cols) </dev/null || sudo apt install bash -qyy if [ "$#" -eq 1 ] then [ -d "$1" ] && cd $1 [ "$1" == "-r" ] && echo "Recursive run" elif [ "$#" -eq 2 ] then [ -d "$1" ] && cd $1 && shift [ "$1" == "-r" ] && echo "Recursive run" fi # directory check [[ "$(pwd)" != *"$ROOT"* ]] && echo "$NAME: directory error" && exit 1 [[ "$(pwd)" == *"scripts"* ]] && exit # main #--------------------------- [ "$DEBUG" == 1 ] && set -x ## set header if [ -f gophermap.head ] then cat gophermap.head >gophermap [ "$(pwd)" == "$ROOT" ] && quote -g >>gophermap [ "$(pwd)" == "$ROOT" ] && echo "Tip: $(qt|fmt -w 40)" >>gophermap [ "$(pwd)" == "$ROOT" ] && log "Update" else echo "$SITE / $TITLE" >gophermap fi echo " ---[${TITLE}]--- ">>gophermap ## check for additional directories for DIRS in $(\ls -d */ 2>/dev/null) do if [ "$1" == "-r" ] # recurse into directories then cd $DIRS $0 cd .. fi DIRN=$(echo $DIRS|cut -d'.' -f1|tr '-' ' '|sed -e 's/.*/\L&/' -e 's/[a-z]*/\u&/g') echo -e "1${DIRN}\t${DIRS}">>gophermap done ## process files for ENTRY in $(ls | egrep -v 'gophermap|default|bin|head|index|include') do [ ! -f $ENTRY ] && continue EXT="${ENTRY##*.}" FNAME=$(echo $ENTRY|cut -d'.' -f1|sed -e 's/[-_]/ /g' -e 's/.*/\L&/' -e 's/[a-z]*/\u&/g') SIZE=$(ls -hs $ENTRY|cut -d' ' -f1) # Get size in human readable format case $EXT in m4v|mp4|mpv|avi) # videos TYPE="9" ;; pdf|epub|moba|azw3) # ebooks TYPE="9" ;; wav|mp3|midi) # audio TYPE="s" ;; jpg|jpeg|png|gif) # Pic TYPE="I" ;; iso|gz|zip|tar|tgz|7z) # archive TYPE="9" ;; exe) # Windows or DOS program TYPE="5" ;; txt|md) # Text TYPE="0" ;; htm|html) # Text TYPE="h" ;; *) # fallback TYPE="9" ;; esac echo -e "${TYPE}${FNAME} ${EXT} ${SIZE}\t $ENTRY" >>gophermap done ## set footer if [ -f gophermap.tail ] then cat gophermap.tail >>gophermap else cat ${ROOT}/default.tail >>gophermap fi echo " ">>gophermap echo "Updated: $(date)">>gophermap # Display quote to validate change [ "$(pwd)" == "$ROOT" ] && grep -A 3 KJV gophermap # vim: nospell ft=sh