summaryrefslogtreecommitdiff
path: root/devel/monotone-server
diff options
context:
space:
mode:
authorjmmv <jmmv@pkgsrc.org>2010-03-12 09:27:17 +0000
committerjmmv <jmmv@pkgsrc.org>2010-03-12 09:27:17 +0000
commit2db4158d68b4aa3965e47626150871d310404595 (patch)
tree7830e8f162e97bf5afeaaeb38a25d17077ba1b71 /devel/monotone-server
parentcf4dbcc2181695c7bfd7875c69a45217e8cb2591 (diff)
downloadpkgsrc-2db4158d68b4aa3965e47626150871d310404595.tar.gz
Full rewrite of the monotone-server package:
- Delete the monotone-server-init script. - Modify the monotone rc.d(8) script to provide extra commands such as 'init', 'genkey' and 'read' to manipulate the server. These are not interactive, but allow the same level of customization as the previous script. Inspired by how the monotone init.d script from Fedora works. - Delete the need of an rc.conf script in the pkg_sysconfdir of this package. The settings previously stored there are now automatically discovered. - Fully automated creation of a server key: no more need to create a passphrase by hand, memorize it, and stick it on a configuration file to never look at it again. - The log file is now placed where it belongs: in varbase/log. - Addition of a monotone-server(7) manpage explaining the whole setup process and pointers to the server files. Note: upgrading from a previous version of the package will require manual intervention if the rc.d script in /etc/rc.d is replaced. However, I really doubt anyone is using this package so I didn't want to go through the trouble of implementing a migration procedure. I've added a note to the MESSAGE, though, asking users to contact me if required.
Diffstat (limited to 'devel/monotone-server')
-rw-r--r--devel/monotone-server/DESCR8
-rw-r--r--devel/monotone-server/MESSAGE11
-rw-r--r--devel/monotone-server/Makefile64
-rw-r--r--devel/monotone-server/PLIST6
-rw-r--r--devel/monotone-server/distinfo5
-rw-r--r--devel/monotone-server/files/hooks.conf12
-rw-r--r--devel/monotone-server/files/monotone-server-init.sh127
-rw-r--r--devel/monotone-server/files/monotone-server.7174
-rw-r--r--devel/monotone-server/files/monotone.sh233
9 files changed, 436 insertions, 204 deletions
diff --git a/devel/monotone-server/DESCR b/devel/monotone-server/DESCR
index 92c80dcc5af..072bda77ee1 100644
--- a/devel/monotone-server/DESCR
+++ b/devel/monotone-server/DESCR
@@ -7,7 +7,7 @@ and client-side RSA certificates. It has good internationalization
support, has no external dependencies, runs on NetBSD, Linux, Solaris,
OSX and Windows (among others), and is licensed under the GNU GPL.
-This package provides all the necessary stuff to easily configure a
-dedicated Monotone server. Of special interest are the included rc.d
-script and the monotone-server-init script, which will greatly simplify
-the whole process.
+This package provides the necessary stuff to configure a dedicated Monotone
+server. The package will create a dedicated user/group account to run the
+server, will install a set of configuration files and will guide you, through
+an rc.d script, to initialize the database and populate it.
diff --git a/devel/monotone-server/MESSAGE b/devel/monotone-server/MESSAGE
index a7b5ce08bf2..6150df4c98b 100644
--- a/devel/monotone-server/MESSAGE
+++ b/devel/monotone-server/MESSAGE
@@ -1,7 +1,12 @@
===========================================================================
-$NetBSD: MESSAGE,v 1.1.1.1 2005/01/12 12:52:50 jmmv Exp $
+$NetBSD: MESSAGE,v 1.2 2010/03/12 09:27:17 jmmv Exp $
-You should now run 'monotone-server-init' to finish installation _before_
-enabling the server. Then, follow the on-screen instructions.
+Please read monotone-server(7) for instructions on how to set up a new
+monotone server with the support files installed by this package.
+
+WARNING: If you are updating from a previous version of this package and
+used the (now non-existent) monotone-server-init script to initialize the
+server, you will need to manually aid the upgrade. Contact the package
+maintainer for assistance.
===========================================================================
diff --git a/devel/monotone-server/Makefile b/devel/monotone-server/Makefile
index f1148812162..8aad86d4daa 100644
--- a/devel/monotone-server/Makefile
+++ b/devel/monotone-server/Makefile
@@ -1,32 +1,33 @@
-# $NetBSD: Makefile,v 1.45 2010/03/07 22:29:20 jmmv Exp $
+# $NetBSD: Makefile,v 1.46 2010/03/12 09:27:17 jmmv Exp $
#
-DISTNAME= monotone-server-0.46
-PKGREVISION= 1
+DISTNAME= monotone-0.46
+PKGNAME= ${DISTNAME:S/-/-server-/}
+PKGREVISION= 2
CATEGORIES= devel scm
-MASTER_SITES= # empty
-DISTFILES= # empty
+MASTER_SITES= http://monotone.ca/downloads/0.46/
MAINTAINER= jmmv@NetBSD.org
HOMEPAGE= http://monotone.ca/
COMMENT= Simplifies the configuration of a dedicated Monotone server
+DEPENDS+= digest>=20080510:../../pkgtools/digest
DEPENDS+= monotone>=0.46:../../devel/monotone
PKG_DESTDIR_SUPPORT= user-destdir
+LICENSE= 2-clause-bsd
NO_BUILD= yes
-WRKSRC= ${WRKDIR}
RCD_SCRIPTS= monotone
PKG_SYSCONFSUBDIR= monotone-server
-OWN_DIRS_PERMS= ${PKG_SYSCONFDIR}/keys \
+OWN_DIRS_PERMS= ${PKG_SYSCONFDIR}/keys \
${MONOTONE_USER} ${MONOTONE_GROUP} 700
EXAMPLEDIR= ${PREFIX}/share/examples/monotone-server
-CONF_FILES_PERMS= ${EXAMPLEDIR}/hooks.conf \
- ${PKG_SYSCONFDIR}/hooks.conf \
+CONF_FILES_PERMS= ${EXAMPLEDIR}/monotonerc \
+ ${PKG_SYSCONFDIR}/monotonerc \
${MONOTONE_USER} ${MONOTONE_GROUP} 600
CONF_FILES_PERMS+= ${EXAMPLEDIR}/read-permissions \
${PKG_SYSCONFDIR}/read-permissions \
@@ -34,6 +35,8 @@ CONF_FILES_PERMS+= ${EXAMPLEDIR}/read-permissions \
CONF_FILES_PERMS+= ${EXAMPLEDIR}/write-permissions \
${PKG_SYSCONFDIR}/write-permissions \
${MONOTONE_USER} ${MONOTONE_GROUP} 600
+CONF_FILES_PERMS+= /dev/null ${MONOTONE_LOGFILE} \
+ ${MONOTONE_USER} ${MONOTONE_GROUP} 600
PKG_GROUPS= ${MONOTONE_GROUP}
PKG_USERS= ${MONOTONE_USER}:${MONOTONE_GROUP}
@@ -43,40 +46,49 @@ PKG_USERS_VARS+= MONOTONE_USER
.include "../../mk/bsd.prefs.mk"
+BUILD_DEFS+= RCD_SCRIPTS_DIR VARBASE
+
+MONOTONE_HOME= ${VARBASE}/monotone
+MONOTONE_LOGFILE= ${VARBASE}/log/monotone.log
+
PKG_GECOS.${MONOTONE_USER}= Monotone dedicated server
-PKG_HOME.${MONOTONE_USER}= ${VARBASE}/monotone
+PKG_HOME.${MONOTONE_USER}= ${MONOTONE_HOME}
PKG_SHELL.${MONOTONE_USER}= ${SH}
-SUBST_CLASSES+= vars
+SUBST_CLASSES+= vars
SUBST_STAGE.vars= do-configure
SUBST_MESSAGE.vars= Configuring sources.
-SUBST_FILES.vars= *
-SUBST_SED.vars= -e 's|@MONOTONE@|${PREFIX}/bin/mtn|g'
-SUBST_SED.vars+= -e 's|@MONOTONE_GROUP@|${MONOTONE_GROUP}|g'
+SUBST_FILES.vars= ${WRKDIR}/monotone-server.7
+SUBST_SED.vars+= -e 's|@MONOTONE_HOME@|${MONOTONE_HOME}|g'
+SUBST_SED.vars+= -e 's|@MONOTONE_LOGFILE@|${MONOTONE_LOGFILE}|g'
SUBST_SED.vars+= -e 's|@MONOTONE_USER@|${MONOTONE_USER}|g'
SUBST_SED.vars+= -e 's|@PKG_SYSCONFDIR@|${PKG_SYSCONFDIR}|g'
-SUBST_SED.vars+= -e 's|@SH@|${SH}|g'
-SUBST_SED.vars+= -e 's|@VARBASE@|${VARBASE}|g'
+SUBST_SED.vars+= -e 's|@PREFIX@|${PREFIX}|g'
+SUBST_SED.vars+= -e 's|@RCD_SCRIPTS_DIR@|${RCD_SCRIPTS_DIR}|g'
+FILES_SUBST+= DIGEST=${PREFIX:Q}/bin/digest
+FILES_SUBST+= MONOTONE=${PREFIX:Q}/bin/mtn
FILES_SUBST+= MONOTONE_GROUP=${MONOTONE_GROUP:Q}
+FILES_SUBST+= MONOTONE_LOGFILE=${MONOTONE_LOGFILE:Q}
FILES_SUBST+= MONOTONE_USER=${MONOTONE_USER:Q}
+FILES_SUBST+= PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q}
-INSTALLATION_DIRS= sbin
+INSTALLATION_DIRS= ${PKGMANDIR}/man7
-do-extract:
-.for f in hooks.conf monotone-server-init.sh read-permissions \
- write-permissions
- ${CP} ${FILESDIR}/${f} ${WRKSRC}
+post-extract:
+.for f in monotone-server.7 read-permissions write-permissions
+ ${CP} ${FILESDIR}/${f} ${WRKDIR}
.endfor
do-install:
- ${INSTALL_SCRIPT} ${WRKSRC}/monotone-server-init.sh \
- ${DESTDIR}${PREFIX}/sbin/monotone-server-init
${INSTALL_DATA_DIR} ${DESTDIR}${EXAMPLEDIR}
- ${INSTALL_DATA} ${WRKSRC}/hooks.conf ${DESTDIR}${EXAMPLEDIR}/hooks.conf
- ${INSTALL_DATA} ${WRKSRC}/read-permissions \
+ ${INSTALL_DATA} ${WRKDIR}/monotone-server.7 \
+ ${DESTDIR}${PREFIX}/${PKGMANDIR}/man7/monotone-server.7
+ ${INSTALL_DATA} ${WRKSRC}/contrib/get_passphrase_from_file.lua \
+ ${DESTDIR}${EXAMPLEDIR}/monotonerc
+ ${INSTALL_DATA} ${WRKDIR}/read-permissions \
${DESTDIR}${EXAMPLEDIR}/read-permissions
- ${INSTALL_DATA} ${WRKSRC}/write-permissions \
+ ${INSTALL_DATA} ${WRKDIR}/write-permissions \
${DESTDIR}${EXAMPLEDIR}/write-permissions
.include "../../mk/bsd.pkg.mk"
diff --git a/devel/monotone-server/PLIST b/devel/monotone-server/PLIST
index a74e7709b8e..6a1d0e7fddb 100644
--- a/devel/monotone-server/PLIST
+++ b/devel/monotone-server/PLIST
@@ -1,6 +1,6 @@
-@comment $NetBSD: PLIST,v 1.5 2009/06/14 17:48:59 joerg Exp $
-sbin/monotone-server-init
-share/examples/monotone-server/hooks.conf
+@comment $NetBSD: PLIST,v 1.6 2010/03/12 09:27:17 jmmv Exp $
+man/man7/monotone-server.7
+share/examples/monotone-server/monotonerc
share/examples/monotone-server/read-permissions
share/examples/monotone-server/write-permissions
share/examples/rc.d/monotone
diff --git a/devel/monotone-server/distinfo b/devel/monotone-server/distinfo
new file mode 100644
index 00000000000..7b59a382620
--- /dev/null
+++ b/devel/monotone-server/distinfo
@@ -0,0 +1,5 @@
+$NetBSD: distinfo,v 1.1 2010/03/12 09:27:17 jmmv Exp $
+
+SHA1 (monotone-0.46.tar.gz) = 2b498c30f91b741e45bc34f8cb5faf135e97976d
+RMD160 (monotone-0.46.tar.gz) = a8f09fc58d09f2144aef3d5f3a333a5cd4555c7b
+Size (monotone-0.46.tar.gz) = 4568806 bytes
diff --git a/devel/monotone-server/files/hooks.conf b/devel/monotone-server/files/hooks.conf
deleted file mode 100644
index 43c2e4b4869..00000000000
--- a/devel/monotone-server/files/hooks.conf
+++ /dev/null
@@ -1,12 +0,0 @@
--- $NetBSD: hooks.conf,v 1.5 2010/03/07 22:29:20 jmmv Exp $
---
--- This file belongs to the monotone-server package. This is the typical
--- ~/.monotonerc configuration file, but is system-wide.
---
-
-function get_passphrase(identity)
- if (identity.given_name == "PUT_KEYNAME_HERE") then
- return "PUT_PASSPHRASE_HERE"
- end
- return false
-end
diff --git a/devel/monotone-server/files/monotone-server-init.sh b/devel/monotone-server/files/monotone-server-init.sh
deleted file mode 100644
index 6ae6d23d239..00000000000
--- a/devel/monotone-server/files/monotone-server-init.sh
+++ /dev/null
@@ -1,127 +0,0 @@
-#!@SH@
-#
-# $NetBSD: monotone-server-init.sh,v 1.5 2010/03/07 22:09:36 jmmv Exp $
-#
-
-progname=$(basename $0)
-
-MONOTONE=@MONOTONE@
-MONOTONE_GROUP=@MONOTONE_GROUP@
-MONOTONE_USER=@MONOTONE_USER@
-PKG_SYSCONFDIR=@PKG_SYSCONFDIR@
-VARBASE=@VARBASE@
-
-if [ $(id -u) -ne 0 ]; then
- echo "${progname}: this program must be run as \`root'" 1>&2
- exit 1
-fi
-
-cat <<EOF
-The following user and group will be used to run the monotone server
-process under a restricted account:
-
- User name \`${MONOTONE_USER}', UID \``id -u monotone`'
- Group name \`${MONOTONE_GROUP}', GID \``id -g monotone`'
-
-If either the UID or the GID are inappropriate, please abort this
-script now, correct them and restart the utility so that all the
-files are created with the correct ownerships.
-
-Press RETURN to continue or CTRL-C to abort.
-EOF
-read key
-
-cat <<EOF
-The monotone package is currently configured to use the
-${VARBASE}/monotone directory to hold the public database.
-You may now change this default path to something else that is
-more suitable for your system, if you wish.
-
-EOF
-
-printf "Enter home directory [${VARBASE}/monotone]: "
-read home
-: ${home:=${VARBASE}/monotone}
-
-if [ ${home} != ${VARBASE}/monotone ]; then
-
- if ! usermod -d ${home} ${MONOTONE_USER}; then
- echo "cannot modify home directory of user " \
- "\`${MONOTONE_USER}'" 1>&2
- exit 1
- fi
-
- echo "monotone_home=${home}" >>${PKG_SYSCONFDIR}/rc.conf
-fi
-
-cat <<EOF
-
-In order to serve a collection, you must now create a public/private key
-pair to access the database. This has to be _different_ to the key pair
-you use for development; it will only be used by the server process.
-
-The key name should be in the form of an email address. Typicall, it will
-be something like monotone@your_host_name.
-
-I have determined that monotone@$(hostname) is probably a good choice.
-
-EOF
-printf "Enter key name [monotone@$(hostname)]: "
-read keyname
-: ${keyname:=monotone@$(hostname)}
-
-if [ ! -d ${home} ]; then
- echo "Initializing new home directory: \`${home}'"
- mkdir -p ${home}
- chmod 755 ${home}
- chown ${MONOTONE_USER}:${MONOTONE_GROUP} ${home}
-fi
-
-cd ${home}
-
-echo "Initializing database: \`${home}/monotone.db'"
-su - ${MONOTONE_USER} -c "${MONOTONE} --confdir=${PKG_SYSCONFDIR} \
- --db=monotone.db --keydir=${PKG_SYSCONFDIR}/keys db init"
-
-cat <<EOF
-
-Monotone will now ask you for a passphrase to protect the key pair we are
-creating. Choose a hard one and write it down temporarily; you will need
-to put it in one of the configuration files in a later step. After that,
-you can forget about it (assuming you have a safe copy).
-
-EOF
-
-su - ${MONOTONE_USER} -c "${MONOTONE} --confdir=${PKG_SYSCONFDIR} \
- --db=monotone.db --keydir=${PKG_SYSCONFDIR}/keys \
- genkey ${keyname}"
-
-chown ${MONOTONE_USER}:${MONOTONE_GROUP} monotone.db
-chmod 600 monotone.db
-
-cat <<EOF
-
-Initialization process finished!
-
-You should now backup the following file and store it in a safe place.
-It contains the key pair that authenticates your server:
-
- ${PKG_SYSCONFDIR}/keys/${keyname}
-
-Then, edit the following files to finish the configuration of your new
-server:
-
- ${PKG_SYSCONFDIR}/hooks.conf
- ${PKG_SYSCONFDIR}/read-permissions
- ${PKG_SYSCONFDIR}/write-permissions
-
-At last, do not forget to register the public keys for the users with
-write access by using a command similar to:
-
- ${MONOTONE##*/} --db=${home}/monotone.db read < file-with-public-keys
-
-Once finished, use the installed rc.d script (monotone) to start the
-dedicated server process.
-EOF
-
-exit 0
diff --git a/devel/monotone-server/files/monotone-server.7 b/devel/monotone-server/files/monotone-server.7
new file mode 100644
index 00000000000..7850ea91398
--- /dev/null
+++ b/devel/monotone-server/files/monotone-server.7
@@ -0,0 +1,174 @@
+.\" $NetBSD4
+.\"
+.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd March 12, 2010
+.Dt MONOTONE-SERVER 7
+.Os
+.Sh NAME
+.Nm monotone-server
+.Nd guide to set up a monotone server
+.Sh DESCRIPTION
+The
+.Nm
+package provides a
+.Xr rc.d 8
+script, called
+.Sq monotone ,
+that aids in the configuration of a monotone server.
+This script follows the normal conventions of other
+.Xr rc.d 8
+scripts, but adds a few extra commands to ease the configuration process
+from scratch.
+.Pp
+.Ss Typical configuration procedure
+In order to configure a monotone server using the
+.Nm
+package, follow these instructions:
+.Bl -enum
+.It
+Check that the home directory of the
+.Sq @MONOTONE_USER@
+user points to the directory you want to use to keep your database in.
+If it is not what you want, change it before initializing the server.
+.It
+Copy
+.Pa @PREFIX@/share/examples/rc.d/monotone
+to
+.Pa @RCD_SCRIPTS_DIR@/monotone
+if the latter does not exist.
+.It
+Set
+.Sq monotone=YES
+in
+.Xr rc.conf 5 .
+.It
+Use the
+.Sq init
+subcommand to generate an empty monotone database for the server.
+.It
+Use the
+.Sq genkey
+subcommand to generate a new key pair for the monotone server.
+.It
+Edit the
+.Pa @PKG_SYSCONFDIR@/read-permissions
+and the
+.Pa @PKG_SYSCONFDIR@/write-permissions
+to adjust the users that are allowed to read from and to write to the server.
+.It
+Use the
+.Sq read
+subcommand to import the public keys needed to fulfill the permissions
+configured in the previous step.
+.It
+Learn how to back up the server data as described in
+.Sx Backing up your server .
+Back the new files up now.
+.It
+Start the server as usual (with the
+.Sq start
+subcommand)!
+.El
+.Ss Backing up your server
+In order to back up a monotone server configured by this package, you need to
+copy the server database, the key pair for the server and the passphrase to
+identify such key pair, in a safe place.
+The exact location of these files is shown below in the
+.Sx FILES
+section.
+.Ss Available subcommands
+The list below describes all the non-standard subcommands provided by the
+.Nm monotone
+.Xr rc.d 8
+script.
+For the sake of completeness, some standard commands are also included:
+.Bl -tag -width genkeyXXkeynameX
+.It Ar genkey Op Ar keyname
+Generates a new key pair to authenticate the server.
+A random password is automatically generated for this key and the server is
+configured to use it.
+.Pp
+If
+.Ar keyname
+is not provided, the key name defaults to
+.Sq monotone@your-domain .
+.It Ar init
+Initializes the server by creating an empty monotone database.
+This database is created in the home directory of the
+.Sq @MONOTONE_USER@
+user, and this directory is previously created if it does not exist.
+.It Ar migrate
+If the database schema has changed during an update of monotone, migrates
+the database to the new version.
+.It Ar read Op Ar file ...
+Imports public keys into the server database.
+Keys can be provided on the standard input or, if they reside in files,
+as arguments.
+.It Ar start
+Starts the server.
+.It Ar stop
+Stops the server.
+.El
+.Sh FILES
+.Bl -tag -width XXXXX -compact
+.It Pa @RCD_SCRIPTS_DIR@/monotone
+The
+.Xr rc.d 8
+startup script.
+.It Pa @MONOTONE_HOME@/
+Default location of the server database, unless the home directory of the
+.Sq @MONOTONE_USER@
+user has been changed.
+.It Pa @PKG_SYSCONFDIR@/keys/
+Location of server private keys.
+.It Pa @PKG_SYSCONFDIR@/monotonerc
+Configuration file (lua hooks) for the monotone server.
+.It Pa @PKG_SYSCONFDIR@/passphrases
+List of passphrases of the private keys.
+.It Pa @PKG_SYSCONFDIR@/read-permissions
+Configuration of the users allowed to read specific branches.
+.It Pa @PKG_SYSCONFDIR@/write-permissions
+Configuration of the users allowed to write to the database.
+.It Pa @MONOTONE_LOGFILE@
+Log file for the server.
+.El
+.Sh SEE ALSO
+.Xr rc.conf 5 ,
+.Xr rc.d 8
+.Sh HISTORY
+The monotone-server package first appeared in pkgsrc-2005Q1 and was composed of
+a simple startup script and a separate interactive script for initial
+configuration of the server.
+.Pp
+The monotone-server package was completely rewritten in pkgsrc-2010Q1 to provide
+a single startup script that bundles the traditional behavior of an
+.Xr rc.d 8
+script alongside the configuration and management of the server.
+These changes were inspired by the monotone-server package from Fedora.
+.Sh AUTHORS
+The monotone-server package and its accompanying scripts were written by
+.An Julio Merino
+.Aq jmmv@NetBSD.org .
diff --git a/devel/monotone-server/files/monotone.sh b/devel/monotone-server/files/monotone.sh
index 94fb46025c7..5e727dc493c 100644
--- a/devel/monotone-server/files/monotone.sh
+++ b/devel/monotone-server/files/monotone.sh
@@ -1,45 +1,220 @@
#!@RCD_SCRIPTS_SHELL@
#
-# $NetBSD: monotone.sh,v 1.5 2007/06/24 20:55:30 jmmv Exp $
+# $NetBSD: monotone.sh,v 1.6 2010/03/12 09:27:18 jmmv Exp $
+#
+# Copyright (c) 2010 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
#
# PROVIDE: monotone
# REQUIRE: DAEMON
+#
+
+#
+# See the monotone-server(7) manual page for details on how to use and configure
+# this script.
+#
. /etc/rc.subr
-if [ -f "@PKG_SYSCONFDIR@/rc.conf" ]; then
- . @PKG_SYSCONFDIR@/rc.conf
-fi
+progname=${0##*/}
+saved_args="${@}"
+
+# Settings from package build. Cannot be modified after installation.
+digest_bin="@DIGEST@"
+monotone_bin="@MONOTONE@"
+monotone_group="@MONOTONE_GROUP@"
+monotone_logfile="@MONOTONE_LOGFILE@"
+monotone_user="@MONOTONE_USER@"
+pkg_sysconfdir="@PKG_SYSCONFDIR@"
+
+# Settings from system configuration.
+monotone_default_home=$(grep "^${monotone_user}:" /etc/passwd | cut -d : -f 6)
+monotone_default_keyname="monotone@$(hostname)"
+: ${monotone_home:=${monotone_default_home}}
-: ${monotone_group=@MONOTONE_GROUP@}
-: ${monotone_home=@VARBASE@/monotone}
-: ${monotone_user=@MONOTONE_USER@}
+# Settings derived from the above.
+monotone_db="${monotone_home}/monotone.db"
+monotone_keysdir="${pkg_sysconfdir}/keys"
+monotone_passphrases="${pkg_sysconfdir}/passphrases"
+monotone_flags="--db='${monotone_db}' \
+ --norc \
+ --confdir='${pkg_sysconfdir}' \
+ --keydir='${monotone_keysdir}' \
+ --rcfile='${pkg_sysconfdir}/monotonerc'"
+# rc.d(8) script boilerplate.
name="monotone"
-rcvar=${name}
-command="@PREFIX@/bin/mtn"
-command_args="--norc \
- --confdir=@PKG_SYSCONFDIR@ \
- --db=${monotone_home}/monotone.db \
- --keydir=@PKG_SYSCONFDIR@/keys \
- --rcfile=@PKG_SYSCONFDIR@/hooks.conf \
- serve \
- >>${monotone_home}/monotone.log 2>&1 &"
-required_dirs="@PKG_SYSCONFDIR@/keys"
-required_files="@PKG_SYSCONFDIR@/hooks.conf \
- @PKG_SYSCONFDIR@/read-permissions \
- @PKG_SYSCONFDIR@/write-permissions \
- ${monotone_home}/monotone.db"
+rcvar="${name}"
+rcvar_manpage="monotone-server(7)"
+command="${monotone_bin}"
+command_args="${monotone_flags} serve >>${monotone_logfile} 2>&1 &"
+monotone_chdir="${monotone_home}"
+required_files="${pkg_sysconfdir}/monotonerc \
+ ${pkg_sysconfdir}/read-permissions \
+ ${pkg_sysconfdir}/write-permissions"
start_precmd="monotone_start_precmd"
+extra_commands="init genkey migrate read"
+genkey_cmd="monotone_genkey"
+init_cmd="monotone_init"
+read_cmd="monotone_read"
-monotone_start_precmd() {
- if test ! -f ${monotone_home}/monotone.log; then
- touch ${monotone_home}/monotone.log
- chown ${monotone_user}:${monotone_group} \
- ${monotone_home}/monotone.log
+info_no_log() {
+ echo "${progname}: ${*}"
+}
+
+info() {
+ log "${@}"
+ info_no_log "${@}"
+}
+
+log() {
+ require_logfile
+ echo "${@}" >>"${monotone_logfile}"
+}
+
+run_monotone() {
+ log su - "${monotone_user}" -c "'${command}' ${monotone_flags} ${*}"
+ su - "${monotone_user}" -c "'${command}' ${monotone_flags} ${*}" || \
+ err 1 "Execution of monotone '${*}' failed"
+}
+
+require_logfile() {
+ test -f "${monotone_logfile}" || \
+ err 1 "'${monotone_logfile}' is missing; use the 'init'" \
+ "subcommand to initialize the server"
+}
+
+require_server_initialized() {
+ test -f "${monotone_db}" || \
+ err 1 "'${monotone_db}' is missing; use the 'init' subcommand" \
+ "to initialize the server"
+}
+
+require_server_key() {
+ test -f "${monotone_passphrases}" || \
+ err 1 "'${monotone_passphrases}' is missing; use the" \
+ "'genkey' subcommand to generate a server key"
+}
+
+monotone_genkey() {
+ set -- ${saved_args}; shift
+ local keyname="${1:-${monotone_default_keyname}}"
+
+ test -f "${monotone_passphrases}" && \
+ err 1 "${monotone_passphrases} already exists"
+
+ if [ ! -d "${monotone_keysdir}" ]; then
+ info "Creating keys directory '${monotone_keysdir}'"
+ mkdir "${monotone_keysdir}" || \
+ err 1 "failed to create '${monotone_keysdir}'"
+ else
+ info "Resetting permissions of '${monotone_keysdir}'"
fi
- echo "=> Session started at `date`" >>${monotone_home}/monotone.log
+ chmod 700 "${monotone_keysdir}"
+ chown "${monotone_user}:${monotone_group}" "${monotone_keysdir}"
+
+ require_server_initialized
+
+ info "Creating key '${keyname}'"
+
+ keypass=$(dd if=/dev/urandom bs=1024 count=100 | ${digest_bin} sha512)
+
+ touch "${monotone_passphrases}"
+ chmod 600 "${monotone_passphrases}"
+ chown "${monotone_user}:${monotone_group}" "${monotone_passphrases}"
+ echo "${keyname} \"${keypass}\"" >>"${monotone_passphrases}"
+
+ run_monotone genkey "${keyname}" <<EOF
+${keypass}
+${keypass}
+EOF
+}
+
+monotone_init() {
+ test -f "${monotone_db}" && \
+ err 1 "database '${monotone_db}' already initialized"
+
+ if [ ! -f "${monotone_logfile}" ]; then
+ info_no_log "Creating log file '${monotone_logfile}'"
+ touch "${monotone_logfile}" || \
+ err 1 "failed to create '${monotone_logfile}'"
+ else
+ info_no_log "Resetting permissions of '${monotone_logfile}'"
+ fi
+ chmod 600 "${monotone_logfile}"
+ chown "${monotone_user}:${monotone_group}" "${monotone_logfile}"
+
+ if [ ! -d "${monotone_home}" ]; then
+ info "Creating home directory '${monotone_home}'"
+ mkdir "${monotone_home}" || \
+ err 1 "failed to create '${monotone_home}'"
+ else
+ info "Resetting permissions of '${monotone_home}'"
+ fi
+ chmod 700 "${monotone_home}"
+ chown "${monotone_user}:${monotone_group}" "${monotone_home}"
+
+ info "Initializing database '${monotone_db}'"
+ run_monotone db init
+ chown "${monotone_user}:${monotone_group}" "${monotone_db}"
+ chmod 600 "${monotone_db}"
+
+ info "All done!"
+ info "Use the 'genkey' subcommand to create a new server key"
+ info "Use the 'read' subcommand to import existing user public keys"
+}
+
+monotone_migrate() {
+ require_server_initialized
+
+ run_monotone db migrate
+}
+
+monotone_read() {
+ set -- ${saved_args}; shift
+
+ require_server_initialized
+
+ if [ ${#} -gt 0 ]; then
+ while [ ${#} -gt 0 ]; do
+ info "Importing keys from '${1}' into '${monotone_db}'"
+ run_monotone read <"${1}"
+ shift
+ done
+ else
+ info "Importing keys from stdin into '${monotone_db}'"
+ run_monotone read
+ fi
+}
+
+monotone_start_precmd() {
+ require_server_initialized
+ require_server_key
+ log "Server started on $(date)"
+ log "${command}" "${command_args}"
}
-load_rc_config $name
-run_rc_command "$1"
+load_rc_config "${name}"
+run_rc_command "${1}"