###############################################################################
#                                                                             #
# IPFire.org - A linux based firewall                                         #
# Copyright (C) 2007-2018  IPFire Team  <info@ipfire.org>                     #
#                                                                             #
# This program is free software: you can redistribute it and/or modify        #
# it under the terms of the GNU 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 General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
#                                                                             #
###############################################################################

###############################################################################
# Definitions
###############################################################################

include Config

THISAPP     = core-updates
TARGET      = $(DIR_INFO)/$(THISAPP)

PROG        = core-upgrade
VER         = $(VERSION)
PAK_VER	    = $(CORE)

SUMMARY     = IPFire Core Update $(CORE)

META_FILENAME = meta-$(PROG)-$(CORE)

###############################################################################
# Top-level Rules
###############################################################################

check :

download :

b2 :

###############################################################################
# Installation Details
###############################################################################

.PHONY:
install:
	@rm -rf $(ARCHIVE_DIR) && mkdir -pv $(ARCHIVE_DIR) $(ARCHIVE_TMP)

	# Generate the archive and write out the rootfile
	$(call COPY_FILES,$(DIR_SRC)/config/rootfiles/core/$(CORE)/filelists,$(ARCHIVE_TMP),,$(ARCHIVE_DIR)/ROOTFILES,$(DIR_SRC)/config/rootfiles/core/$(CORE)/exclude)

	# Create the archive
	$(call COMPRESS_XZ,$(ARCHIVE_TMP),$(ARCHIVE_DIR)/files.tar.xz)

	# Remove the temporary files
	rm -rf $(ARCHIVE_TMP)

	# Install update scripts
	cd $(DIR_SRC) && install -v -m 744 config/rootfiles/core/$(CORE)/update.sh \
		$(ARCHIVE_DIR)/update.sh

	# Replace the kernel version
	sed -e "s/xxxKVERxxx/$(KVER)/g" -i $(ARCHIVE_DIR)/update.sh

	# Create the package
	$(call CREATE_PACKAGE,$(ARCHIVE_DIR),$(PACKAGES_DIR)/$(PACKAGE_FILENAME))

	# Write the meta file
	$(call CREATE_META,$(PACKAGES_DIR)/$(PACKAGE_FILENAME),$(PACKAGES_DIR)/$(META_FILENAME))

	# Cleanup
	@rm -rf $(ARCHIVE_DIR)
