#! /bin/sh # vim: set ft=sh sw=4 et: # postinst script for monotone-server # # see: dh_installdeb(1) set -e # source debconf stuff . /usr/share/debconf/confmodule # we only want to change these values on the initial configuration gen_pass () { # this used to use $RANDOM, but dash doesn't have that # also, the perl version is clearer MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" LENGTH="$1" if [ -z "$LENGTH" ]; then LENGTH=8 fi PASS=`perl -e ' @matrix = split //, $ARGV[0]; $length = $ARGV[1]; print $matrix[int(rand($#matrix + 1))] for 1..$length; print "\n"; ' "$MATRIX" "$LENGTH"` } case "$1" in configure) # set the default monotone keyname db_set monotone-server/key "monotone@`hostname --fqdn`" db_input medium monotone-server/manage-db || true db_go || true # make sure we should manage things db_get monotone-server/manage-db if [ "$RET" = "true" ]; then db_input low monotone-server/key || true db_input low monotone-server/passphrase || true db_go || true # no passphrase was entered, generate one # make sure this is the initial configuration db_get monotone-server/passphrase if [ -z "$RET" ] && [ -z "$2" ]; then gen_pass db_set monotone-server/passphrase "$PASS" fi fi ;; reconfigure) db_input medium monotone-server/manage-db || true db_go || true # make sure we should manage things db_get monotone-server/manage-db if [ "$RET" = "true" ]; then db_input low monotone-server/key || true db_input low monotone-server/passphrase || true db_go || true # Now let's store the passphrase and key in a file. We only do # this on reconfigure, postinst handles this in all other cases. MTN_CONFDIR=/etc/monotone db_get monotone-server/key MTN_KEY="$RET" db_get monotone-server/passphrase MTN_KEY_PASSWD="$RET" echo "$MTN_KEY \"$MTN_KEY_PASSWD\"" > $MTN_CONFDIR/passphrases db_set monotone-server/passphrase "" fi ;; *) echo "config called with unknown argument \`$1'" >&2 exit 1 ;; esac