Author: biurrun Date: Fri Sep 25 16:38:56 2009 New Revision: 986 Log: Script for OpenWrt autoconfiguration of PISA routers. It currently copies all router-specific configuration files into an OpenWrt tree and then patches and configures the tree. Added: trunk/openwrt/trunk/configure_router.sh (contents, props changed) Added: trunk/openwrt/trunk/configure_router.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openwrt/trunk/configure_router.sh Fri Sep 25 16:38:56 2009 (r986) @@ -0,0 +1,86 @@ +#!/bin/sh +# quick script to prepare an OpenWrt tree for flashing PISA routers +# Relies on '-i' GNU extension for sed. + +### helper functions ### +usage() { + echo $0 "<router_name> <path/to/openwrt/checkout> <path/to/pisa/checkout> <path/to/hipl/checkout>" + echo "This program will configure an OpenWrt tree for flashing a PISA router." + echo "Your PISA and hipl trees are assumed to contain 'make dist' tarballs." + exit $1 +} + +check_directory () { + if ! test -d "$2"; then + echo $1 directory does not exist. + exit 1 + fi +} + +check_tarball () { + if test ! -r "$2"; then + echo $1 tarball not available. + echo Run 'make dist' in your $1 tree. + exit 1 + fi +} + + +### set variables ### +ROUTER_NAME=$1 +OPENWRT_PATH=$2 +PISA_PATH=$3 +HIPL_PATH=$4 + +PISA_OPENWRT_PATH=$PISA_PATH/openwrt/trunk + + +### sanity checks ### +case $1 in + -h|--help) + usage 0;; + */*|"") + usage 1;; +esac + +check_directory OpenWrt ${OPENWRT_PATH} +check_directory PISA ${PISA_PATH} +check_directory hipl ${HIPL_PATH} + +check_tarball PISA ${PISA_PATH}/pisa-*.tar.gz +check_tarball hipl ${HIPL_PATH}/hipl-*.tar.gz + + +### configure OpenWrt tree ### +PISA_VERSION=$(basename ${PISA_PATH}/pisa*.tar.gz | sed -e s/pisa-// -e s/.tar.gz//) + +mkdir "${OPENWRT_PATH}/files" +cp -Lr "${PISA_OPENWRT_PATH}/${ROUTER_NAME}/etc" "${OPENWRT_PATH}/files" + +sed -i -e "s/Subversion HEAD/$PISA_VERSION /" "${OPENWRT_PATH}/files/etc/banner" + +mkdir "${OPENWRT_PATH}/dl" +cp ${PISA_PATH}/pisa*.tar.gz ${OPENWRT_PATH}/dl +cp ${HIPL_PATH}/hipl*.tar.gz ${OPENWRT_PATH}/dl + +cp -r "${PISA_OPENWRT_PATH}/package/hipl" "${OPENWRT_PATH}/package/" +cp -r "${PISA_OPENWRT_PATH}/package/pisa" "${OPENWRT_PATH}/package/" +cp -r "${PISA_OPENWRT_PATH}/package/libxml2" "${OPENWRT_PATH}/package/" + +sed -i -e "s/PKG_VERSION:=.*/PKG_VERSION:=$PISA_VERSION/" "${OPENWRT_PATH}/package/pisa/Makefile" + +"${OPENWRT_PATH}/scripts/feeds" update > /dev/null +"${OPENWRT_PATH}/scripts/feeds" install ipsec-tools libconfig libnetfilter-queue ntpclient tcpdump > /dev/null + +# This has to come after the feed installation. Otherwise the .config file gets +# modified and entries about not-yet-installed programs are clobbered. +# Copy only changed .config files to avoid triggering unnecessary rebuilds. +cmp -s ${PISA_OPENWRT_PATH}/dot_config "${OPENWRT_PATH}/.config" || + cp ${PISA_OPENWRT_PATH}/dot_config "${OPENWRT_PATH}/.config" + +cd "${OPENWRT_PATH}" + +for patch in ${PISA_OPENWRT_PATH}/patches/*.patch; do + patch --dry-run --batch --strip=1 --input=$patch && + patch --batch --strip=1 --input=$patch +done