From nobody Wed Nov 15 11:54:26 2023 X-Original-To: dev-commits-ports-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SVhR66vmRz51Sc3; Wed, 15 Nov 2023 11:54:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SVhR65yXvz4Xkr; Wed, 15 Nov 2023 11:54:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700049266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fp83OH+iGrhhmUK3T2uGpcnyWQIBBItBtcpoqRr2hCA=; b=sErpmPrqUb/1wdDfs7D/xOy9hWpuq1nnfr1eImyv/YV75cWOmSavU35uofsfMa0YD0YkoV +0A/4U40nX58n4iSZJE6WXaWEUDJWbOjowA+0ABB/fu/vIRo33aGXv8Jo5uLmMKQKLKKGh 63LVwwy0XilQsl/qYcsxVOfETi2dmOuBGp+rtzLvmbkb/UpCdOd6RT+sj5kCPMkcXeRNON E6ObNsysdcMEWEY0xi06fZvp37/zIMc9+73eg72ojewA2LhJwPL97HsYTSUqoMh4tGVMP6 uk5I7mOq7o0K/Q39J+XLXIugLUATxr7OB8axPvklgzyIiCxLLl5ZjWILc7VNRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700049266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fp83OH+iGrhhmUK3T2uGpcnyWQIBBItBtcpoqRr2hCA=; b=jzPC2GgHuWpM06CcetPb9pc26cYft6ClhHj9DCpIheM0fs5zkjCTe2usI0VbH/m/+hlyLQ TAFLomqcUE1SK8YrBuue6s4J0PIYZr2uCDZzZH6C51k05x7ABL5b1iDLd4ziKPc8btsAUj sBSbMoUrcbVdj6XE66YaVcZvODS3hsL4rPotpVZgAxe+SE7mlVexCmhcUgyI4VomW02l/X Uu87/RfPhyx8xFYmS71MbneU7oq4AwFZn3TwOKuE8vE3BVw61PkRLQMCfLly1ACDJMNsmi DFYAfXLn9dUbi+cUtQj4tnozVwd9i6Zhg900AUB4PEClp8+QaT7ZZsArn4E+Qw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700049266; a=rsa-sha256; cv=none; b=uw9L+tcA7MT7S32MLEutLy7EqIw2ZDQakmISDd9JOze6A6jeGfpb8HYzBLTEsCYfLv7LAP zFzqZe8g8svYXHlDS/AmNq5M/LRr9k6gAMsljmfG6vwhgJ5JCIiUix54pOGIvKU6WTqm+i mR7RqmlWU6bK1c6MxUBjvzGf6K2Wd51qtIoL6sR8pMV+k17i2zBO4aZC/yUs+bg/9JUDzF S5bcOo5FnrvUJ7dD9bvbNoztbGFh/ywmLeBSOO2vDhNla7traY8RG6aSaQGQPFIiiJZLn6 AktZghB0Ohb5uFrZXQD+iI4RJ0b5x65IzOUlF0fAEG7XmOzXrrtKBsy36C2dqg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SVhR654KYz1Nq; Wed, 15 Nov 2023 11:54:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AFBsQQv043047; Wed, 15 Nov 2023 11:54:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AFBsQLg043044; Wed, 15 Nov 2023 11:54:26 GMT (envelope-from git) Date: Wed, 15 Nov 2023 11:54:26 GMT Message-Id: <202311151154.3AFBsQLg043044@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Muhammad Moinur Rahman Subject: git: b1a8f824cc1c - main - sysutils/swtpm: Add rc script List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-main@freebsd.org X-BeenThere: dev-commits-ports-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bofh X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b1a8f824cc1c3a7e3ce0870509ef38d715f53c52 Auto-Submitted: auto-generated The branch main has been updated by bofh: URL: https://cgit.FreeBSD.org/ports/commit/?id=b1a8f824cc1c3a7e3ce0870509ef38d715f53c52 commit b1a8f824cc1c3a7e3ce0870509ef38d715f53c52 Author: Goran Mekić AuthorDate: 2023-11-15 11:52:26 +0000 Commit: Muhammad Moinur Rahman CommitDate: 2023-11-15 11:54:07 +0000 sysutils/swtpm: Add rc script - Pet portclippy while I am here PR: 274786 Approved by: submitter is maintainer --- sysutils/swtpm/Makefile | 16 +++--- sysutils/swtpm/files/swtpm.in | 120 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 6 deletions(-) diff --git a/sysutils/swtpm/Makefile b/sysutils/swtpm/Makefile index f5081098617d..d0bb04eaeafd 100644 --- a/sysutils/swtpm/Makefile +++ b/sysutils/swtpm/Makefile @@ -1,6 +1,7 @@ PORTNAME= swtpm DISTVERSIONPREFIX= v DISTVERSION= 0.8.1 +PORTREVISION= 1 CATEGORIES= sysutils MAINTAINER= meka@tilda.center @@ -10,23 +11,26 @@ WWW= https://github.com/stefanberger/swtpm LICENSE= BSD3CLAUSE LICENSE_FILE= ${WRKSRC}/LICENSE -LIB_DEPENDS= libfuse.so:sysutils/fusefs-libs \ - libgnutls.so:security/gnutls \ - libjson-glib-1.0.so:devel/json-glib \ - libtasn1.so:security/libtasn1 \ - libtpms.so:sysutils/libtpms BUILD_DEPENDS= base64>=0:converters/base64 \ bash>=0:shells/bash \ expect>=0:lang/expect \ gawk>=0:lang/gawk \ socat>=0:net/socat +LIB_DEPENDS= libfuse.so:sysutils/fusefs-libs \ + libgnutls.so:security/gnutls \ + libjson-glib-1.0.so:devel/json-glib \ + libtasn1.so:security/libtasn1 \ + libtpms.so:sysutils/libtpms USES= autoreconf gettext-runtime gmake gnome libtool pathfix \ pkgconfig ssl -USE_GNOME+= glib20 USE_GITHUB= yes GH_ACCOUNT= stefanberger +USE_GNOME+= glib20 +USE_RC_SUBR= swtpm + GNU_CONFIGURE= yes + INSTALL_TARGET= install-strip .include diff --git a/sysutils/swtpm/files/swtpm.in b/sysutils/swtpm/files/swtpm.in new file mode 100644 index 000000000000..83ab0eec2a37 --- /dev/null +++ b/sysutils/swtpm/files/swtpm.in @@ -0,0 +1,120 @@ +#!/bin/sh + +# PROVIDE: swtpm +# KEYWORD: shutdown + +# +# Add the following lines to /etc/rc.conf.local, /etc/rc.conf or +# /etc/rc.conf.d/swtpm to enable this service: +# +# swtpm_enable (bool): Set to NO by default. +# Set it to "YES" to enable swtpm. +# swtpm_configs (string): List of configurations to use +# Default is "tpm" +# swtpm_tpm (string): Arguments passed to swtpm config named tpm + +. /etc/rc.subr + +name=swtpm +desc="Software TPM manager" +rcvar=${name}_enable +start_precmd="${name}_precmd" +start_cmd="${name}_start" +stop_cmd="${name}_stop" +status_cmd="${name}_status" + +command="%%PREFIX%%/bin/swtpm" +command_args="socket" +pidpath="/var/run/${name}" + +# required_modules="cuse" +swtpm_default_args="\ + --daemon \ + --tpmstate dir=${pidpath} \ + --tpm2 \ + --log level=20" +configs= + +load_rc_config $name + +: ${swtpm_enable:="NO"} +: ${swtpm_configs:="tpm"} +: ${swtpm_tpm:="$swtpm_default_args"} + +swtpm_pids() +{ + pids=$(pgrep -d ' ' $name) + pids=${pids% } + printf "${pids}" +} + +swtpm_precmd() +{ + /usr/bin/install -d -m 0755 -o root ${pidpath} +} + +start_instance() +{ + config=$* + instance_args=$(eval "echo \$swtpm_${config}") + if [ -z "${instance_args}" ]; then + echo "No such config ${config}" + else + echo -n "Starting SWTPM config ${config} ..." + ${command} \ + ${command_args} \ + --pid file=${pidpath}/${config}.pid \ + --ctrl type=unixio,path=${pidpath}/${config} \ + ${instance_args} + echo " done" + fi +} + +stop_instance() +{ + config=$* + instance_args=`eval "echo \$swtpm_${config}"` + if [ -z "${instance_args}" ]; then + echo "No such config ${config}" + elif [ -e "${pidpath}/${config}.pid" ]; then + pid=$(check_pidfile ${pidpath}/${config}.pid %%PREFIX%%/bin/swtpm) + if [ ! -z "${pid}" ]; then + echo -n "Stopping SWTPM config ${config} ... " + kill $pid + rm -f ${pidpath}/${config}.pid + echo "done" + fi + fi +} + +swtpm_start() +{ + configs=$* + [ -z "${configs}" ] && configs="${swtpm_configs}" + for config in ${configs}; do + start_instance $config + done +} + +swtpm_stop() +{ + configs=$* + [ -z "${configs}" ] && configs="${swtpm_configs}" + for config in ${configs}; do + stop_instance ${config} + done +} + +swtpm_status() +{ + pids=$(swtpm_pids) + + if [ "${pids}" ]; then + echo "${name} is running as pid ${pids}." + else + echo "${name} is not running." + return 1 + fi +} + +run_rc_command $*