#!/bin/sh

# A script to help you select the modules you want to build for Asterisk.
# You'll need to further edit it.

# Copyright 2018, Tzafrir Cohen <tzafrir.cohen@xorcom.com>
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2 or any later version.
# You can find a copy of the GNU General Public License version 2 at
# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html

# Filter functions:
# They take a list of modules from menuselect's output and only leave in
# the ones you want.

apps() {
	./menuselect/menuselect --list-category MENUSELECT_APPS | awk '{printf "--disable %s\n",$2}' | egrep -v app_'(dial|voicemail)'
}

cdr() {
	./menuselect/menuselect --list-category MENUSELECT_CDR | awk '{printf "--disable %s\n",$2}' | grep -v cdr_csv
}

cel() {
	./menuselect/menuselect --list-category MENUSELECT_CEL | awk '{printf "--disable %s\n",$2}' | grep -v cel_custom
}

channels() {
	./menuselect/menuselect --list-category MENUSELECT_CHANNELS | awk '{printf "--disable %s\n",$2}' | egrep -v 'chan_(bridge_media|sip)'
}

codecs() {
	./menuselect/menuselect --list-category MENUSELECT_CODECS | awk '{printf "--disable %s\n",$2}' | egrep -v 'codec_(a_mu|alaw|ulaw)'
}

formats() {
	./menuselect/menuselect --list-category MENUSELECT_FORMATS | awk '{printf "--disable %s\n",$2}' | egrep -v 'format_wav'
}

funcs() {
	./menuselect/menuselect --list-category MENUSELECT_FUNCS | awk '{printf "--disable %s\n",$2}' | egrep -v 'func_callerid'
}

pbx() {
	./menuselect/menuselect --list-category MENUSELECT_PBX | awk '{printf "--disable %s\n",$2}' | egrep -v 'pbx_config'
}

res() {
	./menuselect/menuselect --list-category MENUSELECT_RES | awk '{printf "--disable %s\n",$2}' | egrep -v 'res_(stasis|sorcery|clioriginate)'
}

# Some categories are completely disabled.
# For others, the filter functions provide the list of modules

./menuselect/menuselect \
	--disable-category MENUSELECT_ADDONS \
	--disable-category MENUSELECT_UTILS \
	--disable-category MENUSELECT_CORE_SOUNDS \
	--disable-category MENUSELECT_EXTRA_SOUNDS \
	--disable-category MENUSELECT_MOH \
	`apps` \
	`cdr` \
	`cel` \
	`channels` \
	`codecs` \
	`formats` \
	`funcs` \
	`pbx` \
	`res` \
	#
