#!/bin/sh
+source `dirname $0`/functions
+
BASEPATH=$1
-SGCONFPATH="$BASEPATH/stg/projects/sgconf"
+SGCONFPATH="$BASEPATH/stg/build/projects/sgconf"
+
+printf "Check initial admin list... "
-RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --get-admins`
+RES=`"$SGCONFPATH/sgconf" -s 127.0.0.1 -p 5555 -u admin -w 123456 --get-admins`
if [ "$?" != "0" ]
then
+ printf "Error.\n"
printf "Failed to get admins list. Result:\n$RES\n"
exit 0
fi
-printf "Got admins list:\n"
+LOGINS=`getFields "login" "$RES"`
+
+NUM=`count "$LOGINS"`
-LOGINS=""
-OLDIFS=$IFS
-IFS=$(printf "\n")
-for LINE in $RES
-do
- printf -- "$LINE\n"
- LOGIN=`printf "$LINE" | grep login`
- if [ "$?" == "0" ]
- then
- LOGINS="$LOGINS\n"`printf "$LOGIN" | cut -d: -f2 | sed -e 's/^ *//' -e 's/ *$//'`
- fi
-done
-IFS=$OLDIFS
+if [ "$NUM" != "1" ]
+then
+ printf "Failed.\n"
+ printf "Admin list should have exactly one entry.\n"
+ printf "Logins:\n$LOGINS\n"
+ printf -- "--------\n$NUM\n\n"
+ exit 0
+fi
-printf "Logins:\n$LOGINS\n"
+printf "Ok.\nCheck updating admin permissions... "
-NUM=`printf "$LOGINS" | wc -l`
+RES=`"$SGCONFPATH/sgconf" -s localhost -p 5555 -u admin -w 123456 --chg-admin admin --priv 111111111`
+
+if [ "$?" != "0" ]
+then
+ printf "Error\n"
+ printf "Failed to update admin's priviledges Result:\n$RES\n"
+ exit 0
+fi
-printf -- "--------\n$NUM\n\n"
+printf "Ok.\n"