Advertisement
Guest User

Flatpress Blog auto-bot-insert script

a guest
Apr 8th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # A script to see if the directory structure for flatpress exists,
  4. # if not, then create it, then add a pre-determined content file to
  5. # the database. Requires the flatpress php index rebuilder script.
  6. # This absolutely needs to be run as your webserver user, otherwise it
  7. # will completely bork your flatpress database. Trust me on this one.
  8.  
  9. # This is version 0.9 and the type is BETA
  10.  
  11. # I think we can assume you've already installed flatpress at this point.
  12.  
  13. # What do we need to know beforehand?
  14.  
  15. tdm=$(date +%m) # two digit month
  16. tdy=$(date +%y) # two digit year
  17. tdd=$(date +%d) # two digit day
  18. fpl="/var/www/flatpress/fp-content/content/" # where does the information go?
  19. hom="/home/chirp/" # where is the post?
  20. msg="message.txt" # what do we call the post?
  21. upd="fpupdate.php" # The updater script.
  22.  
  23. # End of variable list
  24.  
  25. # Check to see if our directories exist.
  26.  
  27. if [ ! -d "$fpl$tdy" ]
  28. then
  29. echo "Creating directory ""$fpl$tdy"
  30. mkdir "$fpl$tdy"
  31. chown www-data:www-data "$fpl$tdy"
  32. chmod 777 "$fpl$tdy"
  33. else
  34. echo "The directory ""$fpl$tdy"" already exists."
  35. fi
  36.  
  37. if [ ! -d "$fpl$tdy$/$tdm" ]
  38. then
  39. echo "Creating directory "$fpl$tdy/$tdm"
  40. mkdir "$fpl$tdy/$tdm"
  41. chown www-data:www-data "$fpl$tdy/$tdm"
  42. chmod 777 "$fpl$tdy/$tdm"
  43. else
  44. echo "The directory ""$fpl$tdy/$tdm"" already exists."
  45. fi
  46.  
  47. # End of directory check.
  48.  
  49. # Insert the content into the database
  50.  
  51. contentdata="$fpl$tdy/$tdm/"
  52. epoch=$(date +%s)
  53.  
  54. # We need the epoch time because that's going to be our insertion time. It doesn't
  55. # really matter if the insertion is off by a few seconds. Well, it doesn't to me, and
  56. # I'm the one writing the script.
  57. #
  58. # Now, we already have the day of insertion, that's not going to change unless your
  59. # machine is really slow. But we do need the time of day.
  60.  
  61. if [ "$tdd" -ge "10" ]
  62. then
  63. n=4
  64. else
  65. n=5
  66. fi
  67.  
  68. # The date returned may have an extra delimiting space if DOM is less than 10
  69.  
  70. tod=`date -d @$epoch | cut -d " " -f $n | tr -d ":"`
  71.  
  72. # create the entry name
  73.  
  74. entry="entry$tdy$tdm$tdd-$tod.txt"
  75.  
  76. # Here's the fun part. Now that we have a filename to write, we need to create the content.
  77. # The message file is a flat list:
  78. # Line 1: Post title
  79. # Line 2: Post author
  80. # Line 3: Post category (as a number, must be in your categories list)
  81. # Line 4: Content. May span multiple lines. Use line formatting to span lines (i.e. \n)
  82. #
  83. # commslock is added to all categories to prevent comments!
  84. # Comment out the next line to allow comments.
  85. lck="commslock,"
  86.  
  87. # If you've locked comments with a plugin, this may do nothing or something unexpected!
  88.  
  89. pst="$hom""$msg"
  90.  
  91. # Yes, I know there are better ways to do this. However this is quick and it works.
  92.  
  93. tit=`cat $pst | head -1 | tail -1` # heh heh I said tit
  94. aut=`cat $pst | head -2 | tail -1`
  95. ctg=`cat $pst | head -3 | tail -1`
  96. cnt=`cat $pst | tail -n +4`
  97.  
  98. # Title, author, category, content.
  99.  
  100. ctl="$lck""$ctg"
  101.  
  102. # Add lock to post. If lck is empty, then nothing is added. Amazing!
  103.  
  104. # Now, we need to create the actual file to insert into the database.
  105.  
  106. # If you want newlines, make sure to use \n after your lines.
  107. # That is:
  108. # This is a line of content.\n
  109. # This is a new line of content.
  110. # This line will appear on the same line as before.
  111.  
  112. # VERSION|fp-1.0|SUBJECT|Test post|CONTENT|There's nothing here yet!|AUTHOR|mynameisontheserver|DATE|1460056632|CATEGORIES|commslock,3|
  113.  
  114. qqq="VERSION|fp-1.0|SUBJECT|""$tit""|CONTENT|""$cnt""|AUTHOR|""$aut""|DATE|""$epoch""|CATEGORIES|""$ctl""|"
  115. echo $qqq
  116. echo "Placing into file ""$entry"
  117. echo -e $qqq > "$contentdata""$entry"
  118.  
  119. # The information has been inserted into the directory, now we need to run the rebuild script.
  120. # Again, pay attention to who runs this particular script. It will kill your database.
  121.  
  122. # I am going to assume that your php file is located in /var/www/flatpress and your php binary is /usr/bin/php
  123. # Modify if not.
  124.  
  125. /usr/bin/php -f "/var/www/flatpress/rebuild.php"
  126.  
  127. # You can move the content file if you want, or simply delete it
  128. # On second thought, this may not work depending on who owns the file.
  129.  
  130. rm "$pst"
  131.  
  132. # All done!
  133.  
  134. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement