#!/bin/bash #linkbox_remove #removes links within a box on the left linkbox_remove() { local linkbox_file="${HTML_LANG_MOD_DIR}/templates/menu_page_head.html" local linkbox_row=$(cat $linkbox_file |nl| sed -n "s/^ *\([0-9]*\).*menu.write_menu('$1')$/\1/p") modsed "$((linkbox_row-6)),$((linkbox_row+9))d" $linkbox_file } #quickstart_remove #removes links within quickstart.html (top menu) quickstart_remove() { for file in \ usr/www/all/templates/quickstart.html \ usr/www.myfritz/all/home/fritzinfo.lua \ usr/www.myfritz/all/home/fritzinfo_mobile.lua \ ; do [ ! -e "${FILESYSTEM_MOD_DIR}/$file" ] && continue modsed \ "/^box.out.*m_link_bold.*href.get.*'[\/]*$1[\/]*'.*box.tohtml.*/d" \ "${FILESYSTEM_MOD_DIR}/$file" done } #menulua_remove #removes links within menu_data.lua (left menu) menulua_remove() { modsed \ "/{* *page = \".*\/$1.lua\",/d" \ "${HTML_LANG_MOD_DIR}/menus/menu_data.lua" } #menu2html_remove #removes links within menu2_home.html (left menu, pre lua) menu2html_remove() { modsed \ "/LMenuitemTop/{N;N;/^
  • \n.*<.a>\n<.li>$/d}" \ "${HTML_SPEC_MOD_DIR}/menus/menu2_home.html" } #homelua_disable #easily disable functions within home.lua by returning nothing homelua_disable() { modsed \ "s/^\(function $1\)()$/\1()\nreturn ''\nend\n\1_()/" \ "${HTML_LANG_MOD_DIR}/home/home.lua" \ " $1_(" } # ------------------------------------------------------------------- # isFreetzType # ------------------------------------------------------------------- # Author: Alexander Kriegisch (http://scrum-master.de) # ------------------------------------------------------------------- # Simplify logical OR comparisons with Freetz box types or types of # lab firmwares etc. # # Example: The following construct... # # if [ "$FREETZ_TYPE_5010" == "y" ] || \ # [ "$FREETZ_TYPE_5050" == "y" ] || \ # [ "$FREETZ_TYPE_7050" == "y" ] || \ # [ "$FREETZ_TYPE_7140" == "y" ] || \ # [ "$FREETZ_TYPE_7141" == "y" ] || \ # [ "$FREETZ_TYPE_7150" == "y" ] || \ # [ "$FREETZ_TYPE_7170" == "y" ] # then # # ... can now be abbreviated by: # # if isFreetzType 5010 5050 7050 7140 7141 7150 7170; then # # This is also possible: # # if isFreetzType 7170 7240 7270 && isFreetzType LABOR_AIO; then # ------------------------------------------------------------------- isFreetzType() { while [ $# -gt 0 ]; do varname=`echo "\\$FREETZ_TYPE"_$1` [ "`eval echo $varname`" == "y" ] && return 0 shift done return 1 } # little helper function used by many patches (maybe this should be sourced out) rm_files() { for file in "$@"; do echo2 "rm -rf $file" rm -rf $file done } #modsed [grep-expression-to-verify-sed] #should be used instead of sed -i -e in patch scripts modsed() { [ $# -le 1 ] && error 1 "modsed failed, not enough parameters." if [ -f "$2" ]; then echo2 "patching $2" sed -i -e "$1" "$2" if [ $# -ge 3 ]; then grep -q "$3" "$2" || error 1 "modsed failed editing $2" fi else if [ $# -lt 3 ]; then warn2 "$2 not found, skipping." else error 1 "$2 not found, aborting." fi fi } # General printing (info messages, warnings and errors) echoX() { # If an error occurs because a parameter starting with "-" (but none of the # predefined letters below) is detected, we heuristically stop option parsing, # assuming the caller wants to print a string like "----" or "-blah", # accidentally starting with a dash/hyphen. In most cases this will work, but # there are a few exceptions: Parameters with additional arguments (here "-i" # and "-p", see below) will lead to conflicts. E.g. if the caller wants to # print "-index" it will be interpreted as "-i ndex" ("ndex" will be used as # an indentation string). If you want to print something like this you have # to play by getopts's rules, i.e. you can use an additional separator "--" # in between real paramaters and function arguments, like this: # echoX -bc -- "-index" # echo2 -c -p "NOTE: " -- "-print this" local indent no_indent prefix no_newline bold unbold colour uncolour OPTIND=0 # Leading colon means: silent error handling, no getopts errors on console while getopts :i:p:lnbc opt; do case $opt in i) indent="$OPTARG" ;; l) no_indent=1 ;; p) prefix="$OPTARG" ;; n) no_newline=-n ;; b) bold='\033[1m'; unbold='\033[0m' ;; c) colour='\033[33m'; uncolour='\033[m' ;; # ANSI brown/yellow ?) break ;; # unknown parameter -> stop option parsing esac done shift $((OPTIND-1)) [ $no_indent ] && indent= echo -e $no_newline "${indent}${bold}${colour}${prefix}$*${uncolour}${unbold}" } # If the verbosity level is undefined, probably this script has been called # directly by a professional user, so let's give him all the details. : ${FREETZ_VERBOSITY_LEVEL:=2} # Two spaces per indentation level seems to be a sensible default [ ! "$L2" ] && L0= && L1=" " && L2=" " # Verbosity-level-dependent, indented printing echo0() { [ "$FREETZ_VERBOSITY_LEVEL" -ge 0 ] && echoX -i "$L0" "$@"; } echo1() { [ "$FREETZ_VERBOSITY_LEVEL" -ge 1 ] && echoX -i "$L1" "$@"; } echo2() { [ "$FREETZ_VERBOSITY_LEVEL" -ge 2 ] && echoX -i "$L2" "$@"; } # Warning message warn() { echoX -c -p "WARNING: " "$@" >&2; } warn0() { [ "$FREETZ_VERBOSITY_LEVEL" -ge 0 ] && warn "$@"; } warn1() { [ "$FREETZ_VERBOSITY_LEVEL" -ge 1 ] && warn "$@"; } warn2() { [ "$FREETZ_VERBOSITY_LEVEL" -ge 2 ] && warn "$@"; } # Error message + exit with specified error code error() { local err_no=$1 [ $err_no -eq 0 ] && return shift # Coloured (can be combined with bold) echoX -c -p "ERROR: " "$@" >&2 exit $err_no } modunsqfs() { local STATUS if [ "$FREETZ_VERBOSITY_LEVEL" -ge 2 ]; then "$UNSQUASHFS" "$UNSQUASHFS_OPTIONS" -dest "$1" "$2" 2>&1 | grep -v "^$" | sed -e "s/^/${L2}/g" STATUS=${PIPESTATUS[0]} else "$UNSQUASHFS" "$UNSQUASHFS_OPTIONS" -dest "$1" "$2" > /dev/null STATUS=$? fi if [ $STATUS -gt 0 ]; then error 1 "modunsqfs: Error in $2" fi } modunsqfs_lzma() { local STATUS if [ "$FREETZ_VERBOSITY_LEVEL" -ge 2 ]; then "$UNSQUASHFS_LZMA" "$UNSQUASHFS_OPTIONS" -dest "$1" "$2" 2>&1 | grep -v "^$" | sed -e "s/^/${L2}/g" STATUS=${PIPESTATUS[0]} else "$UNSQUASHFS_LZMA" "$UNSQUASHFS_OPTIONS" -dest "$1" "$2" > /dev/null STATUS=$? fi if [ $STATUS -gt 0 ]; then error 1 "modunsqfs: Error in $2" fi } modlangsubst() { # modlangsubst # Substitutes all $(lang de:"Deutscher Text" en:"English text" ...) occurrences # in with of the corresponding :"" section. s='[\t\r\n ]' val='\(\([^"\\]*\(\\.\)*\)*\)' entry="\w\+:\"${val}\"" LC_ALL="" LC_CTYPE=C sed -i -e " :a s/\$(lang\(${s}\+${entry}\)*${s}\+${1}:\"${val}\"\(${s}\+${entry}\)*${s}*)/\$(lang:\"\5\")/g s/\$(lang\(${s}\+${entry}\)*${s}*)/*** error: language[${1}] not available ***/g :n s/\$(lang:\"\(\([^\"\\]\+\)\|[\\]\(.\)\)${val}\")/\2\3\$(lang:\"\4\")/g tn s/\$(lang:\"\")//g /\$(lang\(${s}\|\$\)/ {N; ba} " "$2" } modlangconf() { # modlangconf # Get of a { } section in s='[\t\r\n ]' sed -n -e ":n;N;\$!bn;s/^.*${1}${s}\+{${s}*\([^}]*\)${s}*}.*$/\1/p" "$2" } modlang() { # modlang case $1 in /*) conffile=$1 ;; *) conffile="$PWD/$1" ;; esac avail="$(modlangconf "languages" "$conffile")" default="$FREETZ_LANG_STRING $(modlangconf "default" "$conffile") en de $avail" lang="" for i in $default; do for j in $avail; do if [ "$i" == "$j" ]; then lang="$j" break 2 fi done done if [ -z "$lang" ]; then error 1 "no language available" fi [ "$lang" == "$FREETZ_LANG_STRING" ] || \ echo "NOTICE: language $FREETZ_LANG_STRING not available; $lang chosen." 1>&2 ( if ! cd "${2}"; then warn "modlang: $2 does not exist" return fi local dot_exclude="$(echo $FREETZ_BASE_DIR/$1 | sed 's/language$/exclude/')" for i in $(modlangconf "files" "$conffile"); do if [ -e "${i}" ]; then modlangsubst "$lang" "${i}" else do_excluded=n while read l; do echo $i | grep -q $l && do_excluded=y done 2>/dev/null < "$dot_exclude" [ "$do_excluded" != "y" ] && warn "modlang: ${2}/${i} not found" fi done ) } # list of static packages, sorted by start level static_packages() { if [ -r "$STATIC_PACKAGES_FILE" ]; then sort "$STATIC_PACKAGES_FILE" \ | sed -e 's/^[\ \t]*//' -e 's/[\ \t]*$//' -e 's/^S[0-9]*//' \ | grep -v '^#' | grep -v '^$' fi } static_addons() { if [ -r "$STATIC_ADDON_FILE" ]; then cat "$STATIC_ADDON_FILE" \ | sed -e 's/^[\ \t]*//' -e 's/[\ \t]*$//' \ | grep -v '^#' | grep -v '^$' fi } pkg_name() { local name=$1 echo "$name" | sed -r -e 's/-(alpha|beta|rc|(un)?stable|.)[0-9]*$//i' -e 's/-[0-9a-f]{10}$//' -e 's/-[0-9][^-]*$//' -e 's/-cgi$//' } # # Returns "(NEEDED)"-entries for all binaries/libraries supplied # getNeededEntries() { "${FREETZ_BASE_DIR}"/toolchain/target/bin/${FREETZ_TARGET_CROSS}readelf -d "$@" 2>/dev/null \ | grep "(NEEDED)" | sed -r -e 's,^[^[]* [[]([^]]*)[]].*$,\1,' | sort -u } # # Returns if $1 is a "(NEEDED)"-entry of one of the binaries/libraries supplied after $1 # $1 might also be an extended grep-pattern, e.g. (libcapi|libfax) # isNeededEntry() { [ $# -lt 2 ] && error 1 "isNeededEntry failed, not enough parameters." local neededPattern="$1"; shift local neededEntries=$(getNeededEntries "$@") grep -E -q "$neededPattern" 2>/dev/null <<< "$neededEntries" }