From fe8b51686ea80f364c20b1df1f6f9dc7637c7a21 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Thu, 3 Apr 2014 13:04:49 +0200 Subject: [PATCH] Add script to generate openwrt feeds.conf file (and template fuke as fallback). --- extra/openwrt-build/feeds.conf.template | 3 + extra/openwrt-build/gen-feeds-conf.sh | 125 ++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 extra/openwrt-build/feeds.conf.template create mode 100755 extra/openwrt-build/gen-feeds-conf.sh diff --git a/extra/openwrt-build/feeds.conf.template b/extra/openwrt-build/feeds.conf.template new file mode 100644 index 0000000..da488ce --- /dev/null +++ b/extra/openwrt-build/feeds.conf.template @@ -0,0 +1,3 @@ +src-git packages git://git.openwrt.org/packages.git^e5f758e0729d094441aad849bbab4117b816567d +# Edit the path below to point to the directory of the Doodle3D feed. +src-link wifibox /Users/USERNAME/xxxFiles/doodle3d_feed_path diff --git a/extra/openwrt-build/gen-feeds-conf.sh b/extra/openwrt-build/gen-feeds-conf.sh new file mode 100755 index 0000000..3c6ee2d --- /dev/null +++ b/extra/openwrt-build/gen-feeds-conf.sh @@ -0,0 +1,125 @@ +#!/bin/sh + +# This script generates a file feeds.conf and places it in the OpenWrt buildroot directory. +# It deduces the location of your Doodle3D feed by looking at its own path and, +# on OSX, tries to find the OpenWrt buildroot by looking for something mounted in a +# directory containing the word 'openwrt'; specify the path with -p if that fails. + +SYSNAME=`uname -s` +WRT_PATH= +FEED_PATH= +PACKAGES_FEED_SHA5=e5f758e0729d094441aad849bbab4117b816567d + +nextIsWrtPath=0 +for arg in "$@"; do + if [ $nextIsWrtPath -eq 1 ]; then + WRT_PATH="$arg" + nextIsWrtPath=0 + continue + fi + + case "$arg" in + -p) + nextIsWrtPath=1 + ;; + -h) + echo "This script generates an OpenWrt feeds.conf file for building Doodle3D, it works automatically." + echo "If the wrt buildroot path cannot be determined, specify it using '-p '." + echo "If you want the file contents to be shown instead of written out to a file, use '-c'." + exit 0 + ;; + *) + echo "! Error: unknown argument '$arg' found" + exit 1 + ;; + esac +done +if [ $nextIsWrtPath -eq 1 ]; then + echo "! Error: missing argument for -p option" + exit 1 +fi + + +if [ "x$WRT_PATH" = "x" ]; then + if [ "x$SYSNAME" != "xDarwin" ]; then + echo "! Error: it looks like you are not using OSX, please specify the OpenWrt buildroot path with '-p '." + exit 1 + + elif [ "x$SYSNAME" = "xDarwin" ]; then + mountPath=`mount | sed -n 's|^.* \([^ ]*[Oo][Pp][Ee][Nn][Ww][Rr][Tt][^ ]*\).*$|\1|p'` + if [ -z "$mountPath" ]; then + echo "! Error: could not find openwrt-like path in list of mount points." + echo "! Please mount the image an rerun, or specify the path using '-p '." + exit 2 + fi + + # Looking for the word 'openwrt' in a README file in a direct subdir...is this a reasonable 'detect' approach? + for i in $(ls -d $mountPath/*/); do + dirname=${i%%/} + grep -sqi openwrt "$dirname/README" + if [ $? -eq 0 ]; then + WRT_PATH="$dirname" + fi + done + + if [ -z "$WRT_PATH" ]; then + echo "! Error: could not find buildroot path in what looks like an OpenWrt image ('$mountPath'), please rerun with '-p '." + exit 3 + fi + fi +fi + + +echo "===== Doodle3D OpenWrt feeds.conf generator" +echo "* Using OpenWrt buildroot path: '$WRT_PATH'" + +FEED_PATH="$0" +FEED_PATH=`dirname "$FEED_PATH"` # Ok, so after this we've got a non-normalized path to the script dir +FEED_PATH="$FEED_PATH/../../.." # go back to just outside the doodle3d-firmware repo, which should be the feed root + +echo "$FEED_PATH" | grep -sq "^\/" +if [ $? -ne 0 ]; then FEED_PATH="`pwd`/$FEED_PATH"; fi + +#NOTE: and normalize the path...this method feels a bit fragile (spurious output, special user env conditions and whatnot) +pushd "$FEED_PATH" > /dev/null 2>&1 +FEED_PATH="`pwd`" +popd > /dev/null 2>&1 + +echo "* Using Doodle3D feed path: '$FEED_PATH'" + +echo "$FEED_PATH" | grep -sq ' ' +if [ $? -eq 0 ]; then + echo "! Error: the feed path contains spaces, which OpenWrt cannot handle. Exiting..." + exit 4 +fi + +FILE_CONTENTS=$( cat << EOT +src-git packages git://git.openwrt.org/packages.git^$PACKAGES_FEED_SHA5 +src-link wifibox $FEED_PATH +EOT +) + +echo "* Contents to be written:\n$FILE_CONTENTS\n" + +while true; do + read -p "? Proceed to write a new feeds.conf? " yn + case $yn in + [Yy]*) break;; + [Nn]*) + echo "* Ok, feeds.conf will not be generated. Exiting..." + exit 0;; + *) echo "! Please answer yes or no.";; + esac +done + +OUT_PATH="$WRT_PATH/feeds.conf" +BKP_PATH="$WRT_PATH/feeds.conf.d3dbkp" +if [ -f "$OUT_PATH" ]; then + echo "* Backing up $OUT_PATH to $BKP_PATH" + cp "$OUT_PATH" "$BKP_PATH" +fi + +echo "* Generating $OUT_PATH" +echo "$FILE_CONTENTS" > "$OUT_PATH" + +exit 0