Select Git revision
future-features.md
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
makefile 3.00 KiB
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
SHELL=/bin/bash
include .config
INSTALL_SQL_FILE=db_2_0.sql
ifdef LOGIN_PATH
MYSQL_CONNECTION=--login-path=$(LOGIN_PATH)
else
MYSQL_CONNECTION=--user="$(MYSQL_USER)" --password="$(MYSQL_USER_PASSWORD)"
endif
.PHONY: test-connection
test-connection:
@$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "select 0;"
.PHONY: upgrade
upgrade:
@cd patches; ./applyPatches.sh $(MYSQL_CONNECTION) --database=$(DATABASE_NAME)
.PHONY: install
install: _install _grant upgrade
.PHONY: _install
_install:
@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"; \
exit 1; \
else sed 's/db_2_0/$(DATABASE_NAME)/g' $(INSTALL_SQL_FILE) | $(MYSQL_CMD) $(MYSQL_CONNECTION); fi
comma:=,
.PHONY: _grant
_grant:
@while true; do \
printf "\n Please enter the password for $(DATABASE_USER): "; read -s password; \
printf "\nPlease repeat the password for $(DATABASE_USER): "; read -s password2; \
if [ "$$password" != "$$password2" ]; then printf "\n\nThe passwords didn't match. Try again." ; else break ; fi; \
done ; \
printf "\n$$password\n" ; \
for host in $(subst $(comma), ,$(DATABASE_USER_HOST_LIST)); do \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "CREATE USER '$(DATABASE_USER)'@'$$host' identified by '$$password';"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT USAGE ON *.* TO '$(DATABASE_USER)'@'$$host';"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT ALL PRIVILEGES ON *.* TO '$(DATABASE_USER)'@'$$host' WITH GRANT OPTION;"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT EXECUTE ON *.* TO '$(DATABASE_USER)'@'$$host';"; \
done
.PHONY: drop-%
drop-%:
@for host in $(subst $(comma), ,$(DATABASE_USER_HOST_LIST)); do \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "DROP USER '$(DATABASE_USER)'@'$$host';" || true ; \
done
@$(MYSQLADMIN_CMD) $(MYSQL_CONNECTION) -f drop $(patsubst drop-%,%,$@)
.PHONY: _exists
_exists:
@if $(MYSQL_CMD) $(MYSQL_CONNECTION) -D "$(DATABASE_NAME)" -e "show tables;" > /dev/null 2>&1 ; then \
echo "$(DATABASE_NAME) does exist." ; exit 0 ; \
else echo "$(DATABASE_NAME) does not exist." ; exit 1; fi