From f575f8e2e3c0341a32ffbfb60942f7cde0f33f56 Mon Sep 17 00:00:00 2001 From: rurban Date: Thu, 1 Jul 2004 08:15:10 +0000 Subject: [PATCH] improved make git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@3828 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- Makefile | 75 ++++++++++++++++++++++++++++++++--------- config/make-dbhelper.pl | 32 +++++++++++++----- 2 files changed, 82 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 60fef7e4f..935fc94cd 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,46 @@ -# gnu make (also with cygwin) version -DB_ADMINUSER=root -DB_ADMINPASS=secret +# $Id: Makefile,v 1.5 2004-07-01 08:15:10 rurban Exp $ +# user-definable settings: +# for mysqladmin +DBADMIN_USER=root +DBADMIN_PASS=secret + +DB_SQLITE_DBFILE = /tmp/phpwiki-sqlite.db + +# **************************************************************************** # get db params from config/config.ini -DATABASE_DSN := $(shell config/make-dbhelper.pl config/config.ini) -#DB_DB=phpwiki -DB_DB := $(word 1,${DATABASE_DSN}) -#DB_USER=wikiuser -DB_USER := $(word 2,${DATABASE_DSN}) -#DB_PASS= -DB_PASS := $(word 3,${DATABASE_DSN}) +#DATABASE_TYPE=SQL +DATABASE_TYPE := $(shell config/make-dbhelper.pl -v=DATABASE_TYPE config/config.ini) +PROCESS_DSN=0 +ifeq (${DATABASE_TYPE},SQL) + PROCESS_DSN=1 +else + ifeq (${DATABASE_TYPE},ADODB) + PROCESS_DSN=1 + endif +endif + +ifeq (${PROCESS_DSN},1) + # get db params from config/config.ini DATABASE_DSN setting (only if SQL or ADODB) + DATABASE_DSN := $(shell config/make-dbhelper.pl -v=DATABASE_DSN config/config.ini) + #DB_DBTYPE=mysql + DB_DBTYPE := $(word 1,${DATABASE_DSN}) + #DB_DB=phpwiki + DB_DB := $(word 2,${DATABASE_DSN}) + #DB_USER=wikiuser + DB_USER := $(word 3,${DATABASE_DSN}) + #DB_PASS= + DB_PASS := $(word 4,${DATABASE_DSN}) + + DBADMIN_OPTS=-u$(DBADMIN_USER) -p$(DBADMIN_PASS) +else + DB_DBTYPE=${DATABASE_TYPE} +endif -DB_SQLITE_DBFILE = /tmp/phpwiki-sqlite.db # **************************************************************************** PHP_SRC := $(wildcard *.php ./lib/*.php ./lib/WikiDB/*.php ./lib/plugin/*.php) -.PHONY: all locale mysql psql sqlite +.PHONY: all install locale mysql pqsql sqlite dbtest all: TAGS @@ -32,12 +57,30 @@ locale: cd locale make -DB_OPTS=-u$(DB_ADMINUSER) -p$(DB_ADMINPASS) +install: install-config install-database + +install-config: config/config.ini + +config/config.ini: config/config-dist.ini + cp config/config-dist.ini $@ + echo "You must edit config/config.ini, at least set the ADMIN_PASSWD" + ${EDITOR} $@ + +# helpers for database installation +install-database: ${DB_DBTYPE} + +dba: + +cvs: + +# maybe setup permissions +file: dbtest: - echo DB_OPTS=$(DB_OPTS) DB_DB=$(DB_DB) DB_USER=${DB_USER} DB_PASS=${DB_PASS} + echo DATABASE_TYPE=${DATABASE_TYPE} DB_DBTYPE=${DB_DBTYPE} DB_DB=$(DB_DB) DB_USER=${DB_USER} DB_PASS=${DB_PASS} DBADMIN_OPTS=$(DBADMIN_OPTS) # initialize the database +# TODO: compare /var/mysql/data/$(DB_DB) timestamp against schemas/mysql.sql mysql: mysqladmin $(DB_OPTS) create $(DB_DB) mysql $(DB_OPTS) -e "GRANT select,insert,update,delete,lock tables ON $(DB_DB).* \ @@ -45,7 +88,7 @@ TO $(DB_USER)@localhost IDENTIFIED BY '$(DB_PASS)';" mysql $(DB_OPTS) $(DB_DB) < schemas/mysql.sql # initialize the database -psql: +pqsql: su postmaster createdb $(DB_DB) ifeq ($(DB_PASS),"") @@ -57,7 +100,7 @@ psql: logout # initialize the database -sqlite: +sqlite: $(DB_SQLITE_DBFILE) sqlite $(DB_SQLITE_DBFILE) < schemas/sqlite.sql # update the database diff --git a/config/make-dbhelper.pl b/config/make-dbhelper.pl index 78ed31a9b..67fc3bbac 100755 --- a/config/make-dbhelper.pl +++ b/config/make-dbhelper.pl @@ -1,13 +1,27 @@ -#!/usr/bin/perl -n -# makefile helper to extract the database, user and password from config.ini +#!/usr/bin/perl -sn +# makefile helper to extract various settings from config/config.ini +# $Id: make-dbhelper.pl,v 1.2 2004-07-01 08:15:10 rurban Exp $ -if (/^\s*DATABASE_DSN\s*=\s*"?([\w:\/@]+)/) { - $dsn = $1; - $db = $user = $pass = ''; - $dsn =~ /.+\/(.+?)$/ and $db = $1; - $dsn =~ /:\/\/(\w+):/ and $user = $1; - $dsn =~ /:\/\/\w+:(\w+)@/ and $pass = $1; - print "$db $user $pass\n"; +#if ($v eq 'DATABASE_TYPE' and /^\s*DATABASE_TYPE\s*=\s*(\w+)/) { +# print "$1\n"; +# exit; +#} + +# word split +if ($v eq 'DATABASE_DSN' and /^\s*DATABASE_DSN\s*=\s*"?([\w:\/@]+)/) { + my $result = ''; + my $dsn = $1; + $dsn =~ /^(.+?):\/\// and $result .= "$1 "; # backend + $dsn =~ /.+\/(.+?)$/ and $result .= "$1 "; # database: everything after the last slash + $dsn =~ /:\/\/(\w+):/ and $result .= "$1 "; # username (optional) + $dsn =~ /:\/\/\w+:(\w+)@/ and $result .= "$1 "; # password (optional) + print "$result\n"; exit; } +if ($v ne 'DATABASE_DSN') { + if (/^\s*$v\s*=\s*"?([^;]+)$/) { + print "$1\n"; + exit; + } +} -- 2.45.0