]>
Commit | Line | Data |
---|---|---|
8ab34b87 DM |
1 | #!/bin/sh |
2 | ### BEGIN INIT INFO | |
3 | # Provides: mysql_randompw | |
4 | # Required-Start: $local_fs mysql | |
5 | # Required-Stop: | |
6 | # X-Start-Before: | |
7 | # Default-Start: 2 | |
8 | # Default-Stop: | |
9 | # Short-Description: Generate random MySQL root password | |
10 | # Description: Generate and set a random MySQL root password | |
11 | ### END INIT INFO | |
12 | ||
13 | set -e | |
14 | ||
15 | HNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'` | |
16 | ||
17 | if [ "X${HNAME}" = "Xlocalhost" ] ; then | |
18 | exit 0; | |
19 | fi | |
20 | ||
21 | echo "Generate random MySQL root password" | |
22 | ||
23 | # set HOME dir (for .my.cfg) | |
24 | export HOME=/root | |
25 | export USER=root | |
26 | ||
27 | UPASSWD=`openssl rand -base64 9` | |
28 | mysqladmin password "${UPASSWD}" | |
29 | ||
30 | cat <<EOF > /root/.my.cnf | |
31 | [client] | |
32 | user=root | |
33 | password="${UPASSWD}" | |
34 | EOF | |
35 | ||
36 | chmod 0600 /root/.my.cnf | |
37 | ||
38 | if [ -x /sbin/insserv ] ; then | |
39 | /sbin/insserv -r mysql_randompw | |
40 | rm -f /etc/init.d/mysql_randompw | |
41 | else | |
42 | rm -f /etc/init.d/mysql_randompw | |
43 | update-rc.d -f mysql_randompw remove | |
44 | fi |