examples: Reformat shell scripts
[Samba.git] / examples / ad-bench / utils.sh
blob5a7c015b58fe2a4064a67e231987f81e7cd4e677
1 #!/bin/bash
2 # AD-Bench utility functions
4 # Copyright (C) 2009 Kai Blin <kai@samba.org>
6 # This file is part of AD-Bench, an Active Directory benchmark tool
8 # AD-Bench is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # AD-Bench is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with AD-Bench. If not, see <http://www.gnu.org/licenses/>.
21 source $(dirname $0)/settings.sh
23 start_timer()
25 START_TIME=$(${DATE} ${DATE_FORMATSTR})
26 echo "$START_TIME"
29 stop_timer()
31 STOP_TIME=$(${DATE} ${DATE_FORMATSTR})
32 echo "$STOP_TIME"
35 total_time()
37 START_TIME=$1
38 END_TIME=$2
39 TOTAL_TIME=$(echo "scale=9;$STOP_TIME - $START_TIME" | ${BC})
40 echo "$TOTAL_TIME"
43 iterations_per_minute()
45 START_TIME=$1
46 STOP_TIME=$2
47 TOTAL_RUNS=$3
49 TOTAL_TIME=$(total_time $START_TIME $STOP_TIME)
51 ITER_PER_MIN=$(echo "scale=2; 60 * $TOTAL_RUNS / $TOTAL_TIME" | ${BC})
52 echo "$ITER_PER_MIN"
55 get_principal()
57 PRINCIPAL=$(echo $1 | ${SED} -e "s/\(.*\)%.*/\1/")
58 echo "$PRINCIPAL"
61 get_password()
63 PASSWORD=$(echo $1 | ${SED} -e "s/.*%\(.*\)/\1/")
64 echo "$PASSWORD"
67 get_realm()
69 REALM=$(echo $1 | ${SED} -e "s/.*@\(.*\)%.*/\1/")
70 echo "$REALM"
73 get_nt_dom()
75 NT_DOM=$(echo $1 | ${SED} -e "s/.*@\([A-Z1-9-]*\)\..*/\1/")
76 echo "$NT_DOM"
79 set_krb_env()
81 OLD_KRB5CCNAME="${KRB5CCNAME}"
82 KRB5CCNAME="${NEW_KRB5CCNAME}"
83 export KRB5CCNAME
86 restore_krb_env()
88 KRB5CCNAME="${OLD_KRB5CCNAME}"
89 export KRB5CCNAME
92 setup_kinit()
94 ${KINIT} --invalid 2>&1 | grep -q "password-file"
95 if [ $? -eq 0 ]; then
96 KINIT="${KINIT} ${KINIT_PARAM_OLD}"
97 else
98 KINIT="${KINIT} ${KINIT_PARAM_NEW}"
102 write_configfile()
104 REALM=$1
105 NT_DOM=$2
106 echo -e "[global]" >$CONFIG_FILE
107 echo -e "\trealm = $REALM" >>$CONFIG_FILE
108 echo -e "\tworkgroup = $NT_DOM" >>$CONFIG_FILE
109 echo -e "\tsecurity = ADS" >>$CONFIG_FILE
112 call_kinit()
114 PRINCIPAL=$1
115 PASSWORD=$2
116 echo "${PASSWORD}" | ${KINIT} ${PRINCIPAL} >/dev/null
117 RET=$?
118 if [ $RET -ne 0 ]; then
119 echo "kinit returned an error: $RET"
120 exit 1
124 pad_number()
126 NUMBER=$1
127 DIGITS=$2
128 PADDED_NO=$(printf "%0${DIGITS}d" $NUMBER)
129 echo $PADDED_NO