-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_user.sh
executable file
·72 lines (58 loc) · 1.65 KB
/
add_user.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
if [ -z "$1" ]
then
TASKD=../../src/taskd
else
TASKD=$1
fi
if [ -z "$2" ]
then
ROOT=$PWD/root
else
ROOT=$2
fi
if [ -z "$3" ]
then
ROOT_CA=../../pki/ca.cert.pem
else
ROOT_CA=$3
fi
if ! [ -z "$4" ] ; then
if [ "$4" -ge 2048 ] ; then
BITS=$4
fi
fi
#read username and org from comandline
read -p "Username?`echo $'\n> '`" USER
read -p "Org?`echo $'\n> '`" ORGANIZATION
#create org if nessersary
$TASKD add --data $ROOT org $ORG >&2>/dev/null
#create user
$TASKD add --data $ROOT user --quiet $ORGANIZATION $USER 1> user.key
#find configs
$TASKD config --data $ROOT |grep '^server ' >server
./generate.client $ORGANIZATION$USER
cd $PWD
mv $ORGANIZATION$USER.cert.pem $USER.cert
#cat `$TASKD config --data $ROOT |grep '^client.cert '| sed -e 's/client.cert//'`>$USER.cert
cat $ORGANIZATION$USER.key.pem |sed -n '/-----BEGIN RSA PRIVATE KEY-----/,/-----END RSA PRIVATE KEY-----/p' >$USER.key
#if user-config already exists remove it
rm -rf $USER.taskdconfig
#Write to user-conf file
echo "username: "$USER>>$USER.taskdconfig
echo "org: "$ORG>>$USER.taskdconfig
cat user.key| sed 's/New user key:/user key:/g'>>$USER.taskdconfig
echo "server: "`cat server| sed 's/^server//g'|sed 's/^[ \t]*//'`>>$USER.taskdconfig
echo "Client.cert:">>$USER.taskdconfig
cat $USER.cert>>$USER.taskdconfig
echo "Client.key:">>$USER.taskdconfig
cat $USER.key>>$USER.taskdconfig
echo "ca.cert:">>$USER.taskdconfig
cat $ROOT_CA>>$USER.taskdconfig
#remove temp-files
rm -rf user.key server $USER.cert
rm -rf user.key server $USER.key
echo
echo "You're ready!"
echo "Copy the "$USER.taskdconfig" to your device and don't forget to start the server"
#echo "./run"