#!/bin/bash

# Custom firmware modifications

# Directories:
#  ./firmware	- untared firmware
#  ./filesystem	- unpacked filesystem squashfs
#  ./kernel	- unpacked kernel & hidden kernel squashfs

all() {
	dummy=0
}

all_no_freetz() {
	local freetz_base patches_scripts

	freetz_base=$(dirname "$0")
	patches_scripts="${freetz_base}/patches/scripts"

	# source freetz-helper-functions and freetz .config
	source "${freetz_base}/tools/freetz_functions"
	source "${freetz_base}/tools/freetz_patch"
	source "${freetz_base}/.config"

	# run telefon daemon in in-house mode, needed for
	# - /var/flash/calllog processing
	# - telnet-on-/off phone codes support
	# - automatic telnet start
	source "${patches_scripts}/114-run_telefon_in_inhouse_mode.sh"

	# restore telnet support, the user still needs to activate it via the phone code (#96*7*)
	ln -sf ../../bin/busybox ./filesystem/usr/sbin/telnetd

	# the following "mods" could (and should) be controlled used the Freetz menuconfig system
	# i.e. enable the corresponding option in Freetz menuconfig system, otherwise the patches
	# below won't do anything

	# enforce urlader settings, useful on boxes with bootloader version >=1.3179 (7490) resp. >=1.3229 (7580)
	source "${patches_scripts}/101-enforce_urlader-settings.sh"

	# hardcode branding in rc.conf (an alternative to the enforce-urlader-settings patch above)
	source "${patches_scripts}/101-enforce_branding_via_rc.conf.sh"

	# restore debug.cfg support
	source "${patches_scripts}/114-debug_cfg_support.sh"

	# patch away / hide "vom Hersteller nicht unterstützte Änderungen"
	source "${patches_scripts}/195-patch_webmenu_signed.sh"

	# restore volume counter support, 7412 only
	source "${patches_scripts}/241-restore_vol_counter.sh"

	# add modfs boot-manager
	source "${patches_scripts}/800-modfs_boot_manager.sh"

	# unhide Annex selection in Fritz!OS web-if
	source "${patches_scripts}/801-modfs_annex_selection.sh"

	# add support for sending multi-page faxes
	source "${patches_scripts}/802-modfs_multipage_fax.sh"
}

clean() {
	dummy=0
}

case "$1" in
	""|all)
		all
		;;
	all_no_freetz)
		all_no_freetz
		;;
	clean)
		clean
		;;
	*)
		echo "Usage: $0 {all|clean}" 1>&2
		exit 1
		;;
esac

exit 0
