Skip to content
Snippets Groups Projects
Select Git revision
  • 686fe963ac464d673f87302c8a9132cc4a5f1d95
  • main default protected
  • f-standalone-docker
  • f-fix-patch-8.1.0
  • dev protected
  • f-linkahead-rename
  • f-real-id
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-filesystem-main
  • f-name
  • keep_changes
  • f-permission-checks-2
  • f-mysql8-tests
  • f-retrieve-history
  • t-distinct-parents
  • v8.1.0
  • v8.0.0
  • v7.0.2
  • v7.0.1
  • v7.0.0
  • v6.0.1
  • v6.0.0
  • v5.0.0
  • v4.1.0
  • v4.0.0
  • v3.0
  • v2.0.30
31 results

makefile

Blame
  • 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