#!/bin/bash # # Script to modify AVM FRITZ!Box firmware images (Freetz) # # Copyright (C) 2005-2006 Daniel Eiband # Copyright (C) 2006-2011 by the Freetz developers (http://freetz.org) # # Licensed under the GPL v2, see the file COPYING in this tarball. # This script is based on Christian Volkmann's fritzbox mod-0.57. # Legacy URL: http://www.ip-phone-forum.de/showthread.php?t=65894 # # Special Thanks to Andreas Buehmann, Christian Volkmann, Enrik Berkhan, # SpeedyBZ and all members on ip-phone-forum.de who contributed to this mod SHELL=$BASH usage() { cat << 'EOF' Usage: fwmod [-u|-m|-p|-a] [-i ] [-d ] [] actions -u unpack firmware image -m modify previously unpacked image -p pack firmware image -a all: unpack, modify and pack firmware image (-u -m -p) input/output -i input file for configuration data (default: .config) -d build directory (default: .mod) original firmware name 2nd firmware name (e.g. for merging in web UI) EOF } # Print usage info to stdout (no error, just info) if [ $# -eq 0 ]; then usage exit 0 fi # If we are not running in a fakeroot context, provide one and re-run if [ $((FAKEROOTKEY)) -eq 0 ] || [ $UID -ne 0 ]; then "$(dirname "$0")/tools/build/bin/fakeroot" '--' "$0" "$@" exit $? fi L1=' ' L2=' ' BOLD=$(echo -e '\033[1m') NORM=$(echo -e '\033[0m') # Default values FREETZ_VERBOSITY_LEVEL=0 DOT_CONFIG="$(dirname "$0")/.config" CMDLINE_OPTS="umpad:i:" # Default config override? # NOTE: Both 'getopts' must have an identical argument list! while getopts "$CMDLINE_OPTS" opt; do if [ "$opt" == "i" ]; then DOT_CONFIG="$OPTARG" echo $DOT_CCONFIG fi done DO_UNPACK=0 DO_MOD=0 DO_PACK=0 DIR='' _OPT=0 # Reset command line option counter OPTIND=0 # Get other options besides '-i ' # NOTE: Both 'getopts' must have an identical argument list! while getopts "$CMDLINE_OPTS" opt; do case "$opt" in u) DO_UNPACK=1 _OPT=1 ;; m) DO_MOD=1 _OPT=1 ;; p) DO_PACK=1 _OPT=1 ;; a) DO_UNPACK=1 DO_MOD=1 DO_PACK=1 _OPT=1 ;; d) DIR="$OPTARG" ;; i) # Do nothing, DOT_CONFIG has been assigned already ;; *) usage >&2 exit 1 ;; esac done shift $(($OPTIND - 1)) if [ $# -ne 1 -a $# -ne 2 ]; then usage >&2 exit 1 fi if [ "$_OPT" -eq 0 ]; then DO_UNPACK=1 DO_MOD=1 DO_PACK=1 fi FIRMWARE="$1" FIRMWARE2="$2" BASE_DIR="$(dirname "$0")" if [ -z "$DIR" ]; then DIR="${FIRMWARE}.mod" fi ABS_BASE_DIR="$BASE_DIR" if [[ "$ABS_BASE_DIR" != /* ]]; then ABS_BASE_DIR="$(pwd)/$ABS_BASE_DIR" fi TOOLS_SUBDIR="tools" SOURCE_SUBDIR="source" FIRMWARE_SUBDIR="firmware" FILESYSTEM_SUBDIR="filesystem" AVMPLUGINS_SUBDIR="plugins.image" EXTERNAL_SUBDIR="external" KERNEL_SUBDIR="kernel" VARTAR_SUBDIR="var.tar" HTML_SUBDIR="usr/www" GRAPHICS_SUBDIR="graphics" KERNEL_IMAGE="var/tmp/kernel.image" AVMPLUGINS_FILE="var/tmp/plugins.update" RAW_KERNEL_FILE="kernel.raw" RAW_HIDDEN_FILE="kernelsquashfs.raw" VARTAR_FILE="var.tar" FINDSQUASHFS_TOOL="find-squashfs" TICHKSUM_TOOL="tichksum" RMTICHKSUM_TOOL="rmtichksum" MAKEDEVS_TOOL="makedevs" UNSQUASHFS_TOOL="unsquashfs3-lzma" EXTERNAL_TOOL="external" MKSQUASHFS_OPTIONS="-noappend -all-root -info" UNSQUASHFS_OPTIONS="-no-progress" TAR_TOOL="tar" TOOLS_DIR="${ABS_BASE_DIR}/${TOOLS_SUBDIR}" EXTERNAL="${TOOLS_DIR}/${EXTERNAL_TOOL}" UNSQUASHFS="${TOOLS_DIR}/${UNSQUASHFS_TOOL}" FINDSQUASHFS="${TOOLS_DIR}/${FINDSQUASHFS_TOOL}" MKSQUASHFS="${TOOLS_DIR}/${MKSQUASHFS_TOOL}" TICHKSUM="${TOOLS_DIR}/${TICHKSUM_TOOL}" RMTICHKSUM="${TOOLS_DIR}/${RMTICHKSUM_TOOL}" MAKEDEVS="${TOOLS_DIR}/${MAKEDEVS_TOOL}" MAKEDEVS_FILE="${TOOLS_DIR}/device_table.txt" TAR="${TOOLS_DIR}/${TAR_TOOL}" #temporarily use system tar to unpack avm images UNTAR="$(which tar)" PACKAGES_DIR_ROOT="${BASE_DIR}/packages" PATCHES_DIR="${BASE_DIR}/patches" ROOT_DIR="${BASE_DIR}/root" KERNEL_REP_DIR="${BASE_DIR}/kernel" ADDON_DIR="${BASE_DIR}/addon" GRAPHICS_DIR="${BASE_DIR}/${GRAPHICS_SUBDIR}" FAVICON_DIR="${GRAPHICS_DIR}/favicon" TAGGING_DIR="${GRAPHICS_DIR}/tagging" STATIC_PACKAGES_FILE="${BASE_DIR}/.static" DYNAMIC_PACKAGES_FILE="${BASE_DIR}/.dynamic" STATIC_ADDON_FILE="${ADDON_DIR}/static.pkg" DYNAMIC_ADDON_FILE="${ADDON_DIR}/dynamic.pkg" # Config file readable? if [ ! -r "$DOT_CONFIG" ]; then echo -e "ERROR: not configured" 1>&2 exit 1 fi # Load config . "$DOT_CONFIG" # After load config, needs FREETZ_TARGET_CROSS NM="${ABS_BASE_DIR}/toolchain/target/bin/${FREETZ_TARGET_CROSS}nm" STRIP="${ABS_BASE_DIR}/toolchain/target/bin/${FREETZ_TARGET_CROSS}strip" # ar7 (FON WLAN) and ohio (7170) modules dir is 2.6.13.1-ar7/ohio # ur8 (7270) and iks (7390) modules dir is 2.6.19.2 # ar9 (7320) modules dir is 2.6.28.10 MODULES_SUBDIR="lib/modules/${FREETZ_KERNEL_VERSION}" if [ "$FREETZ_KERNEL_VERSION" = "2.6.13.1" ]; then MODULES_SUBDIR="$MODULES_SUBDIR-${FREETZ_KERNEL_LAYOUT}" elif [ "$FREETZ_KERNEL_VERSION" = "2.6.28" ]; then MODULES_SUBDIR="${MODULES_SUBDIR}.10" fi if [ "$FREETZ_TARGET_ARCH_BE" == "y" ]; then MKSQUASHFS_OPTIONS+=" -be" else MKSQUASHFS_OPTIONS+=" -le" fi if [ "$FREETZ_KERNEL_VERSION_2_6_13_1" -a ! "$FREETZ_REPLACE_KERNEL" == "y" ]; then MKSQUASHFS_TOOL="mksquashfs-lzma" else MKSQUASHFS_TOOL="mksquashfs3-lzma" MKSQUASHFS_OPTIONS+=" -no-progress -no-exports -no-sparse" fi # Dot-include 'modpatch' shell function . "${TOOLS_DIR}/freetz_patch" # Dot-include some helper shell function (isFreetzType, rm_files) . "${TOOLS_DIR}/freetz_functions" if [ -z "$FIRMWARE" ]; then error 1 "no firmware filename supplied" fi # Does the firmware image exist ? if [ -n "$FIRMWARE" -a ! -r "$FIRMWARE" ]; then error 1 "firmware image $(basename "$FIRMWARE") not found" fi if [ -n "$FIRMWARE2" -a ! -r "$FIRMWARE2" ]; then error 1 "firmware image $(basename "$FIRMWARE2") not found" fi if [ ! -e "$DIR" ]; then mkdir -p "$DIR" fi ############################################ ## Unpack and unsquash the firmware image ## ############################################ ORG_DIR="${DIR}/original" FIRMWARE_DIR="${ORG_DIR}/${FIRMWARE_SUBDIR}" FILESYSTEM_DIR="${ORG_DIR}/${FILESYSTEM_SUBDIR}" KERNEL_DIR="${ORG_DIR}/${KERNEL_SUBDIR}" AVMPLUGINS_DIR="${KERNEL_DIR}/${AVMPLUGINS_SUBDIR}" VARTAR_DIR="${KERNEL_DIR}/${VARTAR_SUBDIR}" HTML_DIR="${FILESYSTEM_DIR}/${HTML_SUBDIR}" KERNEL="${FIRMWARE_DIR}/${KERNEL_IMAGE}" RAW_KERNEL="${KERNEL_DIR}/${RAW_KERNEL_FILE}" FILESYSTEM="${KERNEL_DIR}/${RAW_HIDDEN_FILE}" AVMPLUGINS="${FIRMWARE_DIR}/${AVMPLUGINS_FILE}" VARTAR="${FILESYSTEM_DIR}/${VARTAR_FILE}" if [ "$DO_UNPACK" -gt 0 ]; then echo "${BOLD}STEP 1: UNPACK${NORM}" rm -rf "$ORG_DIR" mkdir "$ORG_DIR" echo "unpacking firmware image" mkdir "$FIRMWARE_DIR" "$UNTAR" -xf "$FIRMWARE" -C "$FIRMWARE_DIR" || exit 1 # Do the images exist ? if [ ! -r "${FIRMWARE_DIR}/${KERNEL_IMAGE}" ]; then error 1 "cannot find kernel.image" fi # Do we have the tool ? if [ ! -x "$RMTICHKSUM" ]; then error 1 "cannot find the tool $RMTICHKSUM_TOOL" fi if [ ! -x "$UNSQUASHFS" ]; then error 1 "cannot find the tool $UNSQUASHFS_TOOL" fi if [ ! -x "$FINDSQUASHFS" ]; then error 1 "cannot find the very useful tool $FINDSQUASHFS_TOOL" fi "$RMTICHKSUM" -f "${FIRMWARE_DIR}/${KERNEL_IMAGE}" > /dev/null echo "splitting kernel image" mkdir "$KERNEL_DIR" ( cd "$KERNEL_DIR" && "${TOOLS_DIR}/${FINDSQUASHFS_TOOL}" "../${FIRMWARE_SUBDIR}/${KERNEL_IMAGE}" > /dev/null 2>&1 ) if [ ! -r "$RAW_KERNEL" -o ! -r "$FILESYSTEM" ]; then error 1 "kernel splitting failed" fi echo "unpacking filesystem image" modunsqfs "$FILESYSTEM_DIR" "$FILESYSTEM" if [ -r "$AVMPLUGINS" ]; then echo0 "unpacking AVM plugins" mkdir -p "$AVMPLUGINS_DIR" "$UNTAR" -xf "$AVMPLUGINS" -C "$AVMPLUGINS_DIR" || exit 1 for i in "${AVMPLUGINS_DIR}/var/"*.image; do AVMPLUGIN="${i##*/plugin-}" AVMPLUGIN="${AVMPLUGIN%\.image}" echo2 "$AVMPLUGIN image" modunsqfs "$AVMPLUGINS_DIR/plugin-${AVMPLUGIN}" "$i" > /dev/null done chmod -R +w "$AVMPLUGINS_DIR" fi if [ ! -r "$FILESYSTEM_DIR/var" ]; then error 1 "could not unpack the filesystem image" fi if [ ! -r "$VARTAR" ]; then error 1 "no var.tar found" fi echo "unpacking var.tar" mkdir "$VARTAR_DIR" "$UNTAR" -xpf "$VARTAR" -C "$VARTAR_DIR" || exit 1 # Unpacking second firmware image if [ -n "$FIRMWARE2" ]; then echo0 "unpacking tk image" rm -rf "${DIR}/.tk" "$0" -u -d "${DIR}/.tk" "$FIRMWARE2" > /dev/null fi touch "${DIR}/.unpacked" echo "done." echo fi ############################################### # Lets copy and modify the unpacked firmware ## ############################################### MOD_DIR="${DIR}/modified" FIRMWARE_MOD_DIR="${MOD_DIR}/${FIRMWARE_SUBDIR}" FILESYSTEM_MOD_DIR="${MOD_DIR}/${FILESYSTEM_SUBDIR}" EXTERNAL_MOD_DIR="${MOD_DIR}/${EXTERNAL_SUBDIR}" KERNEL_MOD_DIR="${MOD_DIR}/${KERNEL_SUBDIR}" AVMPLUGINS_MOD_DIR="${KERNEL_MOD_DIR}/${AVMPLUGINS_SUBDIR}" AVMPLUGINS_FILESYSTEM_MOD_DIR="${FILESYSTEM_MOD_DIR}/usr/share/avmplugins" VARTAR_MOD_DIR="${KERNEL_MOD_DIR}/${VARTAR_SUBDIR}" KERNEL_MOD="${FIRMWARE_MOD_DIR}/${KERNEL_IMAGE}" RAW_KERNEL_MOD="${KERNEL_MOD_DIR}/${RAW_KERNEL_FILE}" FILESYSTEM_MOD="${KERNEL_MOD_DIR}/${RAW_HIDDEN_FILE}" VARTAR_MOD="${FILESYSTEM_MOD_DIR}/${VARTAR_FILE}" PACKAGES_DIR="${PACKAGES_DIR_ROOT}/target-${FREETZ_TARGET_ARCH}_uClibc-${FREETZ_TARGET_UCLIBC_VERSION}" TARGET_SPECIFIC_ROOT_DIR="${PACKAGES_DIR}/root" HTML_MOD_DIR="${FILESYSTEM_MOD_DIR}/${HTML_SUBDIR}" # HTML_LANG_MOD_DIR can't be defined here MODULES_DIR="${FILESYSTEM_MOD_DIR}/${MODULES_SUBDIR}" if [ "$DO_MOD" -gt 0 ]; then echo "${BOLD}STEP 2: MODIFY${NORM}" # Check if firmware is unpacked if [ ! -r "${DIR}/.unpacked" ]; then error 1 "firmware image has to be unpacked before modifying" fi rm -rf "$MOD_DIR" rm -f "${DIR}/.modified" # Copy the unpacked directory mkdir -p "$MOD_DIR" [ "$FREETZ_HAS_UDEV" == y ] || exclude_dev="--exclude=./filesystem/dev" "$TAR" -c -C "$ORG_DIR" $exclude_dev . | "$TAR" -x -C "$MOD_DIR" || exit 1 # Fix some permissions chmod -R u+w "$FILESYSTEM_MOD_DIR" find "${FILESYSTEM_MOD_DIR}" "${VARTAR_MOD_DIR}" -type d -exec chmod 755 {} '+' # Give all users write permissions to /var/tmp to allow it to be used as a temp-directory. # Set sticky bit to prevent users from deleting/renaming files they are not the owners of. # NB: The permissions set are the regular temp-directory permissions on Unix-like systems. chmod 1777 "${VARTAR_MOD_DIR}/var/tmp" echo0 -n "applying symlinks, deleting additional webinterfaces in:" oems="$(grep 'for i in avm' "${FIRMWARE_MOD_DIR}/var/install" | head -n 1 | sed -e 's/^.*for i in\(.*\); do.*$/\1/')" for webdir in ${FILESYSTEM_MOD_DIR}/usr/www ${FILESYSTEM_MOD_DIR}/usr/www.nas; do if [ -d ${webdir}/avm* ]; then echo0 -n -l " ${webdir#${FILESYSTEM_MOD_DIR}/}" mv ${webdir}/avm* ${webdir}/all for i in $oems; do rm -rf ${webdir}/$i ln -s all ${webdir}/$i done fi done echo0 -l echo0 "applying patches" echo1 "applying patches (${FREETZ_TYPE_PREFIX}-${FREETZ_TYPE_LANGUAGE})" # Apply patches if [ ! -d "${PATCHES_DIR}/${FREETZ_TYPE_PREFIX}" ]; then error 1 "missing ${PATCHES_DIR}/${FREETZ_TYPE_PREFIX}" fi # Execute version specific patch scripts for i in "${PATCHES_DIR}/${FREETZ_TYPE_PREFIX}/${FREETZ_TYPE_LANGUAGE}/"*.sh \ "${PATCHES_DIR}/${FREETZ_TYPE_PREFIX}/"*.sh; do [ -r "$i" ] || continue echo2 "applying patch file $i" . $i done # Now we are in place to check html directory for i in all/en all; do if [ -d "${HTML_MOD_DIR}/$i" ]; then HTML_LANG_MOD_DIR="${HTML_MOD_DIR}/$i" break fi done [ -z "$HTML_LANG_MOD_DIR" ] && error 1 "No HTML directory given." # Apply (general, version specific, language specific) patches shopt -s nullglob for i in "${PATCHES_DIR}/"*.patch \ "${PATCHES_DIR}/${FREETZ_TYPE_PREFIX}/"*.patch \ "${PATCHES_DIR}/${FREETZ_TYPE_PREFIX}/${FREETZ_TYPE_LANGUAGE}/"*.patch do modpatch "$FILESYSTEM_MOD_DIR" "$i" done shopt -u nullglob echo1 "creating symlinks /tmp, /mod and /home" rm -rf "$FILESYSTEM_MOD_DIR"/tmp ln -s var/{tmp,mod} "$FILESYSTEM_MOD_DIR"/ ln -s var/mod/home "$FILESYSTEM_MOD_DIR"/ echo1 "creating /mnt and /opt" mkdir -p "$FILESYSTEM_MOD_DIR"/mnt # 7390 labor preview: /opt is symlink to /var/InternerSpeicher/opt [ ! -L "$FILESYSTEM_MOD_DIR"/opt ] && mkdir -p "$FILESYSTEM_MOD_DIR"/opt # Set version and options SUBVERSION_FILE="${BASE_DIR}/.version" FIRMWAREVERSION_FILE="${FILESYSTEM_MOD_DIR}/etc/.version" FIRMWAREVERSION="$(cat $FIRMWAREVERSION_FILE)" PACKAGES_LIST_FILE="${BASE_DIR}/.packages" if [ ! -r "$SUBVERSION_FILE" ]; then error 1 "cannot determine version" fi if [ "$FREETZ_DEVELOPER_VERSION_STRING" == "y" ]; then # be compatible: older versions of svnversion need WC_PATH if SVN_VERSION="$(svnversion . | tr ":" "_")"; then [ "${SVN_VERSION:0:6}" == "export" ] && SVN_VERSION="" [ "$SVN_VERSION" != "" ] && SVN_VERSION="-$SVN_VERSION" fi fi SUBVERSION="$(cat $SUBVERSION_FILE)${SVN_VERSION}" #delete .packages file rm -f "${PACKAGES_LIST_FILE}" for i in $(set|grep -i "^FREETZ_REMOVE_.*=y$"|sed -e "s/^.\{14\}//;s/=.*//"|tr [A-Z] [a-z]|sort); do OPTIONS+=" -$i" done OPTIONS_ADD=" +busybox" for i in $(set|grep -i "^FREETZ_PATCH_.*=y$"|sed -e "s/^.\{13\}//;s/=.*//"|tr [A-Z] [a-z]); do OPTIONS_ADD+=" +$i" done for pkg in $(static_packages) $(static_addons); do OPTIONS_ADD+=" +$pkg" echo "$pkg" >> "${PACKAGES_LIST_FILE}" done if [ "$FREETZ_REPLACE_KERNEL" == "y" ] && [ "$FWMOD_PATCH_TEST" != "y" ]; then KERNEL_SUBVERSION_FILE="${KERNEL_REP_DIR}/.version-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}" if [ ! -r "$KERNEL_SUBVERSION_FILE" ]; then error 1 "cannot determine kernel version" fi KERNEL_SUBVERSION="$(cat $KERNEL_SUBVERSION_FILE)" OPTIONS_ADD+=" +kernel ($KERNEL_SUBVERSION)" fi for i in $(echo ${OPTIONS_ADD}|sed -e's: +:\n+:g'|sort); do OPTIONS+=" $i" done echo1 "setting freetz-version '${SUBVERSION}'" echo "$SUBVERSION" > "${FILESYSTEM_MOD_DIR}/etc/.freetz-version" if [ "$FREETZ_SUBVERSION_STRING" == "y" ]; then echo1 "setting subversion '${SUBVERSION}'" echo "$SUBVERSION" > "${FILESYSTEM_MOD_DIR}/etc/.subversion" sed -i -e "s/\export\ FIRMWARE_SUBVERSION=.*\$/export\ FIRMWARE_SUBVERSION=\"${SUBVERSION}\"/g" "${FILESYSTEM_MOD_DIR}/etc/version" if [ ! -e "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.init" ]; then AVM_SUBVERSION=`grep "SUBVERSION=" "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.conf" | sed -e "s/[^-0-9]//g"` sed -i -e "s/SUBVERSION=\"$AVM_SUBVERSION\"/SUBVERSION=\"$SUBVERSION\"/" "${FILESYSTEM_MOD_DIR}/etc/init.d/rc.conf" fi fi sed -i -e "s//${SUBVERSION}/g" "${FILESYSTEM_MOD_DIR}/usr/bin/system_status" sed -i -e "s//${OPTIONS}/g" "${FILESYSTEM_MOD_DIR}/usr/bin/system_status" # Execute general patch scripts for i in "${PATCHES_DIR}/"*.sh; do [ -r "$i" ] || continue echo2 "applying patch file $i" . $i done # stop execution if in patch test mode if [ "$FWMOD_PATCH_TEST" == "y" ]; then echo "${BOLD}Patch test mode: exiting without error.${NORM}" exit fi # remove oems [ "$FREETZ_VERBOSITY_LEVEL" -ge 1 ] && echo -n "${L1}removing oem:" oem_removed=0 oem_kept=0 oem_list= oems=$(grep -E 'for i in (avm|tcom)' "${FIRMWARE_MOD_DIR}/var/install" | head -n 1 | sed -e 's/^.*for i in\(.*\); do.*$/\1/') if [ -z "$oems" ]; then error 1 "no oems found" fi ln -sf /usr/www/cgi-bin/freetz_status "${HTML_LANG_MOD_DIR}/cgi-bin/freetz_status" [ "$FREETZ_PACKAGE_WOL_CGI" == "y" ] && ln -sf /usr/www/cgi-bin/freetz_wol "${HTML_LANG_MOD_DIR}/cgi-bin/freetz_wol" for i in $oems; do if [ "$(eval "echo \"\$FREETZ_REMOVE_BRANDING_${i}\"")" == "y" ]; then [ "$FREETZ_VERBOSITY_LEVEL" -ge 1 ] && echo -n " $i" # delete webinterface symlinks otherwise user can choose branding in status.cgi rm -rf "${FILESYSTEM_MOD_DIR}/usr/www/${i}" rm -rf "${FILESYSTEM_MOD_DIR}/usr/www.nas/${i}" find ${FILESYSTEM_MOD_DIR}/etc/default.* -name "*${i}*" | xargs rm -rf oem_removed=1 else oem_list+=" $i" oem_kept=1 fi done if [ "$FREETZ_VERBOSITY_LEVEL" -ge 1 ]; then [ "$oem_removed" -eq 0 ] && echo -n " none" echo fi if isFreetzType W501V; then oem_list="tcom avm" fi sed -i -r -e 's/for i in (avm|tcom).*; do/for i in '"$oem_list"' ; do/g' "${FIRMWARE_MOD_DIR}/var/install" if [ "$oem_kept" -eq 0 ]; then error 1 "please choose at least one OEM (branding) in menuconfig: AVM, 1&1, Freenet etc." fi # Copy selected avmplugins into the firmware if [ "$FREETZ_AVMPLUGINS_ENABLED" == "y" ]; then echo0 "installing AVM plugins" echo "#" > ${FILESYSTEM_MOD_DIR}/sbin/start_plugin.sh rm -rf ${FIRMWARE_MOD_DIR}/${AVMPLUGINS_FILE} mkdir "${AVMPLUGINS_FILESYSTEM_MOD_DIR}" for i in `find "${AVMPLUGINS_MOD_DIR}" -maxdepth 1 -type d -name var -prune -false , -type d -name "plugin-*" 2>/dev/null`; do AVMPLUGIN="${i##*plugin-}" if [ "$(eval "echo \"\$FREETZ_AVMPLUGINS_$(echo "$AVMPLUGIN" | tr [:lower:] [:upper:])\"")" == "y" ]; then echo2 "$AVMPLUGIN plugin" cp -a "${AVMPLUGINS_MOD_DIR}/plugin-${AVMPLUGIN}" "${AVMPLUGINS_FILESYSTEM_MOD_DIR}/plugin-${AVMPLUGIN}" ln -s "/usr/share/avmplugins/plugin-${AVMPLUGIN}" "${VARTAR_MOD_DIR}/var/plugin-${AVMPLUGIN}" for module in `cd "${AVMPLUGINS_FILESYSTEM_MOD_DIR}/plugin-${AVMPLUGIN}";find -type f -name "*.ko"`; do echo2 "moving ${module##*/} to standard modules dir" mv "${AVMPLUGINS_FILESYSTEM_MOD_DIR}/plugin-${AVMPLUGIN}/$module" "${FILESYSTEM_MOD_DIR}/$module" done fi done fi if [ "$FREETZ_INSTALL_BASE" == "y" ]; then echo "installing mod base" MOD_CRON="${VARTAR_MOD_DIR}/var/spool/cron/crontabs" MOD_ROOT="${VARTAR_MOD_DIR}/var/mod" # Remove symlink before creating directory rm -rf ${VARTAR_MOD_DIR}/var/spool mkdir -p "$MOD_CRON" mkdir -p "${MOD_ROOT}/pkg" "${MOD_ROOT}/home" "${MOD_ROOT}/lib" "${MOD_ROOT}/root" mkdir -p "${MOD_ROOT}/bin" "${MOD_ROOT}/sbin" mkdir -p "${MOD_ROOT}/var/cache" mkdir -p "${MOD_ROOT}/usr/bin" "${MOD_ROOT}/usr/sbin" "${MOD_ROOT}/usr/share" \ "${MOD_ROOT}/usr/lib" "${MOD_ROOT}/usr/lib/cgi-bin" "${MOD_ROOT}/usr/lib/freetz" mkdir -p "${MOD_ROOT}/etc/conf" "${MOD_ROOT}/etc/init.d" "${MOD_ROOT}/etc/reg" ln -s /tmp/flash/mod/.profile "${MOD_ROOT}/root/.profile" # AVM compatibility symlink ln -s ../sys "${VARTAR_MOD_DIR}/var/sysfs" echo "root:x:0:0:root:/mod/root:/bin/sh" > "${VARTAR_MOD_DIR}/var/tmp/passwd" echo 'root:$1$$zO6d3zi9DefdWLMB.OHaO.:12332:0:99999:7:::' > "${VARTAR_MOD_DIR}/var/tmp/shadow" echo "root:x:0:" > "${VARTAR_MOD_DIR}/var/tmp/group" echo "users:x:1:" >> "${VARTAR_MOD_DIR}/var/tmp/group" touch "${VARTAR_MOD_DIR}/var/tmp/ethers" touch "${VARTAR_MOD_DIR}/var/tmp/exports" touch "${VARTAR_MOD_DIR}/var/tmp/gshadow" chmod 644 "${VARTAR_MOD_DIR}/var/tmp/passwd" "${VARTAR_MOD_DIR}/var/tmp/group" chmod 600 "${VARTAR_MOD_DIR}/var/tmp/shadow" "${VARTAR_MOD_DIR}/var/tmp/gshadow" # Fix permissions set by AVM, in particular revoke write permissions for g- and o-users. chmod 644 "${VARTAR_MOD_DIR}/var/tmp/hosts" "${VARTAR_MOD_DIR}/var/tmp/resolv.conf" mkdir -p "${VARTAR_MOD_DIR}/var/tmp/onlinechanged" ln -s ../var/tmp/ethers "${FILESYSTEM_MOD_DIR}/etc/ethers" ln -s ../var/tmp/exports "${FILESYSTEM_MOD_DIR}/etc/exports" ln -s ../var/tmp/gshadow "${FILESYSTEM_MOD_DIR}/etc/gshadow" rm -f ${VARTAR_MOD_DIR}/var/*/.dummy echo1 "installing libs" for i in $(set | grep ^FREETZ_LIB_.*=y | grep -v ^FREETZ_LIB_STDCXXLIB); do found=0 conf=${i%%=*} [ "$conf" != "${conf%%_WITH_*}" ] && continue # skip suboptions bn=${conf#FREETZ_LIB_} fn=${bn//_/[-+._]} echo2 "$bn" for dn in lib usr/lib usr/lib/freetz usr/lib/xtables; do files=$(shopt -s nullglob; echo ${TARGET_SPECIFIC_ROOT_DIR}/$dn/$fn[-.]*so*) if [ -z "$files" ]; then continue; fi found=1 [ -d "${FILESYSTEM_MOD_DIR}/${dn}" ] || mkdir -p "${FILESYSTEM_MOD_DIR}/${dn}" cp -a $files "${FILESYSTEM_MOD_DIR}/${dn}/" done if [ "$found" = 0 ]; then warn "Library $bn selected, but no files found" fi done [ "$FREETZ_LIB_libuClibc" == "y" ] && cp -a "${TARGET_SPECIFIC_ROOT_DIR}/lib/libc.so.0" "${FILESYSTEM_MOD_DIR}/lib/" if [ "$FREETZ_SHARE_terminfo" == "y" ]; then echo1 "installing terminfos" for i in $(set | grep ^FREETZ_SHARE_terminfo_.*=y |grep -v '^FREETZ_SHARE_terminfo_showall=' ); do dn=usr/share/terminfo conf=${i%%=*} bn=${conf#FREETZ_SHARE_terminfo_} fn=$(echo "$bn" | sed 's/MINUS/-/g;s/PLUS/+/g;s/\DOT/./g') echo2 "$fn" fn="${fn:0:1}/$fn" file="${TARGET_SPECIFIC_ROOT_DIR}/$dn/$fn" if [ ! -e "$file" ]; then warn "Terminfo $bn selected, but no file found" continue; fi dest="${FILESYSTEM_MOD_DIR}/$dn/${fn:0:1}" [ -d "$dest" ] || mkdir -p "$dest" cp -a $file "$dest/" done fi else error 1 "installation of base system is mandatory" fi if [ "$FREETZ_REPLACE_BUSYBOX" == "y" ]; then echo0 "replacing busybox" echo1 "replacing busybox-${FREETZ_TARGET_REF}" if [ ! -r "${PACKAGES_DIR}/busybox/busybox-${FREETZ_TARGET_REF}" ]; then error 1 "cannot find busybox replacement" fi # Replace busybox cp -pf "${PACKAGES_DIR}/busybox/busybox-${FREETZ_TARGET_REF}" "${FILESYSTEM_MOD_DIR}/bin/busybox" echo1 "installing symlinks" if [ ! -r "${PACKAGES_DIR}/busybox/busybox-${FREETZ_TARGET_REF}.links" ]; then error 1 "cannot find busybox links" fi # Remove old busybox links # be compatible: do not use -delete (not found in older versions of find) find "$FILESYSTEM_MOD_DIR" \( -lname "busybox" -or -lname "*/busybox" \) -print0 | xargs -0 rm # Install new busybox links for link in $(cat "${PACKAGES_DIR}/busybox/busybox-${FREETZ_TARGET_REF}.links"); do LINK_DIR="$(dirname "$link")" LINK_NAME="$(basename "$link")" case "$LINK_DIR" in /) BUSYBOX_PATH="bin/busybox" ;; /bin) BUSYBOX_PATH="busybox" ;; /sbin) BUSYBOX_PATH="../bin/busybox" ;; /usr/bin|/usr/sbin) BUSYBOX_PATH="../../bin/busybox" ;; *) error 1 "unknown installation directory: $link" ;; esac ln -sf "$BUSYBOX_PATH" "${FILESYSTEM_MOD_DIR}${LINK_DIR}/$LINK_NAME" || error 1 "could not create link for $link" done || exit 1 else error 1 "installation of busybox replacement is mandatory" fi if [ "$FREETZ_REPLACE_KERNEL" == "y" ]; then echo0 "replacing kernel" if [ ! -r "${KERNEL_REP_DIR}/kernel-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}.bin" ]; then error 1 "can't find kernel for ref ${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}" fi echo1 "replacing kernel-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING} (${KERNEL_SUBVERSION})" cp "${KERNEL_REP_DIR}/kernel-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}.bin" "$RAW_KERNEL_MOD" fi echo0 "installing modules" for i in \ $( \ cd "${KERNEL_REP_DIR}/modules-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}" && \ find . -type d -name .svn -prune -false , -type f \( -name modules.dep -o -name "*.ko" \) \ ) do bn="$(basename "$i")" mod="${bn%\.ko}" if [ "$FREETZ_MODULES_ALL" = "y" -o "$(eval "echo \"\$FREETZ_MODULE_$(echo "$mod" | tr '\-+' '_x')\"")" == "y" ]; then echo2 "${bn}" dn="$(dirname "$i")" [ -d "${MODULES_DIR}/kernel/${dn}" ] || mkdir -p "${MODULES_DIR}/kernel/${dn}" cp -a "${KERNEL_REP_DIR}/modules-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}/${i}" "${MODULES_DIR}/kernel/${dn}/" fi done echo1 "generating modules.dep" NM=$NM ${TOOLS_SUBDIR}/depmod.pl -b "$MODULES_DIR" \ -F ${KERNEL_REP_DIR}/System-${FREETZ_KERNEL_LAYOUT}-${FREETZ_KERNEL_REF}-${FREETZ_AVM_VERSION_STRING}.map 2> /dev/null # add plugin kernel modules for 7270 if plugins are not enabled if [ "$FREETZ_TYPE_FON_WLAN_7270_V1" == "y" -a ! "$FREETZ_AVMPLUGINS_ENABLED" == "y" ]; then echo -e "kernel/drivers/net/rfcntl/rfcntl.ko: kernel/drivers/char/audio/avm_audio.ko\nkernel/drivers/char/audio/avm_audio.ko:\n" >> $MODULES_DIR/modules.dep fi echo0 "installing packages" for pkg in $(static_packages); do echo1 "${pkg}" pkg_name=$(pkg_name "$pkg") "$TAR" -c -C "${PACKAGES_DIR}/${pkg}/root" \ $( [ -r "${PACKAGES_DIR}/${pkg}/.exclude" ] \ && echo "--exclude-from=${PACKAGES_DIR}/${pkg}/.exclude" ) . | \ "$TAR" -x -C "$FILESYSTEM_MOD_DIR" || exit 1 [ -d "${PACKAGES_DIR}/${pkg}/${VARTAR_SUBDIR}" ] && \ $( "$TAR" -c -C "${PACKAGES_DIR}/${pkg}/${VARTAR_SUBDIR}" . | \ "$TAR" -x -C ${VARTAR_MOD_DIR} || exit 1 ) [ -r "${PACKAGES_DIR}/${pkg}/.language" ] && \ modlang "${PACKAGES_DIR}/${pkg}/.language" "${FILESYSTEM_MOD_DIR}" grep -q "^$pkg_name$" "${FILESYSTEM_MOD_DIR}/etc/static.pkg" >/dev/null 2>&1 || ( echo "$pkg_name" >> "${FILESYSTEM_MOD_DIR}/etc/static.pkg" ) done for pkg in $(static_addons); do echo1 "${pkg} (addon)" pkg_name=$(pkg_name "$pkg") if [ -e "${ADDON_DIR}/${pkg}/etc/init.d/rc.${pkg_name}" ]; then echo "NOTICE: addon '$pkg' is in old-style format (no language support)." 1>&2 "$TAR" -c -C "${ADDON_DIR}/${pkg}" . | "$TAR" -x -C "$FILESYSTEM_MOD_DIR" || exit 1 else "$TAR" -c -C "${ADDON_DIR}/${pkg}/root" \ $( [ -r "${ADDON_DIR}/${pkg}/.exclude" ] \ && echo "--exclude-from=${ADDON_DIR}/${pkg}/.exclude" \ ) . | \ "$TAR" -x -C "$FILESYSTEM_MOD_DIR" || exit 1 [ -d "${ADDON_DIR}/${pkg}/${VARTAR_SUBDIR}" ] && \ $( "$TAR" -c -C "${ADDON_DIR}/${pkg}/${VARTAR_SUBDIR}" . | \ "$TAR" -x -C ${VARTAR_MOD_DIR} || exit 1 ) [ -r "${ADDON_DIR}/${pkg}/.language" ] && \ modlang "${ADDON_DIR}/${pkg}/.language" "${FILESYSTEM_MOD_DIR}" fi grep -q "^$pkg_name$" "${FILESYSTEM_MOD_DIR}/etc/static.pkg" >/dev/null 2>&1 || ( echo "$pkg_name" >> "${FILESYSTEM_MOD_DIR}/etc/static.pkg" ) done if [ -x "${BASE_DIR}/fwmod_custom" ]; then echo "invoking custom script" # syntax check $SHELL -n "${BASE_DIR}/fwmod_custom" if [ $? -ne 0 ]; then error 1 "syntax error in custom script" fi ( cd "$MOD_DIR" && ../../fwmod_custom all ) || exit 1 if [ $? -ne 0 ]; then error 1 "custom script returned error" fi fi # Processing some options, must be done after base package is in place if [ "$FREETZ_INSTALL_BASE" == "y" ]; then echo0 "processing mod base options" # color scheme if [ "$FREETZ_STYLE" == "grey" ]; then echo1 "setting grey style as default" ln -s colorscheme-grey.css ${FILESYSTEM_MOD_DIR}/usr/share/style/colorscheme.css else echo1 "setting colored style as default" ln -s colorscheme-colored.css ${FILESYSTEM_MOD_DIR}/usr/share/style/colorscheme.css fi # favicon if [ "$FREETZ_FAVICON_STRING" != "none" ]; then echo1 "adding favicon(s) (${FREETZ_FAVICON_STRING})" cp "${FAVICON_DIR}/${FREETZ_FAVICON_STRING}/freetz.ico" "${FILESYSTEM_MOD_DIR}/usr/share/favicon.ico" ln -s "../share/favicon.ico" "${FILESYSTEM_MOD_DIR}/usr/mww/favicon.ico" if [ -e "${FAVICON_DIR}/${FREETZ_FAVICON_STRING}/box.ico" ]; then cp "${FAVICON_DIR}/${FREETZ_FAVICON_STRING}/box.ico" "${HTML_LANG_MOD_DIR}/html/favicon.ico" ln -fs "./html/favicon.ico" "${HTML_LANG_MOD_DIR}/favicon.ico" fi fi # security level echo1 "patching security level" sed -i -e "s/sec_level=1/sec_level=$FREETZ_SECURITY_LEVEL/g" ${FILESYSTEM_MOD_DIR}/usr/lib/libmodcgi.sh # external [ ! "$EXTERNAL_ENABLED" == "y" ] && echo1 "rc.external was not integrated into image" # freetz mount [ ! "$FREETZ_PATCH_FREETZMOUNT" == "y" ] && echo1 "libmodmount.sh was not integrated into image" # Box-Info [ "$FREETZ_REMOVE_BOX_INFO" == "y" ] && echo1 "Box-Info cgi was not integrated into image" # FREETZ-Info [ "$FREETZ_REMOVE_FREETZ_INFO" == "y" ] && echo1 "FREETZ-Info cgis were not integrated into image" # Packing .config into image if [ ! "$FREETZ_REMOVE_DOT_CONFIG" == "y" ]; then echo1 "integrating stripped .config file into image" dot_config_file="$MOD_DIR/filesystem/etc/.config" cat .config | sed -e "s/#.*//g;/^$/d" > "$dot_config_file" fi # tagging if [ "$FREETZ_TAGGING_STRING" != "none" ]; then echo1 "tagging avm webif (tag by ${FREETZ_TAGGING_STRING})" # newer (small logo @left, eg 7270 04.88) if [ -z "$tagging_files" ]; then tagging_files="$(find ${HTML_MOD_DIR} -name kopfbalken_links.gif)" tagging_position="center" tagging_geometry="+0+0" fi # older (big header @top, eg 7141 04.76) if [ -z "$tagging_files" ]; then tagging_files="$(find ${HTML_MOD_DIR} -name fw_header980.gif)" tagging_position="west" tagging_geometry="+0+0" fi # even older (big header @top, eg 7050 04.03) if [ -z "$tagging_files" ]; then tagging_files="$(find ${HTML_MOD_DIR} -name fw_header.gif)" tagging_position="west" tagging_geometry="+0-5" fi # tagging [ -z "$tagging_files" ] && error 1 "tagging failed, no files to tag found." tagging_picture="${TAGGING_DIR}/${FREETZ_TAGGING_STRING}.png" for tagging_file in $tagging_files; do echo2 "${tagging_file}" composite -dissolve 100% -gravity $tagging_position -geometry $tagging_geometry -quality 100 $tagging_picture $tagging_file $tagging_file [ $? -ne 0 ] && error 1 "tagging failed while processing ${tagging_file#${FILESYSTEM_MOD_DIR}/}" done fi fi if [ "$FREETZ_STRIP_LIBRARIES" == "y" ]; then echo0 "shrinking shared libs" . ${TOOLS_DIR}/freetz_mklibs mklibs || error 1 "mklibs returned an error. Please see mklibs.log." fi echo0 "stripping leftover unstripped binaries" for i in `find ${FILESYSTEM_MOD_DIR} ! \( -name '*.ko' -o -path '*/usr/www/*' -o -path '*/etc/default*' -o -path '*/lib/modules*' \) \ \( -perm +100 -o -name "*.so*" \) -type f -exec file {} '+'|sed -n 's|^\(.*\):.*MIPS.*not stripped.*|\1|p'`; do echo2 $i chmod u+r $i $STRIP -p --remove-section={.comment,.note,.pdr} $i done # external should run after modifying and stripping and so on # only run, if packaging is enabled if [ "$DO_PACK" -gt 0 ]; then if [ "$EXTERNAL_ENABLED" == "y" ]; then echo0 "processing external" [ ! -x "$EXTERNAL" ] && error 1 "cannot find the tool $EXTERNAL_TOOL" . "${EXTERNAL}" fi fi touch "${DIR}/.modified" echo "done." echo fi ################################ ## Pack the modified firmware ## ################################ if [ "$DO_PACK" -gt 0 ]; then echo "${BOLD}STEP 3: PACK${NORM}" if [ ! "$DO_MOD" -gt 0 ]; then echo "WARNING: Modifications (STEP 2) and this step should never" 1>&2 echo " ever be run with different configurations!" 1>&2 echo " This can result in invalid images!!!" 1>&2 fi # Check if firmware is unpacked if [ ! -r "${DIR}/.unpacked" ]; then error 1 "firmware image has to be unpacked before packing" fi # Check if firmware is modified by the script if [ ! -r "${DIR}/.modified" ]; then warn "firmware does not seem to be modified by the script" if [ ! -d "$MOD_DIR" ]; then # Copy the unpacked directory cp -r "$ORG_DIR" "$MOD_DIR" fi fi # Remove left over Subversion directories echo1 "checking for left over Subversion directories" find "$MOD_DIR" -type d -name .svn | xargs rm -rf # Delete all files that we are going to re-create now rm -f "$VARTAR_MOD" rm -f "$KERNEL_MOD" rm -f "$FILESYSTEM_MOD" rm -f "${DIR}/*.image" if [ "$FREETZ_SQUASHFS_BLOCKSIZE_ORIG" == "y" ]; then FILESYSTEM_BLOCKSIZE="$((1<<$(od -i -N 1 -j 34 "$FILESYSTEM" | sed -n -e '1s#.* ##' -e 1p)))" else FILESYSTEM_BLOCKSIZE=$(set | sed -rn 's/FREETZ_SQUASHFS_BLOCKSIZE_([^=]+)=y/\1/p') fi modmakedate=$(date +%Y%m%d-%H%M%S) modbaseimagename="${FREETZ_TYPE_PREFIX_ALIEN_HARDWARE}${FREETZ_TYPE_PREFIX}_${FIRMWAREVERSION}${SUBVERSION}.${FREETZ_TYPE_LANGUAGE}" if [ "$FREETZ_CUSTOM_IMAGE_NAME" == "y" -a ! -z "$FREETZ_USER_DEFINED_COMMENT" ]; then modcustomimagestring=$(echo $FREETZ_USER_DEFINED_COMMENT | sed -e "s/ /_/g" | tr -cd 'a-zA-Z0-9_+-.<->') else modcustomimagestring="" fi if [ "$FREETZ_CUSTOM_IMAGE_NAME" == "y" -a ! -z "${modcustomimagestring}" ]; then if [ "$FREETZ_CUSTOM_IMAGE_NAME_PREFIX" == "y" ]; then modimagenameprefix="${modcustomimagestring}_" modimagenamesuffix="" else modimagenameprefix="" modimagenamesuffix="_${modcustomimagestring}" fi else modimagenameprefix="" modimagenamesuffix="" fi modimage="${modimagenameprefix}${modbaseimagename}${modimagenamesuffix}_$modmakedate.image" # Create freetz-info echo1 "integrate freetz info file into image" freetz_info_file="$MOD_DIR/filesystem/etc/freetz_info.cfg" echo "export FREETZ_INFO_BOXTYPE='${FREETZ_TYPE_PREFIX_ALIEN_HARDWARE}${FREETZ_TYPE_PREFIX}'" > "$freetz_info_file" echo "export FREETZ_INFO_FIRMWAREVERSION='${FIRMWAREVERSION}'" >> "$freetz_info_file" echo "export FREETZ_INFO_SUBVERSION='${SUBVERSION}'" >> "$freetz_info_file" echo "export FREETZ_INFO_LANG='${FREETZ_TYPE_LANGUAGE}'" >> "$freetz_info_file" echo "export FREETZ_INFO_MAKEDATE='$modmakedate'" >> "$freetz_info_file" echo "export FREETZ_INFO_IMAGE_NAME='$modimage'" >> "$freetz_info_file" echo "export FREETZ_INFO_COMMENT='${FREETZ_USER_DEFINED_COMMENT}'" >> "$freetz_info_file" externalised_files=$(find build/modified/external/ -type f 2>/dev/null | sed -e '/\.external/d;s,build/modified/external/,,') echo "export FREETZ_INFO_EXTERNAL_FILES='${externalised_files}'" >> "$freetz_info_file" # Pack var.tar (use old tar for compatibility) echo0 "packing var.tar" "$TAR" -c -C "$VARTAR_MOD_DIR" . > "$VARTAR_MOD" || exit 1 if [ ! -s "$VARTAR_MOD" ]; then error 1 "packing of var.tar failed" fi # Do we have the tool ? if [ ! -x "$MKSQUASHFS" ]; then error 1 "cannot find $MKSQUASHFS_TOOL" fi echo0 "creating filesystem image" echo1 "squashfs blocksize: $FILESYSTEM_BLOCKSIZE" [ "$FREETZ_HAS_UDEV" == "y" ] || \ $MAKEDEVS -d $MAKEDEVS_FILE $FILESYSTEM_MOD_DIR > $MOD_DIR/filesystem.log 2>&1 $TOOLS_DIR/$MKSQUASHFS_TOOL $FILESYSTEM_MOD_DIR/* $ABS_BASE_DIR/$FILESYSTEM_MOD $MKSQUASHFS_OPTIONS -b $FILESYSTEM_BLOCKSIZE >> $MOD_DIR/filesystem.log 2>&1 if [ ! -s "$FILESYSTEM_MOD" ]; then error 1 "creation of filesystem failed" fi echo0 "merging kernel image" dd if="$RAW_KERNEL_MOD" of="$KERNEL_MOD" bs=256 conv=sync 2> /dev/null cat "$FILESYSTEM_MOD" >> "$KERNEL_MOD" if [ ! -s "$KERNEL_MOD" ]; then error 1 "kernel merging failed" fi # Check size of kernel image let KERNEL_LIMIT="$FREETZ_KERNEL_MTD_SIZE*65536" let KERNEL_SIZE="$(wc -c < "$KERNEL_MOD")" let DIFF="KERNEL_SIZE-KERNEL_LIMIT" echo1 "kernel image size: $KERNEL_SIZE (max: $KERNEL_LIMIT, free: $((-DIFF)))" if [ "$KERNEL_SIZE" -eq 0 ]; then error 1 "kernel image is empty" fi if [ "$KERNEL_SIZE" -gt "$KERNEL_LIMIT" ]; then error 1 "kernel image is $DIFF bytes too big. See http://trac.freetz.org/wiki/FAQ#Filesystemimagetoobig for details." fi if [ "$FREETZ_VERBOSITY_LEVEL" -ge 1 ]; then if [ "$FREETZ_HAS_TAM" = "y" ]; then # Calculate aproximately free space in seconds for the answering machine FREE_BYTE_JFFS2=$((($KERNEL_LIMIT - $KERNEL_SIZE - 233472))) FREE_MINUTES=$((($FREE_BYTE_JFFS2 / 2017 / 60))) if [ "$FREE_BYTE_JFFS2" -gt 0 ]; then echo "${L1}Aproximately free time for the answering machine: $((($FREE_BYTE_JFFS2 / 2017)))s (${FREE_MINUTES}min $((($FREE_BYTE_JFFS2 / 2017 - $FREE_MINUTES * 60)))s)" else echo "${L1}WARNING: Not enough free flash space for answering machine!" fi fi fi # Do we have the tool ? if [ ! -x "$TICHKSUM" ]; then error 1 "cannot find wonderful tool $TICHKSUM_TOOL" fi # Write checksum "$TICHKSUM" "$KERNEL_MOD" > "${MOD_DIR}/kernelchksum.log" # Consistency check if [ -s "${FIRMWARE_DIR}/${KERNEL_IMAGE}" -a ! -s "${FIRMWARE_MOD_DIR}/${KERNEL_IMAGE}" ] || \ [ ! -s "${FIRMWARE_DIR}/${KERNEL_IMAGE}" -a -s "${FIRMWARE_MOD_DIR}/${KERNEL_IMAGE}" ] then error 1 "inconsistency comparing size of old and new kernel.image" fi # Last, but not least, include .config and addon/static.pkg into firmware # image for further reference, e.g. user support [ -r "$DOT_CONFIG" ] && cp "$DOT_CONFIG" "$FIRMWARE_MOD_DIR/var" [ -r "$STATIC_ADDON_FILE" ] && cp "$STATIC_ADDON_FILE" "$FIRMWARE_MOD_DIR/var" [ -r "$PACKAGES_LIST_FILE" ] && cp "$PACKAGES_LIST_FILE" "$FIRMWARE_MOD_DIR/var" # Pack firmware image (use old tar for compatibility) echo0 "packing ${modimage}" "$TAR" -c -C "$FIRMWARE_MOD_DIR" . > "${DIR}/${modimage}" || exit 1 if [ ! -s "${DIR}/${modimage}" ]; then rm -f "${DIR}/${modimage}" error 1 "packing of firmware image failed" fi if [ "$EXTERNAL_CREATEPAK" == "y" ] && [ -n "$externalised_files" ]; then modexternal="${modimagenameprefix}${modbaseimagename}${modimagenamesuffix}_$modmakedate.external" echo "packing ${modexternal}" "$TAR" -c -C "$EXTERNAL_MOD_DIR" . > "${DIR}/${modexternal}" || exit 1 if [ ! -s "${DIR}/${modexternal}" ]; then rm -f "${DIR}/${modexternal}" error 1 "packing of external tar failed" fi fi if [ -s "${DIR}/${modimage}" ]; then echo0 "Image files can be found in the ./${FW_IMAGES_DIR}/ subfolder" if [ "$FREETZ_REPLACE_SSL_LIBS" == "y" ]; then [ "$FREETZ_LIB_libcrypto" == "y" -o "$FREETZ_LIB_libssl" == "y" ] && echo "Caution: Replacing libcrypto or libssl may cause an unusable image. See http://trac.freetz.org/wiki/FAQ#NachdemFlashenistdasAVM-Webinterfacenichtmehrerreichbar for details." fi fi echo0 "done." echo echo "${BOLD}FINISHED${NORM}" fi exit 0