[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Initialize database in its own script



---
 setup/README  | 11 +----------
 setup/init_db | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 10 deletions(-)
 create mode 100755 setup/init_db

diff --git a/setup/README b/setup/README
index d53fb22..1d15a9b 100644
--- a/setup/README
+++ b/setup/README
@@ -24,16 +24,7 @@ Set up the dak user:
 # sudo adduser dak --disabled-login --ingroup ftpmaster --shell /bin/bash
 
 Create postgres roles and database:
-# sudo -u postgres psql
-  CREATE USER dak CREATEROLE;
-  CREATE ROLE ftpmaster WITH ROLE dak;
-  CREATE ROLE ftpteam WITH ROLE ftpmaster;
-  CREATE ROLE ftptrainee WITH ROLE ftpmaster, ftpteam;
-
-  CREATE DATABASE projectb WITH OWNER dak TEMPLATE template0 ENCODING 'SQL_ASCII';
-  \c projectb
-  CREATE EXTENSION IF NOT EXISTS plpgsql;
-  CREATE EXTENSION IF NOT EXISTS debversion;
+# sudo -u postgres ./init_db
 
 Set up the dak directory:
 # sudo mkdir /etc/dak
diff --git a/setup/init_db b/setup/init_db
new file mode 100755
index 0000000..a7de2a9
--- /dev/null
+++ b/setup/init_db
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+set -e
+set -u
+
+psql <<EOT
+  CREATE USER dak CREATEROLE;
+  CREATE ROLE ftpmaster WITH ROLE dak;
+  CREATE ROLE ftpteam WITH ROLE ftpmaster;
+  CREATE ROLE ftptrainee WITH ROLE ftpmaster, ftpteam;
+
+  CREATE DATABASE projectb WITH OWNER dak TEMPLATE template0 ENCODING 'SQL_ASCII';
+  \c projectb
+  CREATE EXTENSION IF NOT EXISTS plpgsql;
+  CREATE EXTENSION IF NOT EXISTS debversion;
+EOT
-- 
2.1.4



Reply to: