#!/bin/bash # Wha'phup? : Edit and upload gopher log # 2018-11-15 # TODO Replace hardcoded variables with option variables [ $(uname) = 'Darwin' ] && [ ! $(which gdate) ] && echo "$(basename $0): 'coreutils' is required." && exit 1 [ ! $(which aspell) ] && echo "$(basename $0): 'aspell' is required." && exit 1 app=$(basename $0) PLOG=true VERBOSE= EDITORARG="+999" VIEWER="Marked 2" READER="lynx" SITE="circumlunar" DIR="gopher" me="cpj" HOLE="gopher://zaibatsu.circumlunar.space/1/~cpj" TITLE="My phlog" FOOTER= [ ! -d $DIR ] && echo $app: Setup required. Create or assign gopher directory. && exit MONTHS=(- Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) MONTHL=(- January February March April May June July August September October November December) DOWS=(Sun Mon Tue Wed Thu Fri Sat) DOWL=(Sunday Monday Tuesday Wednesday Thursday Friday Saturday) usage() { [ $(which getusage) ] && getusage $0 echo -e "\nExamples:" echo -e "phup -ec Edit and spellcheck a phlog. A header will be automatically added to new records." echo -e "phup -ul Upload a phlog; generate phlogmap and upload it." echo -e "phup -gu Upload ~/gophermap." } setdate() { # usage: setdate [yesterday|today|tomorrow] year=$(date -d "$1" +%Y) month=$(date -d "$1" +%0m) day=$(date -d "$1" +%0d) dow=$(date -d "$1" +%w) time=$(date +"%R %Z") } ordinal() { case "$1" in 1) ord="st";; 2) ord="nd";; 3) ord="rd";; 21) ord="st";; 22) ord="nd";; 23) ord="rd";; 31) ord="st";; *) ord="th";; esac } uploadfile() { sftp -pq $SITE < $DIR/$FILE printf "${DOWS[$dow]} $((10#$day))$ord ${MONTHS[$month]} $year /$me\n\n" >> $DIR/$FILE fi fi # file transactions if [ -e "$DIR/$FILE" ]; then if [ $EDIT ]; then [ ! $SELF ] && $EDITOR $EDITORARG $DIR/$FILE || echo "$(basename $0): Self-editing disabled." fi [ $CHKS ] && aspell -c $DIR/$FILE [ $VIEW ] && open -a "$VIEWER" $DIR/$FILE [ $TYPE ] && file -b $DIR/$FILE [ $DELE ] && rm -i $DIR/$FILE [ $UPLD ] && uploadfile $FILE #else # echo "$(basename $0): $DIR/$FILE: No such file" fi # create phlogmap if [ $LIST ]; then FILE="phlog/gophermap" echo "Generating phlogmap." for i in $DIR/$(dirname $FILE)/*.txt; do name=$(basename $i); name=${name%.*}; name=$(date -d$name +%F) line=$(head -n 1 $i) log+=$(printf "0$name : $line _$(basename $i)|") done printf "i== $TITLE ==\t\n\n" > $DIR/$FILE printf "$log" | sed 's/ _/\t/g;s/|/\n/g' | sort -r >> $DIR/$FILE [ $FOOTER ] && printf "\n1..\t/~$me" >> $DIR/$FILE echo "Uploading." uploadfile $FILE fi # open in reader [ $HTTP ] && $READER $HOLE