#!/bin/ksh
#ARTICLE WRITE V1.1
#Script to make gopher article writing easier
#Accepts user input, calls up a text editor, once finished writing, updates gophermap and
#then sets file permissions.
#Now updates the Gemini Capsule index.gmi file since V1.1
print "Welcome to the Article Creation Tool"
print "The following article series can be selected:"
print "architecture"
print "music"
print "radio"
print "sumo"
############################################################################################
#Get article series
echo Which article series is this for?
read ART_SERIES
#Get article title
echo What is the article name?
read ART_TITLE
#Get document name
echo What is the document name?
read DOCNAME
###############################################################################
#Set up nanorc for gopher
rm ~/.nanorc
cp ~/scripts/nanorc_gopher ~/.nanorc
###############################################################################
#Create file, edit text
nano ~/gopher/$ART_SERIES/$DOCNAME.txt
###############################################################################
#Update that gophermap
#Create text to enter
ENTRY="0"$ART_TITLE'\t'$DOCNAME".txt"
GEM_ENTRY="=> "$DOCNAME".txt"" "$ART_TITLE
#Update gophermap
(cat ~/gopher/$ART_SERIES/gophermap && echo $ENTRY) > A.txt && mv A.txt ~/gopher/$ART_SERIES/gophermap
#Update gemini capsule
(cat ~/gopher/$ART_SERIES/index.gmi && echo $GEM_ENTRY) > B.txt && mv B.txt ~/gopher/$ART_SERIES/index.gmi
###############################################################################
#Correct the nanorc to main text mode
rm ~/.nanorc
cp ~/scripts/nanorc_text ~/.nanorc
###############################################################################
#Set permissions
find ~/gopher/ -type f -print0 | xargs -0 chmod 644
find ~/gopher/ -type d -print0 | xargs -0 chmod 755
###############################################################################
#This is the end
print "Article Created"
exit