Adding project base
This commit is contained in:
64
postservice/25-bdd-admin
Executable file
64
postservice/25-bdd-admin
Executable file
@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
todo=$(CreoleGet dbCreateFixAdmin 'non')
|
||||
|
||||
if [[ ${todo} != 'non' ]]
|
||||
then
|
||||
|
||||
readerfile="/root/.mysqlreader"
|
||||
touch "${readerfile}"
|
||||
chmod 600 ${readerfile}
|
||||
|
||||
tempFile=$(mktemp -p /root)
|
||||
sqlFile=$(mktemp -p /root)
|
||||
|
||||
accounts=($(CreoleGet accName))
|
||||
limits="$(CreoleGet accLimitTarget '')"
|
||||
accLimits=(${limits// /})
|
||||
index=0
|
||||
|
||||
previousUsers=($(awk -F ':' '{print $1}' ${readerfile} ))
|
||||
|
||||
for user in ${accounts[@]}
|
||||
do
|
||||
PASS=$(awk -F ':' "/${user}:/ {print \$2}" ${readerfile})
|
||||
[[ -z ${PASS} ]] && PASS=$(openssl rand -base64 32)
|
||||
|
||||
hostsList=()
|
||||
hostsList+=('localhost')
|
||||
if [[ ${accLimits[${index}]} != "Default" ]]
|
||||
then
|
||||
hostsList+=(${accLimits[${index}]//,/ })
|
||||
else
|
||||
ipAddr=($(CreoleGet ip_my_dist))
|
||||
ipMask=($(CreoleGet mask_my_dist))
|
||||
if [[ ${ipMask} == "255.255.255.255" ]]
|
||||
then
|
||||
hostsList+=("${ipAddr}")
|
||||
else
|
||||
hostsList+=("${ipAddr}/${ipMask}")
|
||||
fi
|
||||
fi
|
||||
for hst in ${hostsList[@]}
|
||||
do
|
||||
SQL="DROP USER IF EXISTS '${user}'@'${hst}';"
|
||||
SQL="${SQL} FLUSH PRIVILEGES;"
|
||||
SQL="${SQL} CREATE USER '${user}'@'${hst}' IDENTIFIED BY '${PASS}';"
|
||||
SQL="${SQL} GRANT ALL PRIVILEGES ON *.* TO '${user}'@'${hst}' WITH GRANT OPTION;"
|
||||
SQL="${SQL} FLUSH PRIVILEGES;"
|
||||
echo "${SQL}" >> ${sqlFile}
|
||||
echo " Managing user: ${user}@${hst}"
|
||||
done
|
||||
echo "${user}:${PASS}" >> ${tempFile}
|
||||
|
||||
index=$((index+1))
|
||||
done
|
||||
|
||||
mysql < ${sqlFile}
|
||||
|
||||
mv ${tempFile} ${readerfile}
|
||||
chmod 600 ${readerfile}
|
||||
rm -rf ${sqlFile}
|
||||
fi
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user