2018-08-28 02:51:17 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2019-10-07 22:14:47 +08:00
|
|
|
# Copyright (c) Mainflux
|
2018-08-28 02:51:17 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
|
|
|
|
###
|
2019-04-20 20:09:11 +08:00
|
|
|
# Provisions example user, thing and channel on a clean Mainflux installation.
|
2018-08-28 02:51:17 +08:00
|
|
|
#
|
|
|
|
# Expects a running Mainflux installation.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
if [ $# -lt 4 ]
|
2019-10-07 22:14:47 +08:00
|
|
|
then
|
2018-08-28 02:51:17 +08:00
|
|
|
echo "Usage: $0 user_email user_password device_name channel_name"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
EMAIL=$1
|
|
|
|
PASSWORD=$2
|
|
|
|
DEVICE=$3
|
|
|
|
CHANNEL=$4
|
|
|
|
|
|
|
|
#provision user:
|
|
|
|
printf "Provisoning user with email $EMAIL and password $PASSWORD \n"
|
|
|
|
curl -s -S --cacert docker/ssl/certs/mainflux-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users -d '{"email":"'"$EMAIL"'", "password":"'"$PASSWORD"'"}'
|
|
|
|
|
|
|
|
#get jwt token
|
|
|
|
JWTTOKEN=$(curl -s -S --cacert docker/ssl/certs/mainflux-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/tokens -d '{"email":"'"$EMAIL"'", "password":"'"$PASSWORD"'"}' | grep -Po "token\":\"\K(.*)(?=\")")
|
|
|
|
printf "JWT TOKEN for user is $JWTTOKEN \n"
|
|
|
|
|
2019-04-20 20:09:11 +08:00
|
|
|
#provision thing
|
|
|
|
printf "Provisioning thing with name $DEVICE \n"
|
|
|
|
curl -s -S --cacert docker/ssl/certs/mainflux-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: $JWTTOKEN" https://localhost/things -d '{"name":"'"$DEVICE"'"}'
|
2018-08-28 02:51:17 +08:00
|
|
|
|
2019-04-20 20:09:11 +08:00
|
|
|
#get thing token
|
2018-08-28 02:51:17 +08:00
|
|
|
DEVICETOKEN=$(curl -s -S --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: $JWTTOKEN" https://localhost/things/1 | grep -Po "key\":\"\K(.*)(?=\")")
|
|
|
|
printf "Device token is $DEVICETOKEN \n"
|
|
|
|
|
|
|
|
#provision channel
|
|
|
|
printf "Provisioning channel with name $CHANNEL \n"
|
|
|
|
curl -s -S --cacert docker/ssl/certs/mainflux-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: $JWTTOKEN" https://localhost/channels -d '{"name":"'"$CHANNEL"'"}'
|
|
|
|
|
2019-04-20 20:09:11 +08:00
|
|
|
#connect thing to channel
|
|
|
|
printf "Connecting thing to channel \n"
|
2018-08-28 02:51:17 +08:00
|
|
|
curl -s -S --cacert docker/ssl/certs/mainflux-server.crt --insecure -X PUT -H "Authorization: $JWTTOKEN" https://localhost/channels/1/things/1
|