File: preinst

package info (click to toggle)
vtun 3.0.4-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,520 kB
  • sloc: ansic: 4,180; sh: 2,814; yacc: 536; lex: 195; makefile: 139
file content (111 lines) | stat: -rw-r--r-- 2,616 bytes parent folder | download | duplicates (7)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
# vim:ts=4:sw=4:et:ai:sts=4
# preinst script for vtun

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

update_conf() {
    cat <<END
# Defaults for vtun initscript
# sourced by /etc/init.d/vtun
# Created automatically from /etc/vtund-start.conf

#
# This is a POSIX shell fragment
#
# Should the standalone server be started?
END
    server_args="`sed -ne 's/^\s*--server--\s*/-P /p' \
        < /etc/vtund-start.conf`"
    if [ -n "$server_args" ]; then
        echo "RUN_SERVER=yes"
        echo "SERVER_ARGS=\"$server_args\""
    else
        echo "RUN_SERVER=no"
        echo "SERVER_ARGS=\"\""
    fi
    n=0
    cat /etc/vtund-start.conf | grep -v '^\s*#\|^\s*$' | sed 's/^\s*//' | \
    while read session host args; do
        if [ "$session" = "--server--" ]; then
            continue
        fi
        echo ""
        echo "CLIENT${n}_NAME=\"$session\""
        echo "CLIENT${n}_HOST=\"$host\""
        echo "CLIENT${n}_ARGS=\"$args\""
        n=$(($n+1))
    done
}
create_conf() {
    cat <<END
# Defaults for vtun initscript
# sourced by /etc/init.d/vtun
# Created by the maintainer scripts

#
# This is a POSIX shell fragment
#
# Should the standalone server be started?
# RUN_SERVER=no
# SERVER_ARGS="-P 5000"

# Client sessions to start. Up to ten instances can be configured.
#
# Session name
# CLIENT0_NAME=viper
#
# Destination host
# CLIENT0_HOST=vtun-server.somewhere.com.au
#
# Optional parameters
# CLIENT0_ARGS=
#
# CLIENT1_NAME=
# CLIENT1_HOST=
# CLIENT1_ARGS=
END
}

case "$1" in
    install|upgrade)
        if [ ! -f /etc/default/vtun ]; then
            if [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.6-5 && \
                [ -f /etc/vtund-start.conf ]; then
                # We need to upgrade the old configuration file
                update_conf > /etc/default/vtun
            else
                # We need to provide a default configuration
                create_conf > /etc/default/vtun
            fi
        fi
    ;;

    abort-upgrade)
    ;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

if [ "$1" = upgrade ]; then
    echo "vtun must be restarted manually for changes to take effect."
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#

exit 0