#!/bin/sh

if [ -z "$RPM_INSTALL_NAME" ]; then
    echo "You can't run this script manually, because it can override some privileges values."
    exit 1
fi

user_alter=
for alter in "Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "Super_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL" \
    "ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL" \
    "ssl_cipher BLOB NOT NULL" \
    "x509_issuer BLOB NOT NULL" \
    "x509_subject BLOB NOT NULL" \
    "max_questions int(11) NOT NULL" \
    "max_updates   int(11) unsigned NOT NULL" \
    "max_connections int(11) unsigned NOT NULL"; do
user_alter="$user_alter
ALTER TABLE user ADD $alter;"
done

/usr/sbin/mysqld --bootstrap --skip-grant-tables --skip-innodb <<END_OF_DATA
use mysql;

ALTER TABLE user type=MyISAM;
ALTER TABLE db type=MyISAM;
ALTER TABLE host type=MyISAM;
ALTER TABLE func type=MyISAM;
ALTER TABLE columns_priv type=MyISAM;
ALTER TABLE tables_priv type=MyISAM;

$user_alter

update user set show_db_priv= select_priv, super_priv=process_priv, execute_priv=process_priv, create_tmp_table_priv='Y', Lock_tables_priv='Y', Repl_slave_priv=file_priv, Repl_client_priv=file_priv where user<>"";

alter table db add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL;
alter table db add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;

alter table host add Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL;
alter table host add Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL;
END_OF_DATA
