Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # A script to see if the directory structure for flatpress exists,
- # if not, then create it, then add a pre-determined content file to
- # the database. Requires the flatpress php index rebuilder script.
- # This absolutely needs to be run as your webserver user, otherwise it
- # will completely bork your flatpress database. Trust me on this one.
- # This is version 0.9 and the type is BETA
- # I think we can assume you've already installed flatpress at this point.
- # What do we need to know beforehand?
- tdm=$(date +%m) # two digit month
- tdy=$(date +%y) # two digit year
- tdd=$(date +%d) # two digit day
- fpl="/var/www/flatpress/fp-content/content/" # where does the information go?
- hom="/home/chirp/" # where is the post?
- msg="message.txt" # what do we call the post?
- upd="fpupdate.php" # The updater script.
- # End of variable list
- # Check to see if our directories exist.
- if [ ! -d "$fpl$tdy" ]
- then
- echo "Creating directory ""$fpl$tdy"
- mkdir "$fpl$tdy"
- chown www-data:www-data "$fpl$tdy"
- chmod 777 "$fpl$tdy"
- else
- echo "The directory ""$fpl$tdy"" already exists."
- fi
- if [ ! -d "$fpl$tdy$/$tdm" ]
- then
- echo "Creating directory "$fpl$tdy/$tdm"
- mkdir "$fpl$tdy/$tdm"
- chown www-data:www-data "$fpl$tdy/$tdm"
- chmod 777 "$fpl$tdy/$tdm"
- else
- echo "The directory ""$fpl$tdy/$tdm"" already exists."
- fi
- # End of directory check.
- # Insert the content into the database
- contentdata="$fpl$tdy/$tdm/"
- epoch=$(date +%s)
- # We need the epoch time because that's going to be our insertion time. It doesn't
- # really matter if the insertion is off by a few seconds. Well, it doesn't to me, and
- # I'm the one writing the script.
- #
- # Now, we already have the day of insertion, that's not going to change unless your
- # machine is really slow. But we do need the time of day.
- if [ "$tdd" -ge "10" ]
- then
- n=4
- else
- n=5
- fi
- # The date returned may have an extra delimiting space if DOM is less than 10
- tod=`date -d @$epoch | cut -d " " -f $n | tr -d ":"`
- # create the entry name
- entry="entry$tdy$tdm$tdd-$tod.txt"
- # Here's the fun part. Now that we have a filename to write, we need to create the content.
- # The message file is a flat list:
- # Line 1: Post title
- # Line 2: Post author
- # Line 3: Post category (as a number, must be in your categories list)
- # Line 4: Content. May span multiple lines. Use line formatting to span lines (i.e. \n)
- #
- # commslock is added to all categories to prevent comments!
- # Comment out the next line to allow comments.
- lck="commslock,"
- # If you've locked comments with a plugin, this may do nothing or something unexpected!
- pst="$hom""$msg"
- # Yes, I know there are better ways to do this. However this is quick and it works.
- tit=`cat $pst | head -1 | tail -1` # heh heh I said tit
- aut=`cat $pst | head -2 | tail -1`
- ctg=`cat $pst | head -3 | tail -1`
- cnt=`cat $pst | tail -n +4`
- # Title, author, category, content.
- ctl="$lck""$ctg"
- # Add lock to post. If lck is empty, then nothing is added. Amazing!
- # Now, we need to create the actual file to insert into the database.
- # If you want newlines, make sure to use \n after your lines.
- # That is:
- # This is a line of content.\n
- # This is a new line of content.
- # This line will appear on the same line as before.
- # VERSION|fp-1.0|SUBJECT|Test post|CONTENT|There's nothing here yet!|AUTHOR|mynameisontheserver|DATE|1460056632|CATEGORIES|commslock,3|
- qqq="VERSION|fp-1.0|SUBJECT|""$tit""|CONTENT|""$cnt""|AUTHOR|""$aut""|DATE|""$epoch""|CATEGORIES|""$ctl""|"
- echo $qqq
- echo "Placing into file ""$entry"
- echo -e $qqq > "$contentdata""$entry"
- # The information has been inserted into the directory, now we need to run the rebuild script.
- # Again, pay attention to who runs this particular script. It will kill your database.
- # I am going to assume that your php file is located in /var/www/flatpress and your php binary is /usr/bin/php
- # Modify if not.
- /usr/bin/php -f "/var/www/flatpress/rebuild.php"
- # You can move the content file if you want, or simply delete it
- # On second thought, this may not work depending on who owns the file.
- rm "$pst"
- # All done!
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement