1 |
On 21/08/14 22:24, Kerin Millar wrote: |
2 |
> On 21/08/2014 12:07, Bill Kenworthy wrote: |
3 |
>> Hi, |
4 |
>> I am building some VM's using scripts and want to run "emerge |
5 |
>> --config |
6 |
>> mariadb" automaticly. However it asks for a new root password (entered |
7 |
>> twice) as part of the process - I was going to make an expect script to |
8 |
>> enter the password for me ... but I thought someone might know a |
9 |
>> better way? |
10 |
>> |
11 |
> |
12 |
> You can execute mysql_install_db directly instead of relying on |
13 |
> distro-specific voodoo. Something like this should do the trick:- |
14 |
> |
15 |
> #!/bin/bash |
16 |
> set -e |
17 |
> |
18 |
> # Use SELECT PASSWORD('<password>') to generate a hash |
19 |
> password_hash="*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19" |
20 |
> |
21 |
> # Do nothing if MySQL appears to have been configured |
22 |
> [[ -f /var/lib/mysql/ibdata1 ]] && exit 0 |
23 |
> |
24 |
> # Initialize the database |
25 |
> mysql_install_db |
26 |
> |
27 |
> # Set root password, delete spurious root accounts, drop test database |
28 |
> mysql -B <<-SQL |
29 |
> SET PASSWORD FOR 'root'@'%' = '${password_hash}'; |
30 |
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; |
31 |
> DELETE FROM mysql.user WHERE Host != '%'; |
32 |
> FLUSH PRIVILEGES; |
33 |
> DROP DATABASE test; |
34 |
> SQL |
35 |
> |
36 |
> --Kerin |
37 |
> |
38 |
|
39 |
Tkx, it worked but I ended up with a simple: |
40 |
|
41 |
echo 'password:)' > a && echo 'password:)' >> a && emerge --config |
42 |
mariadb < a && rm a |
43 |
|
44 |
Whilst I can understand the reluctance to make auto-entering passwords |
45 |
easy for security reasons, there are use-cases for quick build/config |
46 |
throwaway solutions in a safe environment where its just a pain :) |
47 |
|
48 |
BillK |