umm how can I start to script such thing?

do you have something specific in mind?

it would be nice to be posted in a repository, others may find it useful