Replaced /var/state/lunar/packages with a sqlite database.

This also has the happy side-effect of eliminating the need
for /var/state/lunar/packages.backup, and eliminating lots of
calls to "lockfile", because sqlite3 deals with modifying
data in-place, and handles its own locking arrangements.

The schema for the database wasn't quite as simple as I'd hoped,
because it turns out that it's possible for a module to have multiple
states.  This means that it's best to have a separate table just for
module state, and a join table to tie them together.  This made the
SQL queries a bit more involved than I'd originally anticipated.