Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: be8b49245a
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 85 lines (70 sloc) 2.616 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#!/bin/bash
#
# Copyright (c) 2012 Mathieu Roy <yeupou--gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

# Will source ~/.tumblr-daily-postrc
# Then
# Will go into $CONTENT where two subdirs exists: queue and over
# It will take the first file in queue/ (pulled with git) and
# post it to $DEST (tumblr post by email address) with mutt,
# move it to over/ then commit the change with git
#
# Important:
#
# - there is no default for $DEST, it must be set in ~/.tumblr-daily-postrc
# - $CONTENT is by default ~/tumblr
# - mutt must be set up to use gmail smtp (smtp_url/smtp_pass in .muttrc)
# otherwise tumblr will not handle the mail (alternative $MUTTRC
# can be set)
# - git will not be used if $USEGIT is not set to 1
#
# This was designed to be set up as a daily cronjob


WHOAMI=`whoami`
RC=/home/$WHOAMI/.tumblr-daily-postrc
MUTTRC=/home/$WHOAMI/.muttrc
CONTENT=/home/$WHOAMI/tmp/tumblr
DEST=0
USEGIT=1

# Wont run as root
if [ `whoami` == "root" ]; then echo "Not supposed to run as root, die here" && exit; fi

# Must have a rcfile to get DEST (could redefine CONTENT)
if [ ! -r $RC ]; then exit; fi
source $RC
if [ "$DEST" == 0 ]; then echo "DEST unset after reading $RC, die here" && exit; fi

# Go inside content
if [ ! -d $CONTENT ]; then echo "$DEST not found/not a directory, die here" && exit; fi
cd $CONTENT

# Update content
if [ "$USEGIT" == 1 ]; then git pull >/dev/null 2>/dev/null; fi

# Mutt need some empty file to succesfully send a mail without content
FAKEMAIL=`mktemp`

# Select the first file
FILE=queue/`ls -1 --color=no queue/ | head -1`

# Stop silently if the queue is empty
if [ ! -f "$FILE" ]; then exit; fi

# Otherwise, mail it
mutt $DEST -F $MUTTRC -a $FILE < $FAKEMAIL

# Commit the change
mv $FILE over/
if [ "$USEGIT" == 1 ]; then
git add over/*
    git commit -am 'Daily post' >/dev/null
    git push >/dev/null 2>/dev/null
fi

# Cleanup
rm -f $FAKEMAIL


# EOF
Something went wrong with that request. Please try again.