This file is indexed.

postinst is in varnish 4.1.1-1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh

# Postinst script for varnish.
# Stig Sandbeck Mathisen <ssm@debian.org>

set -e
set -u

# Settings
daemon_group="varnish"
daemon_user="varnish"
worker_user="vcache"
log_user="varnishlog"
daemon_dir=/var/lib/varnish/$(uname -n)
log_dir="/var/log/varnish"
secret_file=/etc/varnish/secret


ensure_users() {

    # Daemon user and group
    if ! getent passwd $daemon_user 2>&1 >/dev/null; then
        adduser --quiet --system --no-create-home --home /nonexistent --group $daemon_user
    fi

    # Extra users in daemon group
    for user in $worker_user $log_user; do
        if ! getent passwd $user 2>&1 >/dev/null; then
            adduser --quiet --system --no-create-home --home /nonexistent --ingroup $daemon_group $user
        fi
    done

}

varnish_create_storagedir() {
    if ! [ -d "$daemon_dir" ]; then
        install -o $daemon_user -g $daemon_user -d $daemon_dir
    fi
}

varnish_setup_logdir() {
    if ! dpkg-statoverride --list $log_dir >/dev/null; then
        dpkg-statoverride --update --add $log_user $daemon_group 0750 $log_dir
    fi
}

varnish_create_secret() {
    if ! [ -f "${secret_file}" ]; then
        if [ -f /proc/sys/kernel/random/uuid ]; then
            install -m 0600 /proc/sys/kernel/random/uuid "${secret_file}"
        else
            install -m 0600 /dev/null "${secret_file}"
            dd if=/dev/urandom count=1 bs=128 2>/dev/null \
                | tr -dc "A-Za-z0-9" > "${secret_file}"
        fi
    fi
}

# varnish version 2.1.3-1 and older ran the log demons as root, we
# need to change the owner of the old logs for upgrading clients
upgrade_change_log_permissions() {
    chown -Rhf ${log_user}: ${log_dir}
}

# In varnish 4.1, the varnish shared memory log is readable by the "varnish"
# group, instead of by everyone.  We need to update the "varnishlog" user to
# reflect this, as well as the permissions on /var/log/varnish
change_group_for_varnishlog_user() {
    usermod -g $daemon_group $log_user
    dpkg-statoverride --remove $log_dir
    dpkg-statoverride --update --add $log_user $daemon_group 0750 $log_dir
}

case ${1:-} in
    configure)

	ensure_users

        varnish_create_storagedir
        varnish_setup_logdir

        varnish_create_secret

        if dpkg --compare-versions "2.1.3-2" "gt-nl" "${2:-}" ; then
            upgrade_change_log_permissions
        fi

        if dpkg --compare-versions "4.1.0-2~" "gt-nl" "${2:-}"; then
            change_group_for_varnishlog_user
        fi
        ;;
esac

# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask varnish.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled varnish.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable varnish.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state varnish.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask varnishlog.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled varnishlog.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable varnishlog.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state varnishlog.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask varnishncsa.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled varnishncsa.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable varnishncsa.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state varnishncsa.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/varnish" ]; then
		update-rc.d varnish defaults >/dev/null
	fi
	if [ -x "/etc/init.d/varnish" ] || [ -e "/etc/init/varnish.conf" ]; then
		invoke-rc.d varnish start || exit $?
	fi
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/varnishlog" ]; then
		update-rc.d varnishlog defaults >/dev/null
	fi
	if [ -x "/etc/init.d/varnishlog" ] || [ -e "/etc/init/varnishlog.conf" ]; then
		invoke-rc.d varnishlog start || exit $?
	fi
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/varnishncsa" ]; then
		update-rc.d varnishncsa defaults >/dev/null
	fi
	if [ -x "/etc/init.d/varnishncsa" ] || [ -e "/etc/init/varnishncsa.conf" ]; then
		invoke-rc.d varnishncsa start || exit $?
	fi
fi
# End automatically added section