Recursively checking out ports tree

I’ve come across a problem posted on #bsdports channel few days ago, how to download a port (FreeBSD) and its dependencies without checking out complete ports tree. So, I hacked a solution for this in Haskell to celebrate my recently attained bliss moment:

λ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load download-portstree.hs
[1 of 1] Compiling Main             ( download-portstree.hs, interpreted )
Ok, modules loaded: Main.
*Main> downloadPortsTree "editors/emacs-nox11"
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package mtl-2.1.2 ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package bytestring-0.10.0.2 ... linking ... done.
Loading package old-locale-1.0.0.5 ... linking ... done.
Loading package time-1.4.0.1 ... linking ... done.
Loading package unix-2.6.0.1 ... linking ... done.
Loading package filepath-1.3.0.1 ... linking ... done.
Loading package directory-1.2.0.1 ... linking ... done.
Loading package process-1.1.0.2 ... linking ... done.
PortsList {portsSeen = fromList ["converters/libiconv","devel/gettext","devel/gmake","devel/libffi","devel/ncurses","devel/pkgconf","editors/emacs-nox11","lang/perl5.16","math/gmp","print/indexinfo","security/ca_root_nss","security/gnutls","security/libgpg-error","security/libtasn1","security/nettle","security/openssl","security/p11-kit","textproc/libxml2"], portsNew = fromList []}
Checking out port editors/emacs-nox11
Checking out port devel/gmake
Checking out port converters/libiconv
Checking out port devel/gettext
Checking out port devel/ncurses
Checking out port devel/pkgconf
Checking out port print/indexinfo
Checking out port security/gnutls
Checking out port lang/perl5.16
Checking out port security/libgpg-error
Checking out port security/libtasn1
Checking out port security/nettle
Checking out port math/gmp
Checking out port security/openssl
Checking out port security/p11-kit
Checking out port devel/libffi
Checking out port security/ca_root_nss
Checking out port textproc/libxml2

Happy hacking lambdas… ;)

Sagittarius Scheme — FreeBSD port

Created a FreeBSD port for Sagittarius Scheme for fun1, and have this:

SHA256 (sagittarius-scheme-0.5.5.tar.xz) = 1ddf2841af2d79ddf2a54346e97fe7c0e45b9c486df69b866d60e2e6c89f7e03

The only issue pending is, fixing building on 10-CURRENT, and 11-CURRENT (i386) platforms, which I need some time to look.

[UPDATE: There you go]

HTH


1In memory of a sagittarian, I once knew.

Free

“A man can be himself so long as he is alone. If he does not love solitude, he will not love freedom; for it is only when is alone that he is really free.” (Arthur Schopenhauer)

Sadist Elephant

        Once upon a time, there were five blind men who had the opportunity
to experience an elephant for the first time.  One approached the elephant,
and, upon encountering one of its sturdy legs, stated, "Ah, an elephant is
like a tree."  The second, after exploring the trunk, said, "No, an elephant
is like a strong hose."  The third, grasping the tail, said "Fool!  An elephant
is like a rope!"  The fourth, holding an ear, stated, "No, more like a fan."
And the fifth, leaning against the animal's side, said, "An elephant is like
a wall."  The five then began to argue loudly about who had the more accurate
perception of the elephant.
        The elephant, tiring of all this abuse, suddenly reared up and
attacked the men.  He continued to trample them until they were nothing but
bloody lumps of flesh.  Then, strolling away, the elephant remarked, "It just
goes to show that you can't depend on first impressions.  When I first saw
them I didn't think they'd be any fun at all."

Listing FreeBSD packages in order of dependency

So, I upgraded GHC (via pkg) few minutes ago, and didn’t upgrade any of hs- packages, which means now their registration information is gone from GHC’s cache. So as a workaround I just decided to invoke their corresponding register.sh which would result in their package being registered:

λ pkg info |awk '/^hs-/ { print $1; }' |xargs -n1 pkg info -l |fgrep register.sh |xargs -n1 sudo /bin/sh

This was ideal command except it didn’t work because package list (pkg info) was not topologically sorted. And RTFM-ing pkg info didn’t result in any option which could output topologically sorted listing. But thanks to pkg info -d which generates the list of dependencies, I hacked this, which worked:

λ pkg info |awk '/^hs-/ { print $1; }' |xargs -n1 pkg info -d |awk '/^[[:space:]]+hs-/ { print $1; }'  |sort |uniq -c |sort -k1 -nr |awk '{ print $2; }' |sed -re 's/-[[:digit:]._,]+$//g' |xargs -n1 pkg info -l |fgrep register.sh |xargs -n1 sudo /bin/sh

:)

Duplicity

Recently I needed to do some backups on a host (not managed by me), and being somewhat paranoid, and lazy, I didn’t schedule backups for sometime. Recently while trying to be just paranoid, I decided it’s finally time to close this task pending for a while, so gave a shot to duplicity again. Its manpage is quite well written, and so is the software.

My backup provider offers SFTP space (courtesy: ProFTPD, I think). So to login to SFTP account, I created a SSH public key to be used by backup script, and converted it into RFC4716 format (ssh-keygen -e), and uploaded to remote host. For encrypting backups, I used GPG, so generated a GPG key locally, and copied the public key to the host which is to be backed up. Since decryption of backups is not needed, unless it’s to be restored therefore I don’t need to copy private GPG key on remote host.

Now with a duplicity command-lines similar to below, I was able to do full, and incremental backups respectively:

duplicity full --encrypt-key ${GPG_KEY} --log-file=${LOG_FILE} ${SOURCE_DIRECTORY_TO_BACKUP} scp://${BACKUP_USER}@${BACKUP_HOST}/${BACKUP_DIRECTORY}
duplicity incremental --encrypt-key ${GPG_KEY} --log-file=${LOG_FILE} ${SOURCE_DIRECTORY_TO_BACKUP} scp://${BACKUP_USER}@${BACKUP_HOST}/${BACKUP_DIRECTORY}

And to periodically clean old backups:

duplicity remove-all-but-n-full --force  --log-file=${LOG_FILE} ${NUMBER_OF_OLD_BACKUPS_TO_KEEP} scp://${BACKUP_USER}@${BACKUP_HOST}/${BACKUP_DIRECTORY}

That’s it. Put these things in a script in a cron job scheduled at appropriate times, I can now do encrypted backups. As an anonymous guy puts it:

It’s better to have dump-ed, and restored, than to never have dumped at all

Now go backup yourself!