#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/pcsc-lite/files/pcscd-init.7,v 1.1 2014/02/14 23:11:54 flameeyes Exp $
#
# Forked from Alpine's pcsc-lite package to start the cardreader hardware on
# the librem 5

name="PC/SC Daemon for the Librem 5"

pidfile=/run/pcscd/pcscd.pid

command=/usr/sbin/pcscd
command_args="${EXTRA_OPTS}"

start_stop_daemon_args="--user pcscd:pcscd"

depend() {
	need localmount
	after udev openct dbus
	use logger
}

start_pre() {
	checkpath -d -m 0755 -o pcscd:pcscd /run/pcscd

	# power on smartcard reader
	echo 1 > /sys/class/leds/smc_en/brightness

	# delay to give card reader time to start up
	sleep 2
}

stop_post() {
	# power off smartcard reader
	echo 0 > /sys/class/leds/smc_en/brightness
}
