summaryrefslogtreecommitdiff
path: root/debian/sane-utils.postinst
blob: cf97dbed11fe97b95f52e9532f3d5aa241e07e46 (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
85
86
87
88
#!/bin/sh
set -e
. /usr/share/debconf/confmodule

SANED_DEFAULT=/etc/default/saned

saned_eh () {
    echo "saned couldn't start; check your inetd configuration and README.Debian"
}

#
# POSIX-compliant shell function
# to check for the existence of a command
# Return 0 if found
#
pathfind() {
    OLDIFS="$IFS"
    IFS=:
    for p in $PATH; do
        if [ -x "$p/$*" ]; then
            IFS="$OLDIFS"
            return 0
        fi
    done
    IFS="$OLDIFS"
    return 1
}



if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then
    db_get sane-utils/saned_run
    RUN_SANED="$RET"

    db_get sane-utils/saned_scanner_group
    SANED_IN_SCANNER="$RET"

    # Add saned service, disabled by default
    pathfind update-inetd
    if [ $? = 0 ]; then
	update-inetd --add "#<off># sane-port\tstream\ttcp\tnowait\tsaned:saned\t/usr/sbin/saned saned"
    fi

    # Stop debconf; output to stdout after this point. update-inetd needs debconf.
    db_stop

    # Create saned user/group if they do not exist
    if ! getent passwd | grep -q "^saned:"; then
	echo "Adding saned group and user..."
	adduser --home /var/lib/saned  --quiet --system --no-create-home --group saned || true
    fi

    # Move home from /home/saned to /var/lib/saned (since 1.0.24-6)
    if getent passwd | grep "^saned:" | grep -q "/home/saned"; then
	echo "Test for running scanbd"
	if ps -Af | grep "saned" | grep -q "scanbd"; then
	    echo "Stop scanbd"
	    invoke-rc.d --quiet scanbd stop
	    echo "Move homedir from /home/saned to /var/lib/saned"
	    usermod -d /var/lib/saned saned
	    echo "Start scanbd"
	    invoke-rc.d --quiet scanbd start
	else
	    echo "Move homedir from /home/saned to /var/lib/saned"
	    usermod -d /var/lib/saned saned
	fi
    fi
    if [ "$SANED_IN_SCANNER" = "true" ]; then
	adduser --quiet saned scanner || true
    else
	if id saned | grep -q "groups=.*\(scanner\)"; then
	    deluser --quiet saned scanner
	fi
    fi

    if [ -e $SANED_DEFAULT ]; then
	if [ "$RUN_SANED" = "true" ]; then
	    RUN_SANED=yes
	else
	    RUN_SANED=no
	fi

	sed -e "s/^ *RUN=.*/RUN=$RUN_SANED/" < $SANED_DEFAULT > $SANED_DEFAULT.tmp
	mv -f $SANED_DEFAULT.tmp $SANED_DEFAULT
    fi
fi

#DEBHELPER#