File: minidlna.postinst

package info (click to toggle)
minidlna 1.1.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,600 kB
  • ctags: 1,793
  • sloc: ansic: 19,398; sh: 284; makefile: 51
file content (67 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (6)
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
#!/bin/sh
# postinst script for minidlna

set -e

USER=minidlna
HOME_DIR=/var/lib/minidlna
CACHE_DIR=/var/cache/minidlna

setup_user() {

	if ! getent passwd "${USER}" >/dev/null; then
		adduser --quiet\
			--system \
			--group \
			--gecos "MiniDLNA server" \
			--home "${HOME_DIR}" \
			--no-create-home \
			${USER}
	fi
}

setup_cache() {
	if [ ! -d "${CACHE_DIR}" ];then
		mkdir -p "${CACHE_DIR}"
		chown ${USER}:${USER} "${CACHE_DIR}"
		chmod 750 "${CACHE_DIR}"
	fi
}

fix_statoverride() {
	# Previous versions create some dumb overrides and do not clean them on
	# removal, so we should remove them here.
        for file in /var/lib/minidlna /var/cache/minidlna /etc/minidlna.conf;do
		if dpkg-statoverride --list "${file}" >/dev/null; then
			dpkg-statoverride --remove "${file}"
		fi
	done
}

fix_permissions() {
	# Previous versions use some strange and even not secure permissions,
	# so we should fix them here.
	chown root:root /etc/minidlna.conf
	if [ -d "${CACHE_DIR}" ];then
		chown ${USER}:${USER} "${CACHE_DIR}"
		chmod 750 "${CACHE_DIR}"
	fi
}

ACTION="$1"
OLD_VERSION="$2"

if [ "$ACTION" = configure ];then
	setup_user

	if dpkg --compare-versions "$OLD_VERSION" lt-nl 1.1.5; then
		fix_statoverride
		fix_permissions
	fi

	setup_cache
fi

#DEBHELPER#

exit 0