mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
36 lines
877 B
Bash
36 lines
877 B
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
force=$1
|
|
|
|
function safe_copy () {
|
|
if [[ "$force" == "True" ]]; then
|
|
sudo yunohost service safecopy \
|
|
-s mysql $1 $2 --force
|
|
else
|
|
sudo yunohost service safecopy \
|
|
-s mysql $1 $2
|
|
fi
|
|
}
|
|
|
|
function randpass () {
|
|
[ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
|
|
cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
|
|
echo
|
|
}
|
|
|
|
cd /usr/share/yunohost/templates/mysql
|
|
|
|
if [[ "$(safe_copy my.cnf /etc/mysql/my.cnf | tail -n1)" == "True" ]]; then
|
|
sudo service mysql restart
|
|
fi
|
|
|
|
if [ ! -f /etc/yunohost/mysql ]; then
|
|
[[ $(/bin/ps aux | grep '[m]ysqld') == "0" ]] \
|
|
&& sudo service mysql start
|
|
|
|
mysql_password=$(randpass 10 0)
|
|
sudo mysqladmin -u root -pyunohost password $mysql_password
|
|
echo $mysql_password | sudo tee /etc/yunohost/mysql
|
|
sudo chmod 400 /etc/yunohost/mysql
|
|
fi
|