Skip to content
Snippets Groups Projects
Unverified Commit 3ad0ef00 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

EHN: use .config for makefile and patches

parent fb2aaf4d
No related branches found
No related tags found
No related merge requests found
...@@ -84,5 +84,5 @@ for opt in $OPTIONS; do ...@@ -84,5 +84,5 @@ for opt in $OPTIONS; do
esc_dollar=${esc_hash//\$/'$$'} esc_dollar=${esc_hash//\$/'$$'}
esc_dq=${esc_dollar//\"/\\\"} esc_dq=${esc_dollar//\"/\\\"}
esc_sq=${esc_dq//\'/\\\'} esc_sq=${esc_dq//\'/\\\'}
echo "$opt=$esc_sq" >> .config echo "$opt=\"$esc_sq\"" >> .config
done done
...@@ -23,21 +23,30 @@ ...@@ -23,21 +23,30 @@
SHELL=/bin/bash SHELL=/bin/bash
include .config include .config
M_MYSQL_USER=$(patsubst "%", %, $(MYSQL_USER))
M_MYSQL_USER_PASSWORD=$(patsubst "%", %, $(MYSQL_USER_PASSWORD))
M_LOGIN_PATH=$(patsubst "%", %, $(LOGIN_PATH))
M_DATABASE_NAME=$(patsubst "%", %, $(DATABASE_NAME))
M_DATABASE_USER_HOST_LIST=$(patsubst "%", %, $(DATABASE_USER_HOST_LIST))
M_DATABASE_USER=$(patsubst "%", %, $(DATABASE_USER))
M_MYSQL_CMD=$(patsubst "%", %, $(MYSQL_CMD))
M_MYSQLDUMP_CMD=$(patsubst "%", %, $(MYSQLDUMP_CMD))
M_MYSQLADMIN_CMD=$(patsubst "%", %, $(MYSQLADMIN_CMD))
INSTALL_SQL_FILE=db_2_0.sql INSTALL_SQL_FILE=db_2_0.sql
ifdef LOGIN_PATH ifdef LOGIN_PATH
MYSQL_CONNECTION=--login-path=$(LOGIN_PATH) M_MYSQL_CONNECTION=--login-path=$(M_LOGIN_PATH)
else else
MYSQL_CONNECTION=--user="$(MYSQL_USER)" --password="$(MYSQL_USER_PASSWORD)" M_MYSQL_CONNECTION=--user="$(M_MYSQL_USER)" --password="$(M_MYSQL_USER_PASSWORD)"
endif endif
.PHONY: test-connection .PHONY: test-connection
test-connection: test-connection:
@$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "select 0;" $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -e "select 0;"
.PHONY: upgrade .PHONY: upgrade
upgrade: upgrade:
@cd patches; ./applyPatches.sh $(MYSQL_CONNECTION) --database=$(DATABASE_NAME) @cd patches; ./applyPatches.sh $(M_MYSQL_CONNECTION) --database=$(M_DATABASE_NAME)
.PHONY: install .PHONY: install
install: _install _grant upgrade install: _install _grant upgrade
...@@ -45,35 +54,35 @@ install: _install _grant upgrade ...@@ -45,35 +54,35 @@ install: _install _grant upgrade
.PHONY: _install .PHONY: _install
_install: _install:
@if $(MAKE) _exists > /dev/null 2>&1; then \ @if $(MAKE) _exists > /dev/null 2>&1; then \
printf "\n\nA database with with the name \"$(DATABASE_NAME)\" does already exist.\nCall 'make drop-$(DATABASE_NAME)' to delete that database or reconfigure with './configure'.\n"; \ printf "\n\nA database with with the name \"$(M_DATABASE_NAME)\" does already exist.\nCall 'make drop-$(M_DATABASE_NAME)' to delete that database or reconfigure with './configure'.\n"; \
exit 1; \ exit 1; \
else sed 's/db_2_0/$(DATABASE_NAME)/g' $(INSTALL_SQL_FILE) | $(MYSQL_CMD) $(MYSQL_CONNECTION); fi else sed 's/db_2_0/$(M_DATABASE_NAME)/g' $(INSTALL_SQL_FILE) | $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION); fi
comma:=, comma:=,
.PHONY: _grant .PHONY: _grant
_grant: _grant:
@for host in $(subst $(comma), ,$(DATABASE_USER_HOST_LIST)); do \ @for host in $(subst $(comma), ,$(M_DATABASE_USER_HOST_LIST)); do \
( $(MYSQL_CMD) $(MYSQL_CONNECTION) -e "SELECT COUNT(*) FROM mysql.user WHERE user='$(DATABASE_USER)' AND host=\"$$host\";" | grep 0 ) || ( echo "The user '$(DATABASE_USER)@$$host' is already in the database. Please use another user or delete her. E.g. with 'mysql -u $(MYSQL_USER) -p -e \"DROP USER $(DATABASE_USER)@$$host;\"'" ; exit 1 ) ; \ ( $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -e "SELECT COUNT(*) FROM mysql.user WHERE user='$(M_DATABASE_USER)' AND host=\"$$host\";" | grep 0 ) || ( echo "The user '$(M_DATABASE_USER)@$$host' is already in the database. Please use another user or delete her. E.g. with 'mysql -u $(M_MYSQL_USER) -p -e \"DROP USER $(M_DATABASE_USER)@$$host;\"'" ; exit 1 ) ; \
done done
@while true; do \ @while true; do \
printf "\n Please enter the password for $(DATABASE_USER): "; read -s password; \ printf "\n Please enter the password for $(M_DATABASE_USER): "; read -s password; \
printf "\nPlease repeat the password for $(DATABASE_USER): "; read -s password2; \ printf "\nPlease repeat the password for $(M_DATABASE_USER): "; read -s password2; \
if [ "$$password" != "$$password2" ]; then printf "\n\nThe passwords didn't match. Try again." ; else break ; fi; \ if [ "$$password" != "$$password2" ]; then printf "\n\nThe passwords didn't match. Try again." ; else break ; fi; \
done ; \ done ; \
echo "" ; \ echo "" ; \
for host in $(subst $(comma), ,$(DATABASE_USER_HOST_LIST)); do \ for host in $(subst $(comma), ,$(M_DATABASE_USER_HOST_LIST)); do \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "CREATE USER IF NOT EXISTS '$(DATABASE_USER)'@'$$host' identified by '$$password';" ; \ $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -e "CREATE USER IF NOT EXISTS '$(M_DATABASE_USER)'@'$$host' identified by '$$password';" ; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT USAGE ON *.* TO '$(DATABASE_USER)'@'$$host';"; \ $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -e "GRANT USAGE ON *.* TO '$(M_DATABASE_USER)'@'$$host';"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT ALL PRIVILEGES ON *.* TO '$(DATABASE_USER)'@'$$host' WITH GRANT OPTION;"; \ $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -e "GRANT ALL PRIVILEGES ON *.* TO '$(M_DATABASE_USER)'@'$$host' WITH GRANT OPTION;"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT EXECUTE ON *.* TO '$(DATABASE_USER)'@'$$host';"; \ $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -e "GRANT EXECUTE ON *.* TO '$(M_DATABASE_USER)'@'$$host';"; \
done done
.PHONY: drop-% .PHONY: drop-%
drop-%: drop-%:
@$(MYSQLADMIN_CMD) $(MYSQL_CONNECTION) -f drop $(patsubst drop-%,%,$@) @$(M_MYSQLADMIN_CMD) $(M_MYSQL_CONNECTION) -f drop $(patsubst drop-%,%,$@)
.PHONY: _exists .PHONY: _exists
_exists: _exists:
@if $(MYSQL_CMD) $(MYSQL_CONNECTION) -D "$(DATABASE_NAME)" -e "show tables;" > /dev/null 2>&1 ; then \ @if $(M_MYSQL_CMD) $(M_MYSQL_CONNECTION) -D "$(M_DATABASE_NAME)" -e "show tables;" > /dev/null 2>&1 ; then \
echo "$(DATABASE_NAME) does exist." ; exit 0 ; \ echo "$(M_DATABASE_NAME) does exist." ; exit 0 ; \
else echo "$(DATABASE_NAME) does not exist." ; exit 1; fi else echo "$(M_DATABASE_NAME) does not exist." ; exit 1; fi
...@@ -37,7 +37,7 @@ fi ...@@ -37,7 +37,7 @@ fi
mysql_execute "CREATE FUNCTION CaosDBVersion() RETURNS VARCHAR(255) DETERMINISTIC RETURN 'v2.0.0';" mysql_execute "CREATE FUNCTION CaosDBVersion() RETURNS VARCHAR(255) DETERMINISTIC RETURN 'v2.0.0';"
# create transaction_log table with new schema # create transaction_log table with new schema
mysql $MYSQL_CONNECTION -D $DATABASE -e "CREATE TABLE new_transaction_log ( mysql_execute "CREATE TABLE new_transaction_log (
transaction VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'TRANSACTION.', transaction VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'TRANSACTION.',
user_id INT UNSIGNED NOT NULL COMMENT 'User.', user_id INT UNSIGNED NOT NULL COMMENT 'User.',
date INT NOT NULL COMMENT 'Date of transaction.', date INT NOT NULL COMMENT 'Date of transaction.',
...@@ -48,19 +48,19 @@ mysql $MYSQL_CONNECTION -D $DATABASE -e "CREATE TABLE new_transaction_log ( ...@@ -48,19 +48,19 @@ mysql $MYSQL_CONNECTION -D $DATABASE -e "CREATE TABLE new_transaction_log (
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;" ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"
# copy from old transaction_log # copy from old transaction_log
mysql $MYSQL_CONNECTION -D $DATABASE -e "INSERT INTO new_transaction_log SELECT transaction, user_id, (Year(timestamp) * 10000 + Month(timestamp) * 100 + Day(timestamp)) as date, ((Hour(timestamp) + 1) * 10000 + (Minute(timestamp) + 1)*100 + Second(timestamp) + 1 ) as time, NULL as ns, entity_id from transaction_log"; mysql_execute "INSERT INTO new_transaction_log SELECT transaction, user_id, (Year(timestamp) * 10000 + Month(timestamp) * 100 + Day(timestamp)) as date, ((Hour(timestamp) + 1) * 10000 + (Minute(timestamp) + 1)*100 + Second(timestamp) + 1 ) as time, NULL as ns, entity_id from transaction_log";
# check if both have same number of rows # check if both have same number of rows
ROWSTEST=$(mysql $MYSQL_CONNECTION -D $DATABASE -e "SELECT count(*) from new_transaction_log into @newRows; SELECT count(*) from transaction_log into @oldRows; Select (@newRows = @oldRows) as test" | sed -e ':a;N;$!ba;s/[^01]//g') ROWSTEST=$(mysql_execute "SELECT count(*) from new_transaction_log into @newRows; SELECT count(*) from transaction_log into @oldRows; Select (@newRows = @oldRows) as test" | sed -e ':a;N;$!ba;s/[^01]//g')
if [ 0 -eq "$ROWSTEST" ]; then if [ 0 -eq "$ROWSTEST" ]; then
failure "The rows do not match. Something went wrong." failure "The rows do not match. Something went wrong."
fi fi
# delete old transaction_log # delete old transaction_log
mysql $MYSQL_CONNECTION -D $DATABASE -e "DROP TABLE transaction_log;" mysql_execute "DROP TABLE transaction_log;"
# rename new_transaction_log to transaction_log # rename new_transaction_log to transaction_log
mysql $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE new_transaction_log RENAME TO transaction_log" mysql_execute "ALTER TABLE new_transaction_log RENAME TO transaction_log"
success success
...@@ -22,12 +22,11 @@ ...@@ -22,12 +22,11 @@
# #
#header for patch scripts #header for patch scripts
if test -e ../.config ; then if test -e ../.config ; then
source ../.config . ../.config
fi fi
if test -e .config ; then if test -e .config ; then
source .config . .config
fi fi
USAGE="$1 --database=DATABASE_NAME [ --login-path=LOGIN_PATH | --user=USER [ --password=PASSWORD ] ]\n\n"
CMD_OPTIONS="options:\n\n-h, --help\n\tShow brief help.\n-l LOGIN_PATH, --login-path=LOGIN_PATH\n\tA login-path for the mysql connection (see 'man mysql' and 'man mysql-config-editor').\n-u USER, --user=USER\n\tA mysql user.\n-p PASSWORD, --password=PASSWORD\n\tThe password for the mysql user.\n" CMD_OPTIONS="options:\n\n-h, --help\n\tShow brief help.\n-l LOGIN_PATH, --login-path=LOGIN_PATH\n\tA login-path for the mysql connection (see 'man mysql' and 'man mysql-config-editor').\n-u USER, --user=USER\n\tA mysql user.\n-p PASSWORD, --password=PASSWORD\n\tThe password for the mysql user.\n"
set -e set -e
...@@ -189,3 +188,5 @@ function mysql_execute { ...@@ -189,3 +188,5 @@ function mysql_execute {
function redo_table { function redo_table {
$MYSQL_CMD $MYSQL_CONNECTION -D $DATABASE_NAME < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql $MYSQL_CMD $MYSQL_CONNECTION -D $DATABASE_NAME < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql
} }
echo "$MYSQL_CMD $MYSQL_CONNECTION -D $DATABASE_NAME -e $1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment