From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1413913-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 73763158094
	for <garchives@archives.gentoo.org>; Fri,  1 Jul 2022 19:13:02 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id B50B7E0BAA;
	Fri,  1 Jul 2022 19:13:01 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(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)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 906C3E0BAA
	for <gentoo-commits@lists.gentoo.org>; Fri,  1 Jul 2022 19:13:01 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(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)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 71B5A3418A4
	for <gentoo-commits@lists.gentoo.org>; Fri,  1 Jul 2022 19:13:00 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 806534D3
	for <gentoo-commits@lists.gentoo.org>; Fri,  1 Jul 2022 19:12:58 +0000 (UTC)
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" <robbat2@gentoo.org>
Message-ID: <1656702766.6fb33c7d84a6e9fefe03ec6b0af77a01eaf1d421.robbat2@gentoo>
Subject: [gentoo-commits] proj/elections:master commit in: /
X-VCS-Repository: proj/elections
X-VCS-Files: README.md infra-schedule-countify-collect
X-VCS-Directories: /
X-VCS-Committer: robbat2
X-VCS-Committer-Name: Robin H. Johnson
X-VCS-Revision: 6fb33c7d84a6e9fefe03ec6b0af77a01eaf1d421
X-VCS-Branch: master
Date: Fri,  1 Jul 2022 19:12:58 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 7f429b4c-91e6-434d-8b7a-9e97c6c39e87
X-Archives-Hash: 57272b5424ead639bebfd5aefaaf74fa

commit:     6fb33c7d84a6e9fefe03ec6b0af77a01eaf1d421
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Fri Jul  1 19:12:46 2022 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Fri Jul  1 19:12:46 2022 +0000
URL:        https://gitweb.gentoo.org/proj/elections.git/commit/?id=6fb33c7d

infra-schedule-countify-collect: new tool to schedule countify --collect

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 README.md                       | 20 +++++++++++++++++--
 infra-schedule-countify-collect | 44 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index a59ed18..1afdba0 100644
--- a/README.md
+++ b/README.md
@@ -85,8 +85,24 @@ Trustees.
 Just wait. `election-stats-count` runs every 30 minutes by cronjob, and prints
 status files into the home directories of election officials: `voter-turnout-${election_name}`.
 
-4. Close of election:
----------------------
+4.a. Automated "Close of election"
+----------------------------------
+Before the end of the election, run the script to schedule automated
+`countify --collect`:
+```
+$ sudo su
+# cd /etc/elections
+# ./infra-schedule-countify-collect ${election_name}
+````
+
+The job can be verified with:
+```
+# atq
+# at -c $JOB_ID
+```
+
+4.b. Manual "Close of election"
+-------------------------------
 This is the only step where the infra contact is absolutely required.
 The infra contact must run `countify --collect ${election_name}` as root,
 which will write the master ballot & confirmation stub file to all officials:

diff --git a/infra-schedule-countify-collect b/infra-schedule-countify-collect
new file mode 100755
index 0000000..f44f343
--- /dev/null
+++ b/infra-schedule-countify-collect
@@ -0,0 +1,44 @@
+#!/bin/bash
+# This will schedule an at(1) job to run for countify --collect
+# Any special ballots must be in place before the end of the election.
+# Infra needs to run this script, and it will schedule the rest, so infra does
+# NOT need to be on hand at the end closing time.
+election_name=$1
+
+UID=$(id -u)
+if test $UID -ne 0; then
+	echo "You must be root to run this" 1>&2
+	exit 1
+fi
+
+# Find the dir, validate
+for d in /etc/elections/$election_name ./$election_name ; do
+	files=( start stop voters ballot officials )
+	good=1
+	for f in ${files[@]}; do
+		test -e $d/${f}-$election_name || good=0
+	done
+	if test $good -eq 1 ; then
+		export election_dir=$d
+		break
+	fi
+	unset good
+done
+
+if test -z "$election_dir" ; then
+	echo "Could not find election $election_name in /etc/elections" 1>&2
+	exit 1
+fi
+
+stopfile=$election_dir/stop-$election_name
+t=$(date -u +%Y%m%d%H%M.%S -d @$(<$stopfile) )
+
+cd /etc/elections
+unset MAIL PWD SSH_CLIENT SSH_CONNECTION SSH_TTY
+
+at -t $t <<-EOF
+#!/bin/sh
+# This was scheduled by $SUDO_USER at $(date -uR)
+cd /etc/elections
+./countify --collect ${election_name}
+EOF