[sdc] update code of sdc
[sdc.git] / ui-ci / src / main / resources / ci / scripts / addUsersFromList_new.sh
1 #!/bin/bash
2
3 function help_usage ()
4 {
5         echo "$0 -ip <ip> -f <userToAdd_file>"
6         echo "for example: -ip 127.0.0.1 -f /var/tmp/userToAdd.txt"
7         exit
8 }
9
10 function check_file_existance ()
11 {
12 echo "check_file_existance $1"
13 if [ $1 == "" ]; then
14         echo "Please provide full path to user file"
15         exit;
16 elif [ -f $1 ]; then
17         source $1
18         USERS=("${USER_LIST[@]}")
19         echo "file exist" $1
20 else
21         echo "Provided user file does not exist"
22         exit
23 fi
24 }
25
26 function check_ip_existance ()
27 {
28 if [ $1 == "" ]; then
29         echo "Please provide ip address"
30         exit;
31 fi
32 }
33
34 function addUser ()
35 {
36         #for user in "${USER_LIST[@]}"; do
37         for user in "${USERS[@]}"; do
38                 PING=`ping -c 1 $IP  > /var/tmp/ping.log`
39                 pattern1='100% packet loss'
40                 pattern2='Host Unreachable'
41                 COUNT=`egrep -c "$pattern1|$pattern2" /var/tmp/ping.log`
42                 if [ $COUNT -eq 0 ]; then
43                 #       curl -i -X post -d '{ "userId" : "kk1123", "role" : "ADMIN" }'  -H "Content-Type: application/json" -H "USER_ID: jh0003" http://192.168.111.9:8080/sdc2/rest/v1/user
44                         userId=`echo $user|awk '{print $1}'`
45                         role=`echo $user|awk '{print $2}'`
46             firstName=`echo $user|awk '{print $3}'`
47             lastName=`echo $user|awk '{print $4}'`
48             email=`echo $user|awk '{print $5}'`
49                         curl -i -X post -d '{ "userId" : "'${userId}'", "role" : "'${role}'", "firstName" : "'${firstName}'", "lastName" : "'${lastName}'", "email" : "'${email}'" }'  -H "Content-Type: application/json" -H "USER_ID: jh0003" http://${IP}:8080/sdc2/rest/v1/user
50                 else
51                         echo "Host" $IP "Is Unreachable"
52                 fi
53         done
54 curl -i -X post -d '{"consumerName": "ci","consumerSalt": "2a1f887d607d4515d4066fe0f5452a50","consumerPassword": "0a0dc557c3bf594b1a48030e3e99227580168b21f44e285c69740b8d5b13e33b"}'  -H "Content-Type: application/json" -H "USER_ID: jh0003" -H "Authorization:Basic Y2k6MTIzNDU2" http://${IP}:8080/sdc2/rest/v1/consumers
55         
56 }
57
58 #main
59 [ $# -eq 0 ] && help_usage
60 while [ $# -ne 0 ]; do
61         case $1 in
62                 "-f")
63                         USER_FILE=$2
64                         shift 1
65                         shift 1
66                 ;;      
67                 -ip)
68                         IP=$2
69                         shift 1
70                         shift 1
71                 ;;
72                 *)
73 #                       help_usage
74                 ;;
75         esac
76 done
77
78 check_file_existance $USER_FILE
79 check_ip_existance $IP
80 addUser