post_install() {
	if ! getent passwd sndiod &>/dev/null; then
		useradd -r -g audio -G adm -d /run/sndiod -s /bin/nologin sndiod >/dev/null
	fi
	if ! groups sndiod | grep audio &>/dev/null; then
		gpasswd -a sndiod audio >/dev/null
	fi
	if ! groups sndiod | grep adm &>/dev/null; then
		gpasswd -a sndiod adm >/dev/null
	fi
	sndiod_shell=$(getent passwd sndiod | cut -d: -f7)
	if [ "$sndiod_shell" != '/bin/nologin' ]; then
		chsh -s /bin/nologin sndiod &>/dev/null
	fi
	if [[ ! -h /etc/runlevels/default/sndiod ]]; then
		if [[ ! -d /etc/runlevels/default ]]; then
			mkdir -p /etc/runlevels/default
		fi
		ln -s /etc/init.d/sndiod /etc/runlevels/default/sndiod
	fi
	if [[ ! -h /etc/runlevels/nonetwork/sndiod ]]; then
		if [[ ! -d /etc/runlevels/nonetwork ]]; then
			mkdir -p /etc/runlevels/nonetwork
		fi
		ln -s /etc/init.d/sndiod /etc/runlevels/nonetwork/sndiod
	fi
}

post_upgrade() {
	if ! getent passwd sndiod &>/dev/null; then
		useradd -r -g audio -G adm -d /run/sndiod -s /bin/nologin sndiod >/dev/null
	fi
	if ! groups sndiod | grep audio &>/dev/null; then
		gpasswd -a sndiod audio >/dev/null
	fi
	if ! groups sndiod | grep adm &>/dev/null; then
		gpasswd -a sndiod adm >/dev/null
	fi
	sndiod_shell=$(getent passwd sndiod | cut -d: -f7)
	if [ "$sndiod_shell" != '/bin/nologin' ]; then
		chsh -s /bin/nologin sndiod &>/dev/null
	fi
	if (( $(vercmp $2 1.6.0-1.hyperbola4.backports1) < 0 )); then
		if [[ ! -h /etc/runlevels/default/sndiod ]]; then
			if [[ ! -d /etc/runlevels/default ]]; then
				mkdir -p /etc/runlevels/default
			fi
			ln -s /etc/init.d/sndiod /etc/runlevels/default/sndiod
		fi
		if [[ ! -h /etc/runlevels/nonetwork/sndiod ]]; then
			if [[ ! -d /etc/runlevels/nonetwork ]]; then
				mkdir -p /etc/runlevels/nonetwork
			fi
			ln -s /etc/init.d/sndiod /etc/runlevels/nonetwork/sndiod
		fi
	fi
}

post_remove() {
	if getent passwd sndiod &>/dev/null; then
		userdel sndiod >/dev/null
	fi
}
