aboutsummaryrefslogtreecommitdiff
blob: f44f3439df92d5613d6ce389fb811d07718349d0 (plain)
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
#!/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