-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmicadoctl.sh
executable file
·96 lines (87 loc) · 2.22 KB
/
micadoctl.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
SCRIPT=$(basename $0)
if [[ ! $1 =~ (adduser)|(verify)|(resetpwd)|(changepwd)|(getrole)|(changerole)|(deleteuser) ]]; then
echo "Usage: ./$SCRIPT adduser|verify|resetpwd|changepwd|getrole|changerole|deleteuser"
exit 1
fi
if [[ $1 == 'adduser' ]];
then
if [ -z "$2" ] && [ -z "$3" ] && [ -z "$4" ]
then
echo "Usage: $(basename $0) adduser arg1 arg2 arg3"
echo "arg1 (required): username"
echo "arg2 (optional): password"
echo "arg3 (optional): email"
exit 0
fi
if [ -z "$4" ]
then
curl -X POST -d "username=$2&password=$3" localhost:5001/v1.1/adduser
else
curl -X POST -d "username=$2&password=$3&email=$4" localhost:5001/v1.1/adduser
fi
fi
if [[ $1 == 'verify' ]];
then
if [ -z "$2" ] || [ -z "$3" ]
then
echo "Usage: $(basename $0) verify arg1 arg2"
echo "arg1 (required): username"
echo "arg2 (required): password"
exit 0
fi
curl -X POST -d "username=$2&password=$3" localhost:5001/v1.1/verify
fi
if [[ $1 == 'resetpwd' ]];
then
if [ -z "$2" ]
then
echo "Usage: $(basename $0) resetpwd arg1"
echo "arg1 (required): username"
exit 0
fi
curl -X PUT -d "username=$2" localhost:5001/v1.1/resetpwd
fi
if [[ $1 == 'changepwd' ]];
then
if [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]
then
echo "Usage: $(basename $0) changepwd arg1 arg2 arg3"
echo "arg1 (required): username"
echo "arg2 (required): current password"
echo "arg3 (required): new password"
exit 0
fi
curl -X PUT -d "username=$2&oldpasswd=$3&newpasswd=$4" localhost:5001/v1.1/changepwd
fi
if [[ $1 == 'getrole' ]];
then
if [ -z "$2" ]
then
echo "Usage: $(basename $0) getrole arg1"
echo "arg1 (required): username"
exit 0
fi
curl -X GET -d "username=$2" localhost:5001/v1.1/getrole
fi
if [[ $1 == 'changerole' ]];
then
if [ -z "$2" ] || [ -z "$3" ]
then
echo "Usage: $(basename $0) changerole arg1 arg2"
echo "arg1 (required): username"
echo "arg2 (required): new role ('user' or 'admin')"
exit 0
fi
curl -X PUT -d "username=$2&newrole=$3" localhost:5001/v1.1/changerole
fi
if [[ $1 == 'deleteuser' ]];
then
if [ -z "$2" ]
then
echo "Usage: $(basename $0) deleteuser arg1"
echo "arg1 (required): username"
exit 0
fi
curl -X PUT -d "username=$2" localhost:5001/v1.1/deleteuser
fi