Debian Codegraph @

script/booth-keygen

raw
1 #!/bin/sh
2 #
3 # Generate authentication key for booth
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 #
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like. Any license provided herein, whether implied or
16 # otherwise, applies only to this software file. Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #
24
25 DFLT_AUTHFILE=/etc/booth/authkey
26 KEYSIZE=64
27 # /dev/urandom should be good enough
28 RND_SRC=/dev/urandom
29
30 usage() {
31 cat<<EOF
32 usage: $0 [-h] [auth-file]
33 EOF
34 exit
35 }
36 error() {
37 echo "ERROR: $*" >&2
38 }
39 fatal() {
40 error $*
41 exit 1
42 }
43
44 case "$1" in
45 "-h"|"--help"|"-?") usage;;
46 /*|"") : ;;
47 *) fatal "please use absolute path for the key file" ;;
48 esac
49
50 keyf=${1:-$DFLT_AUTHFILE}
51
52 if test -f $keyf; then
53 fatal "file $keyf already exists"
54 fi
55
56 umask 077
57 errout=`dd if=$RND_SRC of=$keyf bs=$KEYSIZE count=1 2>&1`
58 rc=$?
59 if [ $rc -ne 0 ]; then
60 echo "$errout" >&2
61 exit $rc
62 fi
63
64 chown root:root $keyf