blob: d4e81ac794041991c428996c9c7f661738f278eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/sbin/runscript
# Copyright 2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /var/cvsroot/gentoo-x86/dev-util/monotone/files/monotone-0.36.initd,v 1.1 2007/10/07 12:34:03 opfer Exp $
opts="import"
depend() {
need net
}
# Substitute common default values
MTN_KEY=${MTN_KEY:-monotone@`hostname --fqdn`}
MTN_CONFDIR=${MTN_CONFDIR:-/etc/monotone}
MTN_COMMON="--norc --confdir=${MTN_CONFDIR} \
--keydir=${MTN_KEYDIR:-/var/lib/monotone/keys} \
--db=${MTN_DB:-/var/lib/monotone/default.mtn} \
--rcfile=${MTN_CONFDIR}/hooks.lua --log=/var/log/monotone/monotone.log"
#--dump=$ERRORLOG
MTN_PIDFILE="/var/run/monotone/monotone.pid"
MTN_HOME=$(awk -F: -vuid=$MTN_USER -vuser=$MTN_USER '$3 == uid || $1 == user { print $6 }' </etc/passwd)
dbexists() {
# Create the database if it doesn't exist
if [ ! -e ${MTN_DB:-/var/lib/monotone/default.mtn} ]; then
ebegin "Creating monotone database"
start-stop-daemon --start \
--chuid ${MTN_USER:-monotone}:${MTN_GROUP:-monotone} \
--exec /usr/bin/mtn -- ${MTN_COMMON} db init
eend $?
fi
if [ ! -e ${MTN_KEYDIR:-/var/lib/monotone/keys}/${MTN_KEY} ]; then
ebegin "Creating monotone server keypair"
export MTN_PWD=${RANDOM}
yes "${MTN_PWD}" | \
start-stop-daemon --start \
--chuid ${MTN_USER:-monotone}:${MTN_GROUP:-monotone} \
--exec /usr/bin/mtn -- ${MTN_COMMON} genkey ${MTN_KEY}
eend $?
# Update the password lua hook
cat > ${MTN_CONFDIR}/passphrase.lua <<EOF
-- This file is automaticaly generated by the init scripts.
-- If you want to add custom hooks, edit ${MTN_CONFDIR}/hooks.lua
-- If you want to change the settings, please edit /etc/conf.d/monotone
function get_passphrase(identity)
if (identity == "${MTN_KEY}") then
return "${MTN_PWD}"
end
return false
end
EOF
fi
}
start() {
cd ${MTN_HOME}
dbexists
ebegin "Starting monotone server"
start-stop-daemon --start --background \
--chuid ${MTN_USER:-monotone}:${MTN_GROUP:-monotone} \
--exec /usr/bin/mtn -- ${MTN_COMMON} --pid-file=${MTN_PIDFILE} \
--key=${MTN_KEY} --bind=${MTN_ADDRESS:-0.0.0.0} serve
eend $?
}
stop() {
ebegin "Stopping monotone server"
start-stop-daemon --stop --quiet --pidfile ${MTN_PIDFILE}
eend $?
}
import() {
cd ${MTN_HOME}
dbexists
# Read packets into the database
einfo "Importing packets to monotone database"
cat | /usr/bin/mtn ${MTN_COMMON} read
eend $?
}
|