#!/bin/bash ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*- ##### Author: Travis Cross codename="sid" modulelist_opt="" modules_add="" use_sysvinit="" while getopts "c:m:p:v" o; do case "$o" in c) codename="$OPTARG" ;; m) modulelist_opt="$OPTARG" ;; p) modules_add="$modules_add $OPTARG";; v) use_sysvinit="true";; esac done shift $(($OPTIND-1)) if [ x${use_sysvinit} = x ]; then case "$codename" in wheezy|trusty|utopic|xenial) use_sysvinit="true";; *) use_sysvinit="false";; esac fi mod_dir="../src/mod" conf_dir="../conf" lang_dir="../conf/vanilla/lang" fs_description="FreeSWITCH is a scalable open source cross-platform telephony platform designed to route and interconnect popular communication protocols using audio, video, text or any other form of media." mod_build_depends="." mod_depends="." mod_recommends="." mod_suggests="." supported_debian_distros="wheezy jessie stretch sid" supported_ubuntu_distros="trusty utopic xenial" supported_distros="$supported_debian_distros $supported_ubuntu_distros" avoid_mods=( applications/mod_sms_flowroute applications/mod_limit applications/mod_mongo applications/mod_mp4 applications/mod_mp4v2 applications/mod_osp applications/mod_rad_auth applications/mod_skel applications/mod_cluechoo asr_tts/mod_cepstral codecs/mod_com_g729 codecs/mod_ilbc codecs/mod_openh264 codecs/mod_siren codecs/mod_skel_codec endpoints/mod_gsmopen endpoints/mod_h323 endpoints/mod_khomp endpoints/mod_opal endpoints/mod_reference endpoints/mod_unicall event_handlers/mod_smpp formats/mod_webm sdk/autotools xml_int/mod_xml_ldap xml_int/mod_xml_radius ) avoid_mods_sid=( directories/mod_ldap ) avoid_mods_jessie=( directories/mod_ldap ) avoid_mods_wheezy=( event_handlers/mod_amqp languages/mod_java languages/mod_managed applications/mod_av applications/mod_cv applications/mod_hiredis formats/mod_shout applications/mod_sonar applications/mod_soundtouch formats/mod_vlc ) avoid_mods_trusty=( event_handlers/mod_amqp codecs/mod_sangoma_codec ) avoid_mods_utopic=( directories/mod_ldap codecs/mod_sangoma_codec ) avoid_mods_xenial=( event_handlers/mod_ldap event_handlers/mod_amqp codecs/mod_sangoma_codec asr_tts/mod_flite ) manual_pkgs=( freeswitch-all freeswitch libfreeswitch1 freeswitch-meta-bare freeswitch-meta-default freeswitch-meta-vanilla freeswitch-meta-sorbet freeswitch-meta-all freeswitch-meta-codecs freeswitch-meta-conf freeswitch-meta-lang freeswitch-meta-mod-say freeswitch-all-dbg freeswitch-dbg libfreeswitch1-dbg libfreeswitch-dev freeswitch-doc freeswitch-lang freeswitch-timezones ) if [ ${use_sysvinit} = "true" ]; then manual_pkgs=( "${manual_pkgs[@]}" "freeswitch-sysvinit" ) else manual_pkgs=( "${manual_pkgs[@]}" "freeswitch-systemd" ) fi err () { echo "$0 error: $1" >&2 exit 1 } xread () { local xIFS="$IFS" IFS='' read $@ local ret=$? IFS="$xIFS" return $ret } intersperse () { local sep="$1" awk " BEGIN { first=1; sep=\"${sep}\"; }"' /.*/ { if (first == 0) { printf "%s%s", sep, $0; } else { printf "%s", $0; } first=0; } END { printf "\n"; }' } postfix () { local px="$1" awk " BEGIN { px=\"${px}\"; }"' /.*/ { printf "%s%s\n", $0, px; }' } avoid_mod_filter () { local x="avoid_mods_$codename[@]" local -a mods=("${avoid_mods[@]}" "${!x}") for x in "${mods[@]}"; do if [ "$1" = "$x" ]; then [ "$2" = "show" ] && echo "excluding module $x" >&2 return 1 fi done return 0 } modconf_filter () { while xread l; do if [ "$1" = "$l" ]; then [ "$2" = "show" ] && echo "including module $l" >&2 return 0 fi done < modules.conf return 1 } mod_filter () { if test -f modules.conf; then modconf_filter $@ else avoid_mod_filter $@ fi } mod_filter_show () { mod_filter "$1" show } map_fs_modules () { local filterfn="$1" percatfns="$2" permodfns="$3" for x in $mod_dir/*; do test -d $x || continue test ! ${x##*/} = legacy || continue category=${x##*/} category_path=$x for f in $percatfns; do $f; done for y in $x/*; do module_name=${y##*/} module_path=$y module=$category/$module_name if $filterfn $category/$module; then [ -f ${y}/module ] && . ${y}/module for f in $permodfns; do $f; done fi unset module_name module_path module done unset category category_path done } map_modules () { local filterfn="$1" percatfns="$2" permodfns="$3" for x in $parse_dir/*; do test -d $x || continue category=${x##*/} category_path=$x for f in $percatfns; do $f; done for y in $x/*; do test -f $y || continue module=${y##*/} module_path=$y $filterfn $category/$module || continue module="" category="" module_name="" section="" description="" long_description="" build_depends="" depends="" recommends="" suggests="" distro_conflicts="" distro_vars="" for x in $supported_distros; do distro_vars="$distro_vars build_depends_$x" eval build_depends_$x="" done . $y [ -n "$description" ] || description="$module_name" [ -n "$long_description" ] || description="Adds ${module_name}." for f in $permodfns; do $f; done unset \ module module_name module_path \ section description long_description \ build_depends depends recommends suggests \ distro_conflicts $distro_vars done unset category category_path done } map_confs () { local fs="$1" for x in $conf_dir/*; do test ! -d $x && continue conf=${x##*/} conf_dir=$x for f in $fs; do $f; done unset conf conf_dir done } map_langs () { local fs="$1" for x in $lang_dir/*; do test ! -d $x && continue lang=${x##*/} lang_dir=$x for f in $fs; do $f; done unset lang lang_dir done } map_pkgs () { local fsx="$1" for x in "${manual_pkgs[@]}"; do $fsx $x done map_pkgs_confs () { $fsx "freeswitch-conf-${conf//_/-}"; } map_confs map_pkgs_confs map_pkgs_langs () { $fsx "freeswitch-lang-${lang//_/-}"; } map_langs map_pkgs_langs map_pkgs_mods () { $fsx "freeswitch-${module//_/-}" $fsx "freeswitch-${module//_/-}-dbg"; } map_modules map_pkgs_mods } list_pkgs () { list_pkgs_thunk () { printf '%s\n' "$1"; } map_pkgs list_pkgs_thunk } print_source_control () { local libtool_dep="libtool, libtool-bin" case "$codename" in wheezy|trusty) libtool_dep="libtool" ;; esac local debhelper_dep="debhelper (>= 8.0.0)" if [ ${use_sysvinit} = "false" ]; then debhelper_dep=${debhelper_dep}", dh-systemd" fi cat < Build-Depends: # for debian ${debhelper_dep}, # bootstrapping automake (>= 1.9), autoconf, ${libtool_dep}, # core build dpkg-dev (>= 1.15.8.12), gcc (>= 4:4.4.5), g++ (>= 4:4.4.5), libc6-dev (>= 2.11.3), make (>= 3.81), libpcre3-dev, libedit-dev (>= 2.11), libsqlite3-dev, wget, pkg-config, yasm, # core codecs libogg-dev, libspeex-dev, libspeexdsp-dev, # configure options libssl-dev, unixodbc-dev, libpq-dev, libncurses5-dev, libjpeg62-turbo-dev | libjpeg-turbo8-dev | libjpeg62-dev | libjpeg8-dev, python-dev, python-all-dev, python-support (>= 0.90) | dh-python, erlang-dev, # documentation doxygen, # for APR (not essential for build) uuid-dev, libexpat1-dev, libgdbm-dev, libdb-dev, # used by many modules libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl-dev, bison, zlib1g-dev, # module build-depends $(debian_wrap "${mod_build_depends}") Standards-Version: 3.9.3 Homepage: https://freeswitch.org/ Vcs-Git: https://freeswitch.org/stash/scm/fs/freeswitch.git Vcs-Browser: https://freeswitch.org/stash/projects/FS/repos/freeswitch/browse EOF } print_core_control () { cat <= 3.0-6), sysvinit | sysvinit-utils Conflicts: freeswitch-init Provides: freeswitch-init Description: FreeSWITCH SysV init script $(debian_wrap "${fs_description}") . This package contains the SysV init script for FreeSWITCH. EOF else cat <> control } gencontrol_per_cat () { (echo "## mod/$category"; echo) >> control } geninstall_per_mod () { local f=freeswitch-${module_name//_/-}.install (print_edit_warning; print_mod_install "$module_name") > $f test -f $f.tmpl && cat $f.tmpl >> $f } genoverrides_per_mod () { local f=freeswitch-${module_name//_/-}.lintian-overrides (print_edit_warning; print_mod_overrides freeswitch-${module_name//_/-}) > $f test -f $f.tmpl && cat $f.tmpl >> $f } genmodulesconf () { genmodules_per_cat () { echo "## $category"; } genmodules_per_mod () { echo "$module"; } print_edit_warning map_modules 'mod_filter' 'genmodules_per_cat' 'genmodules_per_mod' } genconf () { print_conf_control >> control local p=freeswitch-conf-${conf//_/-} local f=$p.install (print_edit_warning; print_conf_install) > $f test -f $f.tmpl && cat $f.tmpl >> $f local f=$p.lintian-overrides (print_edit_warning; print_conf_overrides "$p") > $f test -f $f.tmpl && cat $f.tmpl >> $f } genlang () { print_lang_control >> control local p=freeswitch-lang-${lang//_/-} local f=$p.install (print_edit_warning; print_lang_install) > $f test -f $f.tmpl && cat $f.tmpl >> $f local f=$p.lintian-overrides (print_edit_warning; print_lang_overrides "$p") > $f test -f $f.tmpl && cat $f.tmpl >> $f } geninstall_perl () { local archlib eval `perl -V:archlib` echo $archlib/ESL.\* >libesl-perl.install echo $archlib/ESL/\*.\* >>libesl-perl.install } accumulate_mod_deps () { local x="" # build-depends if [ -n "$(eval echo \$build_depends_$codename)" ]; then x="$(eval echo \$build_depends_$codename)" else x="${build_depends}"; fi if [ -n "$x" ]; then if [ ! "$mod_build_depends" = "." ]; then mod_build_depends="${mod_build_depends}, ${x}" else mod_build_depends="${x}"; fi; fi # depends if [ -n "$(eval echo \$depends_$codename)" ]; then x="$(eval echo \$depends_$codename)" else x="${depends}"; fi x="$(echo "$x" | sed 's/, \?/\n/g' | grep -v '^freeswitch' | tr '\n' ',' | sed -e 's/,$//' -e 's/,/, /g')" if [ -n "$x" ]; then if [ ! "$mod_depends" = "." ]; then mod_depends="${mod_depends}, ${x}" else mod_depends="${x}"; fi; fi # recommends if [ -n "$(eval echo \$recommends_$codename)" ]; then x="$(eval echo \$recommends_$codename)" else x="${recommends}"; fi x="$(echo "$x" | sed 's/, \?/\n/g' | grep -v '^freeswitch' | tr '\n' ',' | sed -e 's/,$//' -e 's/,/, /g')" if [ -n "$x" ]; then if [ ! "$mod_recommends" = "." ]; then mod_recommends="${mod_recommends}, ${x}" else mod_recommends="${x}"; fi; fi # suggests if [ -n "$(eval echo \$suggests_$codename)" ]; then x="$(eval echo \$suggests_$codename)" else x="${suggests}"; fi x="$(echo "$x" | sed 's/, \?/\n/g' | grep -v '^freeswitch' | tr '\n' ',' | sed -e 's/,$//' -e 's/,/, /g')" if [ -n "$x" ]; then if [ ! "$mod_suggests" = "." ]; then mod_suggests="${mod_suggests}, ${x}" else mod_suggests="${x}"; fi; fi } genmodctl_new_mod () { grep -e "^Module: ${module}$" control-modules >/dev/null && return 0 cat </dev/null && return 0 cat < control-modules.preparse local category="" local module_name="" rm -rf $parse_dir while xread l; do if [ -z "$l" ]; then # is newline continue fi local header="${l%%:*}" local value="${l#*: }" if [ "$header" = "Module" ]; then category="${value%%/*}" module_name="${value#*/}" mkdir -p $parse_dir/$category (echo "module=$(var_escape "$value")"; \ echo "category=$(var_escape "$category")"; \ echo "module_name=$(var_escape "$module_name")"; \ ) >> $parse_dir/$category/$module_name else ([ -n "$category" ] && [ -n "$module_name" ]) \ || err "unexpected header $header" local var_name="$(echo "$header" | sed -e 's/-/_/g' | tr '[A-Z]' '[a-z]')" echo "${var_name}=$(var_escape "$value")" >> $parse_dir/$category/$module_name fi done < control-modules.preparse } debian_wrap () { local fl=true echo "$1" | fold -s -w 69 | while xread l; do local v="$(echo "$l" | sed -e 's/ *$//g')" if $fl; then fl=false echo "$v" else echo " $v" fi done } genmodctl_cat () { (echo "## mod/$category"; echo) } genmodctl_mod () { echo "Module: $module" [ -n "$section" ] && echo "Section: $section" echo "Description: $description" echo "$long_description" | fold -s -w 69 | while xread l; do local v="$(echo "$l" | sed -e 's/ *$//g')" echo " $v" done [ -n "$build_depends" ] && debian_wrap "Build-Depends: $build_depends" for x in $supported_distros; do [ -n "$(eval echo \$build_depends_$x)" ] \ && debian_wrap "Build-Depends-$x: $(eval echo \$build_depends_$x)" done [ -n "$depends" ] && debian_wrap "Depends: $depends" [ -n "$reccomends" ] && debian_wrap "Recommends: $recommends" [ -n "$suggests" ] && debian_wrap "Suggests: $suggests" [ -n "$distro_conflicts" ] && debian_wrap "Distro-Conflicts: $distro_conflicts" echo } set_modules_non_dfsg () { local len=${#avoid_mods} for ((i=0; i/dev/null; then printf '%s\n' "$x" >> $of fi done fi } echo "Bootstrapping debian/ for ${codename}" >&2 echo >&2 echo "Please wait, this takes a few seconds..." >&2 test -z "$modulelist_opt" || set_modules_${modulelist_opt/-/_} test -z "$modules_add" || unavoid_modules "$modules_add" echo "Adding any new modules to control-modules..." >&2 parse_dir=control-modules.parse map_fs_modules ':' 'genmodctl_new_cat' 'genmodctl_new_mod' >> control-modules echo "Parsing control-modules..." >&2 parse_mod_control echo "Displaying includes/excludes..." >&2 map_modules 'mod_filter_show' '' '' echo "Generating modules_.conf..." >&2 genmodulesconf > modules_.conf echo "Generating control-modules.gen as sanity check..." >&2 (echo "# -*- mode:debian-control -*-"; \ echo "##### Author: Travis Cross "; echo; \ map_modules ':' 'genmodctl_cat' 'genmodctl_mod' \ ) > control-modules.gen echo "Accumulating dependencies from modules..." >&2 map_modules 'mod_filter' '' 'accumulate_mod_deps' echo "Generating debian/..." >&2 > control (print_edit_warning; print_source_control; print_core_control) >> control echo "Generating debian/ (conf)..." >&2 (echo "### conf"; echo) >> control map_confs 'genconf' echo "Generating debian/ (lang)..." >&2 (echo "### lang"; echo) >> control map_langs 'genlang' echo "Generating debian/ (modules)..." >&2 (echo "### modules"; echo) >> control map_modules "mod_filter" \ "gencontrol_per_cat" \ "gencontrol_per_mod geninstall_per_mod genoverrides_per_mod" geninstall_perl if [ ${use_sysvinit} = "true" ]; then echo -n freeswitch-sysvinit >freeswitch-init.provided_by else echo -n freeswitch-systemd >freeswitch-init.provided_by fi echo "Generating additional lintian overrides..." >&2 grep -e '^Package:' control | while xread l; do m="${l#*: }" f=$m.lintian-overrides [ -s $f ] || print_edit_warning >> $f if ! grep -e 'package-has-long-file-name' $f >/dev/null; then print_long_filename_override "$m" >> $f fi if ! grep -e 'new-package-should-close-itp-bug' $f >/dev/null; then print_itp_override "$m" >> $f fi done for p in freeswitch libfreeswitch1; do f=$p.lintian-overrides [ -s $f ] || print_edit_warning >> $f print_gpl_openssl_override "$p" >> $f done echo "Cleaning up..." >&2 rm -f control-modules.preparse rm -rf control-modules.parse diff control-modules control-modules.gen >/dev/null && rm -f control-modules.gen echo "Done bootstrapping debian/" >&2 touch .stamp-bootstrap