_      _            _
         _ __ ___ (_) ___| | __  _ __ | |
        | '_ ` _ \| |/ _ \ |/ / | '_ \| |
        | | | | | | |  __/   < _| | | | |
        |_| |_| |_| |\___|_|\_(_)_| |_|_|
                  | |
                  |_|       Thoughts on (technical) stuff...
You're from: 54.242.188.217

January 2009 Archives

Jan 31 2009

rdup 0.7.0

Posted in rdup; by Miek Gieben; comments: 0

rdup 0.7.0 has just been released. This is a major bug fix release and until I release 1.0.0 I will only make further bug fixes to rdup (and rdup-tr and rdup-up).

Also the internal filelist has seen some changes, so if you start using this version you will get a (much) larger backup then you might expect.

The changelog reads

-- major bugfixes, internal filelist format change --
- slowly going to a 1.0.0 release -
* version bumped to 0.7.0 as the internal file list format
has changed. Using this new version as a drop-in replacement
for 0.6.6 you will get a larger backup then you expected.
* rdup-backups.7: typo (Johann Klähn)
* rdup-simple.sh: check for a minimum of 2 arguments (Tom Hendrikx)
* rdup-simple.sh: fix -f (full dump)
* rdup-up: add mkpath (works like mkdir -p) function and fix -t option
(reported by Tom Hendrikx)
* rdup-simple.sh/rdup-ln.sh: only report errors on stderr, for the rest 
use stdout (Tom Hendrikx)
* rdup: honor .nobackup files again (Tom Hendrikx)
* rdup: Add filesize and linktype to the internal filelist - this is mostly to
better support hard- and softlinks.
* rdup: allow comments in the internal filelist, this is completely
useless except that rdup now writes a line describing what's in the
filelist using a comment: '# blaa ' etc.
* rdup, rdup-tr, rdup-simple: handle link removals better and add
a test case that will test this specific bug (reported by Tom
Hendrikx)
* small document tweaks and cleanups

See the project page or download the new version directly.


Jan 30 2009

A 'more...' link in nanoblogger

Posted in nanoblogger, site; by Miek Gieben; comments: 2

Update (200911-08): I've stopped using this, because it made the archive generating fail in mysterious ways...

As you might have seen I have now these nice (opinions may vary) "more..." links in my blog. This is done with some JavaScript and shell foo and in this entry I will explain how I did it.

The setup also works with text browsers and people who disable JavaScript. In the latter case you will get the normal nb behavior where you see the entire article. When using a text browser you also see the entire article but there is also a (non functional) 'more' link.

User side

When writing a blog entry the only thing you need to do is to put the following on a line

- read more -

(technically you need more -'s to make it work, but this will suffice for this example).

Anything you type below that line will become collapsible with a 'more' link. Anything above will be directly visible.

Implementation

First a shell script which reads your entire blog entry and replaces the - read more- with the html and JavaScript to make it work.

#!/bin/bash
EPOCH=$(date +%s)
ART_ID="art_$$_$EPOCH"
HREF_ID="href_$$_$EPOCH"
DATA=$(cat)

# escape galore
repl="<script type=\"text\/javascript\">\n\
<!--\n\
function toggle_visibility(id, anchor) {\n\
   var e = document.getElementById(id);\n\
   var a = document.getElementById(anchor);\n\
   if(e.style.display == 'block') {\n\
      e.style.display = 'none';\n\
      a.innerHTML = \"\&laquo; more ...\";\n\
   } else {\n\
      e.style.display = 'block';\n\
      a.innerHTML = \"\&laquo; less\";\n\
   }\n\
}\n\
\/\/-->\n\
<\/script>\n\
<div class=\"readmore\">\n\
<a class=\"readmore\" style=\"display: none;\" id=\"$HREF_ID\"\n\
href=\"javascript:\/\/\" onclick=\"toggle_visibility(\'$ART_ID\', \'$HREF_ID\');\">\
\&raquo; more ...<\/a>\n\
<\/div>\n\
<div id=\"$ART_ID\">\n\
<script type=\"text\/javascript\">\n\
<!--\n\
e = document.getElementById('$ART_ID');\n\
e.style.display = 'none';\n\
e = document.getElementById('$HREF_ID');\n\
e.style.display = 'block';\n\
\/\/-->\n\
<\/script>\n\
"
if echo "$DATA" | egrep -q -- '-{3,}.?read.more.?-{3,}'; then
echo "$DATA" | sed -r "s/-{3,}.?read.more.?-{3,}/$repl/"
echo "</div> <!-- id=$ART_ID -->";
else
echo "$DATA"
fi

As I'm using stdin twice I am capturing it in the variable $DATA.

The variable $repl is filled and is used by sed the replace - read more-. It was a real pain to correctly quote everything (as you might see).

The JavaScript trick to do this collapsing can be easily found on the internet (google: hide/show divs).

interfacing with nanobloggger

You need to edit two templates, entry.htm and permalink.htm, in the first one you enable the 'read more'-feature and the latter you need to get rid of the '- read more -' line.

entry.htm

In entry.htm replace

$NB_EntryBody

with

$(echo "$NB_EntryBody" | ${BLOG_DIR}/bin/readmore)

Adjust this to where you have saved the shell script from above.

permalink.htm

On your permalink page this read more stuff is ridiculous, so there we must get rid of it.

Where it says

$NB_EntryBody

replace that with

$(echo "$NB_EntryBody" | sed -r 's/-{3,}.?read.more.?-{3,}//')

to filter out the line.


Jan 30 2009

rdup 0.6.6 bugs

Posted in rdup, bugs; by Miek Gieben; comments: 0

As I'm without a bug database I'm abusing my blog for it.

The following bugs were reported (and fixed) in rdup. Thanks to Tom Hendrikx for reporting and fixing some of the issues mentioned here.

incremental backups of symlinks

Incremental backup of symlink and hardlink were b0rked, this is now fixed (revision r1780 and r1781) but this required a change to the internal filelist which is used by rdup.

rdup-simple with one argument

rdup-simple would just go ahead even if you only give it one argument. This is fixed in revision r1775.

rdup-simple -f without any previous backup

This would fail, because the leading directories are not created by rdup-up. This is fixed in revision r1777 by including a mkpath() function and extending the -t flag of rdup-up a little.

rdup-simple output to stderr

Now only the errors are printed to stderr, the rest if echoed to stdout. See revision r1778

.nobackup are not respected

Normally if a .nobackup file is found in a directory the directory is excluded from the backup.

This is fixed in revision r1779.

Due to the internal file format change, the next version of rdup will be 0.7.0 and we are closely going to a 1.0.0 release.


Jan 26 2009

Nanoblogger comments (update)

Posted in nanoblogger, site; by Miek Gieben; comments: 0

Basicly these blog items serve as a personal reminder and documentation. Also the code needs to be refactored a bit and some html tags need to be removed from it.

Files needed

The following files are needed for this comment system:

  • comment.php, this is the PHP file the implements everything

  • nbadmin, a small shell script that implemented the comment moderation (just a mv of the comment to the correct directory)

  • nbnofity, small shell script that notifies you a new comments (to be put in cron)

  • com.css, the css code for the comment pages.

Templates

In your templates you will need to require the php script, so a

require_once "/home/miekg/miek.nl/comment.php";

must be there somewhere.

Further more all pages that do something with comments need the following code:

  • Get the current comments and put them in a PHP array

$comments = gather("$NB_EntryID");

  • Show the current comments as HTML

show($comments);

  • Check the current form input and act accordingly

if ($_POST['preview'] == "Preview Comment") {
        preview();
}
if ($_POST['submit'] == "Submit Comment") {
        submit();
}

  • Show the comment input form

form("$NB_EntryID");

  • Show a "recent comment" section in your side title

recent_comments();

And that should be it.


Jan 24 2009

NB comments

Posted in nanoblogger, site; by Miek Gieben; comments: 5

I've implemented a simple comment system in which

  • there are no user accounts
  • has a preview function
  • once a comment is submitted you cannot edit it anymore
  • all comments are moderated
  • a small set of BB tags are allowed
  • implemented as one PHP file
  • the PHP script has some html in it
  • needs a writeable directory in your document root

You need this file: comment.php.

The first few lines allow for some customization:

$NB_TIME = "%Y-%m-%d %T %Z"; # strftime function
$NB_COM_BASE="/home/miekg/miek.nl/blog/comments";
$NB_COM = 1;    # 0 -> disable comments
$NB_COM_CLOSE = 2592000; # number of seconds after which comments are closed
$NB_COM_MAX_SIZE = 2000; # max number of chars in a comment

which have the following meaning:

  1. NB_TIME: how to format the time and date of the comment
  2. NB_COM_BASE: where to put the comment files
  3. NB_COM: emergency comment disable, when 0 all commenting is disabled
  4. NB_COM_CLOSE: number of seconds when commenting on an article is disabled
  5. NB_COM_MAX_SIZE: maximum number of character per comment.

In NB_COM_BASE all comments are put, each article gets a directory named after its $NB_EntryID. In that directory, two sub dirs are made ok and new. All comments are first put in the new directory, where they wait for moderation. See below for the moderation script.

Further more you need to tweak apache to allow PHP code in .html files or make nb create .php files.

In all files you will need to following code:

<?php
require "/home/miekg/miek.nl/comment.php";
?>

Of course you need to use a different path for your situation.

comment string

In articles you will need something like comments: (5) with comment.php the following is needed (remember the shell is touching this code too, so you'll need to escape the PHP stuff):

<?php
echo commentstr($NB_EntryID, ${ARCHIVES_PATH}$NB_EntryPermalink);
\$comments =  gather($NB_EntryID);
echo "(" . count(\$comments) . ")";
?>

Or whatever you want to put there. The gather() function will retrieve the current comments of this article. It will also create a link to the permalink of the article as I decided that new comments are to be added there.

adding comments

In my permalink template I have the following code: Note: 1) the shell is touching is and 2) my templates are written in m4, where I've made '[' and ']' mean something, hence the double '[[' and ']]'):

<?php
show(\$comments);
if (\$_POST[['preview']] == "Preview Comment") {
    preview();
}
if (\$_POST[['submit']] == "Submit Comment") {
    submit();
}
form("$NB_EntryID");
?>

Well this kinda speaks for itself. A user can preview comments when pressing 'Preview' in the form and for submitting submit is pressed.

The form() function displays the commenting form.

moderation script

After a comment has been left in the new/ directory it needs to be moved to the ok/ dir. I've written nbadmin for this purpose. A typical run looks like this:

> Article: e2009-01-12T19_34_47.txt
 >> Comment found: 1232783070_uvTSOy
<a href="http://miek.nl">Miek Gieben</a>
Test 123
(A)approve (D)discard (N)skip [A]: A
new/1232783070_uvTSOy ok/1232783070_uvTSOy

And with that the comment is okayed.

cron job

Of course you want to be notified of new comments, this is implemented as a cronjob which checks if there are any files in a new/ directory.

The quick and dirty script:

#!/bin/sh
# send email for the comments that are found in my website
COM_BASE="/home/miekg/miek.nl/blog/comments"
BODY=""

for art in $COM_BASE/*.txt; do
for com in $art/new/*; do
    if [ $com = $art/new/* ]; then continue; fi
    BODY="$BODY\n o $com"
done
done

if [ ! -z "$BODY" ]; then
echo "New comments found for miek.nl"
echo ${BODY}
fi

And my cronjob:

% crontab -l
MAILTO=miek@atoom.net
# check if there are new comments
10 8-22/2 * * * /home/miekg/bin/nbnotify

Jan 19 2009

Simple audio player

Posted in life, linux; by Miek Gieben; comments: 1

Thank God for audacious.

I just want to play my nicely ordered music without the need to open up playlists, start a server and what not.

Audacious is just a ... simple ... audio ... player like go'old xmms.

But xmms is no longer... The guys that wrote xmms decided they needed a client/server model for xmms2, so basically they rewrote mpd.

All "advanced" players suffer from the same feature creep and have too much options. Most of these don't even fit on the screen of my (much beloved) 701 EeePC.

I just want to click on a directory and play the mp3's inside. And audacious allows me to do to. (And then I haven't even begun to mention the tons of plugins that are available).


Jan 17 2009

Nanoblogger comments

Posted in nanoblogger, site; by Miek Gieben; comments: 1

I've been thinking about comments on my blog ever since I started using nanoblogger. While nb is great (with VIM and markdown) I'm starting to miss the comment stuff.

Comment systems for nb

I've been searching for a good comment system that I want to use for nb. It should meet the following criteria:

  1. Simple moderation system. With all the spam nowadays every comment made should be moderated.
  2. Should not require a database, the filesystem is enough of a database to handle these tasks. This does imply that there will be no user accounts, nor the possibility to edit your comments.
  3. Simple interface with nanoblogger.

I've looked at blogkomm, haloscan and cgicomment.

blogkomm

Looks nice, easy to setup, but I could not get the moderation to work. Also I looked like all the comments are kept in a single file called comments.txt, but I prefer the comments to be more linked to the article they belong to.

haloscan

This is a external site which takes care of the comments. So here I'm I running nb because I prefer to keep things simple and then I outsource my comment system to a site which I do not control and which does rely on databases and what not.

cgicomment

Could ... not ... found ... the ... damn ... thing ... anywhere.

Conclusion

I need to write my own system. I have the following in mind:

  • Simple PHP based system
  • All comments are put in a 'to-be-moderated' directory. A simple tool called nbadmin will control if a comment is let through. You can compare it with listadmin which you can use when you use mailman. If you 'OK' a comment, the comment will be moved to another directory,
  • Notification of new comments to 'someone'. This will probably will be implemented as a cron job which scans the 'to-be-moderated' directories.
  • Some PHP functions which allow the display of comments and which can be integrated with the rest of nanoblogger.

The implementation will (probably) result in one PHP file called comment.php which needs to be included in your templates.

I'm still in the early stages of this project and I do not yet know if it will work like I want.


Jan 12 2009

rdup 0.6.6

Posted in rdup; by Miek Gieben; comments: 0

Hot on the heels of 0.6.5 I'm releasing 0.6.6 which fixes two annoying bugs.

Again look at the project page or download it.


Jan 10 2009

rdup 0.6.5

Posted in rdup; by Miek Gieben; comments: 0

Rdup 0.6.5 was just released with a few bugfixes and the inclusion of rdup-simple.sh.

See the project page for more info or download it right away.


Jan 02 2009

Future of rdup-utils

Posted in rdup; by Miek Gieben; comments: 0

From 0.6.2 the rdup-utils, then consisting out of rdup-gzip, rdup-crypt, rdup-gpg, rdup-simple, rdup-snap and rdup-snap-link, was split off to lead a life of its own.

This was the end of the utils and I wanted to concentrate solely on rdup.

However, after the split, I created a tool called rdup-tr. It is written in C and is a generic transform tool, which can do everything rdup-gzip, rdup-crypt and rdup-gpg could do and more. With rdup-tr you can also generate tar, pax or cpio archives. See this post for more info.

rdup-snap is used to update a directory structure with an rdup archive. It is written in Perl. As writing rdup-tr was not that difficult I decided that rdup-snap should also be rewritten in C. This lead to the creation of rdup-up, click here for more info.

So from the original utils, only the shell wrapper rdup-simple and rdup-snap-link (a small helper utility which figures out what kind of backup should be made and which hardlinks any previous backup) were left. rdup-snap-link came back as rdup-ln.sh, which is now installed in /usr/lib/rdup. rdup-simple was gone, but the core of the shell script is now documented in rdup-backups(7).

So to summarize, only rdup-simple has no equivalent in rdup version 0.6.4. And while thinking about it, I think it should, but then also as something that is installed in /usr/lib/rdup as rdup-simple.sh.

For 0.6.5 I'm doing a little rewrite so the rdup-simple.sh works with rdup-tr and rdup-up. My original plan was to not do any development on the extra utilities, but this seems to be impossible :-)


Jan 01 2009

moved to our new house

Posted in news, life; by Miek Gieben; comments: 0

We have finally moved to our new house and it is great. Of course there were some last minute bugs, but they are all solved now and we are enjoying our new house.

No real internet as of yet, but the glass fiber is going to be connected next week or so.

And in other good news, I just learned there is a new Night Rider series :-)

Happy new year :-)