#!/bin/sh
# an installation script for monkeysphere (borrowing liberally from
-# Wnn6's port and from monkeysphere's debian/monkeysphere.postinst)
+# postgresql and mysql pkg-install scripts, and from monkeysphere's
+# debian/monkeysphere.postinst)
# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
# Copyright 2008
# FIXME: is /var/lib/monkeysphere the right place for this stuff on
# FreeBSD?
-VARLIB="/var/lib/monkeysphere"
-check_pw()
-{
- if which -s pw; then
- :
- else
- cat <<EOF
+# PostgreSQL puts its data in /usr/local/pgsql/data
-This system looks like a pre-2.2 version of FreeBSD. We see that it
-is missing the "pw" utility. We need this utility. Please get and
-install it, and try again. You can get the source from:
+# MySQL puts its data in /var/db/mysql
- ftp://ftp.freebsd.org/pub/FreeBSD/FreeBSD-current/src/usr.sbin/pw.tar.gz
-
-EOF
- exit 1
- fi
-}
-
-ask() {
- local question default answer
-
- question=$1
- default=$2
- if [ -z "${PACKAGE_BUILDING}" ]; then
- read -p "${question} (y/n) [${default}]? " answer
- fi
- if [ x${answer} = x ]; then
- answer=${default}
- fi
- echo ${answer}
-}
-
-yesno() {
- local dflt question answer
-
- question=$1
- dflt=$2
- while :; do
- answer=$(ask "${question}" "${dflt}")
- case "${answer}" in
- [Yy]*) return 0;;
- [Nn]*) return 1;;
- esac
- echo "Please answer yes or no."
- done
-}
-
-failure() {
- local retval badgroups badusers
- retval=$1
- badgroups=`getent group monkeysphere 641`
- badusers=`getent passwd monkeysphere 641`
-
- if [ X"$badgroups" != X ]; then
- badgroups="
-Conflicting group(s):
-
-$badgroups"
- fi
-
- if [ X"$badusers" != X ]; then
- badusers="Conflicting user(s):
-
-$badusers"
- fi
-
- cat <<EOF
-
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-This port or package assumes that the ID number of 'monkeysphere' will
-be 641. But this system has:
-$badgroups
-$badusers
-
-Please correct these conflict(s) and try again.
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-EOF
- exit $retval
-}
+VARLIB="/var/monkeysphere"
+ETCDIR="/usr/local/etc/monkeysphere"
case $2 in
POST-INSTALL)
-
- # make sure that the correct user and group are present:
- id_monkeysphere=`id -u monkeysphere 2> /dev/null`
- gid_monkeysphere=`getent group monkeysphere | cut -f3 -d: 2> /dev/null`
- if [ X"$id_monkeysphere" = X641 ] && [ X"$gid_monkeysphere" = X641 ];then
- exit 0
- else
- # add an account 'monkeysphere' to this system
- echo ""
- echo "You need an account 'monkeysphere' whose ID number is 641, with group 'monkeysphere' (GID 641)"
- if yesno "Would you like to create it automatically?" y; then
- # We need a command 'pw(8)'
- check_pw
- pw groupadd monkeysphere -g 641 || failure $?
- pw useradd monkeysphere -u 641 -g 641 -h - -d "$VARLIB" \
- -s /bin/sh -c 'monkeysphere authentication user,,,' || failure $?
- # FIXME: should we really be using a real shell? Convention
- # (/usr/ports/UIDs) seems to indicate /nonexistent is
- # preferred
- else
- echo "Please create it, and try again."
- exit 1
- fi
- fi
- # FIXME: we should create $VARLIB and chown the relevant subdirs
- # (see debian/monkeysphere.postinst)
-
- ;;
+ USER=monkeysphere
+ GROUP=${USER}
+ UID=641
+ GID=${UID}
+ SHELL=/usr/local/bin/bash
+
+ if pw group show "${GROUP}" >/dev/null 2>&1; then
+ echo "You already have a group \"${GROUP}\", so I will use it."
+ else
+ if pw groupadd ${GROUP} -g ${GID}; then
+ echo "Added group \"${GROUP}\"."
+ else
+ echo "Adding group \"${GROUP}\" failed..."
+ exit 1
+ fi
+ fi
+
+ if pw user show "${USER}" >/dev/null 2>&1; then
+ oldshell=`pw user show "${USER}" 2>/dev/null | cut -f10 -d:`
+ if [ x"$oldshell" != x"$SHELL" ]; then
+ echo "You already have a \"${USER}\" user, but its shell is '$oldshell'."
+ echo "This package requires that \"${USER}\"'s shell be '$SHELL'."
+ echo "You should fix this by hand and then re-install the package."
+ echo " hint: pw usermod '$USER' -s '$SHELL'"
+ exit 1
+ fi
+ echo "You already have a user \"${USER}\" with the proper shell, so I will use it."
+ else
+ if pw useradd ${USER} -u ${UID} -g ${GROUP} -h - \
+ -d "$VARLIB" -s /usr/local/bin/bash -c "monkeysphere authentication user,,,"
+ then
+ echo "Added user \"${USER}\"."
+ else
+ echo "Adding user \"${USER}\" failed..."
+ exit 1
+ fi
+ fi
+
+ ## set up the cache directories, and link them to the config files:
+
+ install -d -o root -g monkeysphere -m 750 "$VARLIB"/gnupg-host
+ ln -sf "$ETCDIR"/gnupg-host.conf "$VARLIB"/gnupg-host/gpg.conf
+
+ install -d -o monkeysphere -g monkeysphere -m 700 "$VARLIB"/gnupg-authentication
+ ln -sf "$ETCDIR"/gnupg-authentication.conf "$VARLIB"/gnupg-authentication/gpg.conf
+
+ chown monkeysphere:monkeysphere "$VARLIB"/gnupg-authentication/gpg.conf
+
+ monkeysphere-server diagnostics
+ ;;
esac