This script can create the adminTenant and demoTenant, create Roles, setup permissions, create service and their endpoints. Execute this script as:

./keystonescript openstack1_IP

#keystonescript
 
if [ $# != 1 ]
then
  echo "Usage: keystonescript openstack1_IP";
  exit 1;
fi

region=RegionOne
publicIP=$1
adminIP=$1
internalIP=$1

sudo bin/keystone-manage tenant add adminTenant
sudo bin/keystone-manage user add adminUser password
sudo bin/keystone-manage role add Admin
sudo bin/keystone-manage role grant Admin adminUser
sudo bin/keystone-manage role grant Admin adminUser adminTenant

sudo bin/keystone-manage tenant add demoTenant
sudo bin/keystone-manage user add demoUser password
sudo bin/keystone-manage role add Member
sudo bin/keystone-manage role grant Member demoUser
sudo bin/keystone-manage role grant Member demoUser demoTenant

sudo bin/keystone-manage role add KeystoneServiceAdmin
sudo bin/keystone-manage role grant KeystoneServiceAdmin adminUser
sudo bin/keystone-manage role grant KeystoneServiceAdmin adminUser adminTenant

sudo bin/keystone-manage token add 999888777666 adminUser adminTenant 2015-02-05T00:00

sudo bin/keystone-manage service add nova compute "OpenStack Compute Service"
sudo bin/keystone-manage service add glance image "OpenStack Image Service"
sudo bin/keystone-manage service add identity identity "OpenStack Identity Service"

sudo bin/keystone-manage endpointTemplates add $region nova http://$publicIP:8774/v1.1/%tenant_id% http://$adminIP:8774/v1.1/%tenant_id% http://$internalIP:8774/v1.1/%tenant_id% 1 1

sudo bin/keystone-manage endpointTemplates add $region glance http://$publicIP:9292/v1.1/%tenant_id% http://$adminIP:9292/v1.1/%tenant_id% http://$internalIP:9292/v1.1/%tenant_id% 1 1

sudo bin/keystone-manage endpointTemplates add $region identity http://$publicIP:5000/v2.0 http://$adminIP:35357/v2.0 http://$internalIP:5000/v2.0 1 1