the script I wrote for sexoskeleton.com to create a blog from a folder of images and txt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.2 KiB

#!/bin/bash
#sexoskeleton.com update script by trav fryer
echo "SEXOSKELETONZ INCOMMING"
#set some vars
MAXINDEX=70
MAXLOG=1000
didsomethingchange=false
#if log is too big just wipe it, who cares
numlines="$(wc -l ~/cronlog.log)"
numlinez="$(echo $numlines | head -c 3)"
echo "cronlog is $numlinez/$MAXLOG"
if [ "$numlinez" -gt "$MAXLOG" ]
then
echo "fuck it, wipe the log"
rm ~/cronlog.log
#make new log
touch cronlog.log
echo "cronlog archived" | tee -a ~/cronlog.log
fi
#ok, now logging
echo "" >> ~/cronlog.log
date >> ~/cronlog.log
#if the index is of a certain size archive it
#check if index > x lines
numlines="$(wc -l webdir/index.html)"
numlinez="$(echo $numlines | head -c 3)"
echo "index lines: $numlinez/$MAXINDEX" | tee -a ~/cronlog.log
if [ "$numlinez" -gt "$MAXINDEX" ]
then
echo "ARCHIVING INDEX!!!" | tee -a ~/cronlog.log
#generate the current date for archive
todayis="$(date -u +%Y-%m-%d)"
#generate new page name with date
movedpage="~/webdir/$(date -u +%Y-%m-%s).html"
#change name of old index to new generated name
mv webdir/index.html "$movedpage"
#add link to new archived page into archive.html
file="webdir/archive.html"
insert="<!--posts-->\n<a href=$movedpage>$todayis<\/a><br><br>\n"
sed -i -- "s/<!--posts-->/$insert/" "$file"
#make new index.html
cp template.conf webdir/index.html
didsomethingchange=true
fi
#BLOG POST STUFF
#get all files in webadd directory
filez="$(ls -1 webadd)"
echo "here are the files we're gonna push: $filez" | tee -a ~/cronlog.log
#make array of files
arr=($filez)
#get first file in arry
afile=${arr[0]}
#POST ALL THE FILES!!
while [ "$filez" != "" ]
do
#get extension of top file (this is not the best way to get file extension, it's not using the period as a delimiter!!
extn="${afile: -4}"
# test for image or txt
if [ "$extn" == '.png' ] || [ "$extn" = '.jpg' ] || [ "$extn" == '.gif' ] || [ "$extn" == 'jpeg' ]
then
echo "posting $afile" | tee -a ~/cronlog.log
#come up with unique string to rename the file (to avoid colisions)
newname="$(date +%s)$extn"
#move the image into the web directory and insert into index.html
mv webadd/$afile webdir/$newname
insert="<!--posts-->\n$(date)<br><p><img src=$newname><\/p><br><br><br>\n"
file="webdir/index.html"
sed -i -- "s/<!--posts-->/$insert/" "$file"
didsomethingchange=true
#is it text?
elif [ "$extn" == '.txt' ]
then
echo "found a text, $afile" | tee -a ~/cronlog.log
str="$(cat webadd/"$afile")"
rm webadd/$afile
file="webdir/index.html"
insert="<!--posts-->\n$(date)<br><p>$str<\/p><br><br><br>\n"
sed -i -- "s/<!--posts-->/$insert/" "$file"
didsomethingchange=true
else
echo "BAD FILE EXTENSION $extn , REMOVING FILE $afile" | tee -a ~/cronlog.log
rm webadd/$afile
fi
# i t e r a t e
#get all files in webadd
filez="$(ls -1 webadd)"
#make array of files
arr=($filez)
#get first file in array
afile=${arr[0]}
done
# if something changed, post to da web
if [ "$didsomethingchange" == true ]
then
echo "surging now" | tee -a ~/cronlog.log
/usr/local/bin/surge ~/webdir sexoskeleton.com | tee -a ~/cronlog.log
else
echo "no files" | tee -a ~/cronlog.log
fi