]> git.proxmox.com Git - dab.git/blame - scripts/mysql_randompw
include wheezy-updates
[dab.git] / scripts / mysql_randompw
CommitLineData
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
13set -e
14
15HNAME=`head -n 1 /etc/hostname|awk '{ print $1; }'`
16
17if [ "X${HNAME}" = "Xlocalhost" ] ; then
18 exit 0;
19fi
20
21echo "Generate random MySQL root password"
22
23# set HOME dir (for .my.cfg)
24export HOME=/root
25export USER=root
26
27UPASSWD=`openssl rand -base64 9`
28mysqladmin password "${UPASSWD}"
29
30cat <<EOF > /root/.my.cnf
31[client]
32user=root
33password="${UPASSWD}"
34EOF
35
36chmod 0600 /root/.my.cnf
37
38if [ -x /sbin/insserv ] ; then
39 /sbin/insserv -r mysql_randompw
40 rm -f /etc/init.d/mysql_randompw
41else
42 rm -f /etc/init.d/mysql_randompw
43 update-rc.d -f mysql_randompw remove
44fi