copy nb configuration and modules
This commit is contained in:
13
utils/modules/mysql/default.nix
Normal file
13
utils/modules/mysql/default.nix
Normal file
@@ -0,0 +1,13 @@
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
mysql-scripts = pkgs.callPackage ./pkgs/mysql-scripts.nix {};
|
||||
in {
|
||||
environment.systemPackages = [
|
||||
mysql-scripts
|
||||
];
|
||||
|
||||
services.mysql = {
|
||||
enable = true;
|
||||
package = pkgs.mariadb;
|
||||
};
|
||||
}
|
||||
14
utils/modules/mysql/pkgs/mysql-scripts.nix
Normal file
14
utils/modules/mysql/pkgs/mysql-scripts.nix
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
stdenv,
|
||||
lib,
|
||||
bash,
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
name = "mysql-scripts";
|
||||
src = ./scripts;
|
||||
buildInputs = [ bash ];
|
||||
#nativeBuildInputs = [lib.makeWrapper];
|
||||
installPhase = ''
|
||||
install -D --target $out/bin *
|
||||
'';
|
||||
}
|
||||
28
utils/modules/mysql/pkgs/scripts/create-database.sh
Normal file
28
utils/modules/mysql/pkgs/scripts/create-database.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
echo "Usage: $0 <database>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ $EUID -eq 0 ]
|
||||
then
|
||||
echo "Must be root!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DB="$1"
|
||||
PASSWORD="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 64 | xargs)"
|
||||
|
||||
cat <<EOF | mysql --host localhost --user root
|
||||
create database $DB;
|
||||
grant usage on $DB.* to '$DB'@'%' identified by '$PASSWORD';
|
||||
grant all privileges on $DB.* to '$DB'@'%';
|
||||
EOF
|
||||
|
||||
echo
|
||||
echo "Password for user $DB is:"
|
||||
echo
|
||||
echo $PASSWORD
|
||||
echo
|
||||
25
utils/modules/mysql/pkgs/scripts/delete-database.sh
Normal file
25
utils/modules/mysql/pkgs/scripts/delete-database.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
echo "Usage: $0 <database>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ $EUID -eq 0 ]
|
||||
then
|
||||
echo "Must be root!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DB="$1"
|
||||
PASSWORD="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 64 | xargs)"
|
||||
|
||||
cat <<EOF | mysql --host localhost --user root
|
||||
drop database $DB;
|
||||
drop user '$DB';
|
||||
EOF
|
||||
|
||||
echo
|
||||
echo "Dropped database $DB!"
|
||||
echo
|
||||
Reference in New Issue
Block a user