[PATCH 3/3] adds prototype script to apply patches and package feed

tk+ff at meskal.net tk+ff at meskal.net
Mi Jul 15 19:33:40 CEST 2015


most of the functionality is implemented in a
functions.sh bash library to support future smaller scripts
like "buildallArchs", "upgradOpenwrt", or "saveRevision"
just to name some examples
---
 README.md            |   4 ++
 scripts/.keepdir     |   0
 scripts/config       |   7 +++
 scripts/functions.sh | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/install      |  79 ++++++++++++++++++++++++++++
 5 files changed, 233 insertions(+)
 delete mode 100644 scripts/.keepdir
 create mode 100644 scripts/config
 create mode 100644 scripts/functions.sh
 create mode 100755 scripts/install

diff --git a/README.md b/README.md
index aa4e57d..b4b6f39 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,10 @@ Finally start the build process
 make
 </pre>
 
+How to automate applying these patches and packages
+===================================================
+Use the script./scripts/install
+
 How to submit patches
 =====================
 Please send patches you would like to contribute to this repository to this mailinglist:
diff --git a/scripts/.keepdir b/scripts/.keepdir
deleted file mode 100644
index e69de29..0000000
diff --git a/scripts/config b/scripts/config
new file mode 100644
index 0000000..20abde5
--- /dev/null
+++ b/scripts/config
@@ -0,0 +1,7 @@
+OPENWRT_REV="HEAD"
+PACKAGES_REV="HEAD"
+ROUTING_REV="HEAD"
+
+SUPPORTED_BOARDS=""
+
+MYBOARD=""
diff --git a/scripts/functions.sh b/scripts/functions.sh
new file mode 100644
index 0000000..0f6515c
--- /dev/null
+++ b/scripts/functions.sh
@@ -0,0 +1,143 @@
+
+##
+#Syntax: getBaseDirs pathToscript
+#sets FFBASE and checks if it ist a correct freifunk firmware checkout
+#sets OWBASE and checks if it ist a correct openwrt checkout
+
+getBaseDirs(){
+  #directory of install script
+  FFBASE=$(dirname $0)
+  #absolute path of firmware repository
+  FFBASE=$(realpath $FFBASE/..)
+  echo Using FreiFunk base: $FFBASE
+  echo
+  if [[ -z $FFBASE || ! -d $FFBASE || ! -d $FFBASE/patches  || ! -d $FFBASE/packages  ]] ; then
+    echo We need a working copy of the firmware repository as a single argument
+    exit 1
+  fi
+  
+  #use current working dir as openwrt base
+  OWBASE=$(realpath ./)
+  echo Using OpenWRT base: $OWBASE
+  echo
+  #this is a very weak check for openwrt base...
+  if [[ ! -d $OWBASE &&  ! -f $OWBASE/feeds.config.default ]] ; then
+    echo This script has to be called from a openWRT buildroot
+    exit 1
+  fi
+}
+
+patchDirToGit(){
+  local PATCHDIR=$1
+  local GITCO=$2
+  if [[ -z $PATCHDIR || -z $GITCO ]] ; then
+    echo PATCHDIR and GITCO needed!
+    return 1
+  fi
+  local MYGIT="git -C $GITCO"
+  for PATCH in $(ls $PATCHDIR/) ; do
+    echo Test applying $PATCH to $GITCO
+    if  $MYGIT apply --check --whitespace=nowarn $PATCH ; then
+      echo Actually applying patch
+      if $MYGIT am --whitespace=nowarn $PATCH ; then
+        echo Success!
+      else
+        echo this should never happen...
+        exit 1
+      fi
+    else
+      echo Applying $PATCH failed!
+      FAILEDPATCHES="${FAILEDPATCHES}Failed applying\n$PATCH\nto\n$GITCO\n"
+      FAILEDPATCHES="${FAILEDPATCHES}\nTry calling \"git -C $GITCO am $PATCH\" manually. git will tell you more!\n\n"
+      echo Has it already been applied?
+    fi
+    echo
+  done
+  echo Patching $GITCO done
+  echo
+}
+
+#
+# Hard reeset git repo to given Revision
+# resetGit $repo $revision
+
+resetGit() {
+  local GITCO=$1
+  local REVISION=$2
+
+  local MYGIT="git -C $GITCO"
+
+  if $MYGIT rev-parse --quiet --verify $REVISION  >> /dev/null ; then
+    echo Resetting $GITCO to $REVISION
+    $MYGIT reset --hard $REVISION
+    echo
+  else
+    echo Revision $REVISION is not valid!
+    echo Maybe you have to update Openwrt?
+  fi
+}
+
+resetRepos(){
+  if [[ -n $OPENWRT_REV ]] ; then
+    resetGit $OWBASE $OPENWRT_REV
+  else
+    resetGit $OWBASE \@{upstream}
+  fi
+
+  if [[ -n $ROUTING_REV ]] ; then
+    resetGit $OWBASE/feeds/routing $ROUTING_REV
+  else
+    resetGit $OWBASE/feeds/routing \@{upstream}
+  fi
+
+  if [[ -n $PACKAGES_REV ]] ; then
+    resetGit $OWBASE/feeds/packages $PACKAGES_REV
+  else
+    resetGit $OWBASE/feeds/packages \@{upstream}
+  fi
+}
+
+patchRepos(){
+  echo Patching openwrt
+  echo
+  patchDirToGit $FFBASE/patches/openwrt/ $OWBASE $OWBASE
+
+  echo Patching openwrt routing feed
+  echo
+  patchDirToGit $FFBASE/patches/routing/ $OWBASE/feeds/routing/
+
+  echo Patching openwrt packages feed
+  echo
+  patchDirToGit $FFBASE/patches/packages/ $OWBASE/feeds/packages/
+  
+  if [[ -n $FAILEDPATCHES ]] ; then
+    echo Unfortunatly applying these patches failed:
+    echo -e $FAILEDPATCHES
+    echo Please examine them and fix them.
+    echo Thanks
+  fi
+}
+
+#usage: installFeed feeddir feedname
+installFeed(){
+  local FFPACKAGEDIR=$1
+  local FFFEEDNAME=$2
+  if [[ -f  $OWBASE/feeds.conf ]] ; then
+    if ! grep $FFFEEDNAME $OWBASE/feeds.conf ; then
+      echo Adding FreiFunk packages to package feeds.conf
+      echo src-link  $FFFEEDNAME $FFPACKAGEDIR >> $OWBASE/feeds.conf
+    else
+      echo FreiFunk packages already installed
+      echo
+    fi
+  else
+    echo Using default feeds.config
+    cp $OWBASE/feeds.conf.default $OWBASE/feeds.conf
+    echo src-link $FFFEEDNAME $FFPACKAGEDIR >> $OWBASE/feeds.conf
+  fi
+}
+
+boardConfig(){
+  local BOARD=$1
+  echo $BOARD=y
+}
diff --git a/scripts/install b/scripts/install
new file mode 100755
index 0000000..95d2e97
--- /dev/null
+++ b/scripts/install
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# Copyright (C) 2015 Tobias Klaus - All Rights Reserved
+# Permission to copy and modify is granted under the GPL license
+
+#Small script to install ff-firmware to a plain openwrt repository as an "environment"
+#this script should only be called once. After that normal git operations on the ff-firmware
+#dir "env" and the openwrt package should be used.
+
+#Call this script from the base of your openwrt git checkout
+
+FFFEEDNAME=FreiFunk
+
+#Should the git repos be reset to their upstream HEAD?
+#"yes" is the default because custom patches should be kept in FFBASE anyway
+#and "yes" makes this script reappliable
+RESETREPOS=yes
+source $(dirname $0)/functions.sh
+source $(dirname $0)/config
+
+getBaseDirs $1
+FFPACKAGEDIR=$FFBASE/packages
+FEEDSCRIPT=$OWBASE/scripts/feeds
+
+installFeed $FFPACKAGEDIR $FFFEEDNAME
+
+echo Updating all packages
+echo
+$FEEDSCRIPT update -a
+
+#make sure the repositories are reset to desired revisions
+resetRepos
+
+#apply patches
+patchRepos
+
+#recreate index for packages
+$FEEDSCRIPT update -i
+
+#make all packages available for configuration
+$FEEDSCRIPT install -a
+
+
+DOTCONFIG="y"
+if [[ -f $OWBASE/.config ]] ; then
+  echo
+  echo Do you really want to override $OWBASE/.config? Type \"y\". Anything else will abort here.
+  read OVERRIDE
+  if [[ ! ${OVERRIDE} = "y" ]] ; then
+    DOTCONFIG="n"
+  fi
+fi
+echo DOTCONFIG: $DOTCONFIG
+if [[ $DOTCONFIG = "y" ]] ; then
+#make sure to build our packages
+  cat $FFBASE/package.config > $OWBASE/.config
+
+  if [[ -n $MYBOARD ]] ; then
+    boardConfig $MYBOARD >> $OWBASE/.config
+  fi
+fi
+
+#TODO: introduce general flag $FAILED to indicate that something on the way went wrong
+if [[ -z $FAILEDPATCHES ]] ; then
+  echo All patches succesfully applied!
+fi
+
+echo Next steps:
+echo Configure for the target device:
+echo
+echo make defconfig
+echo make menuconfig
+echo
+echo Build it:
+echo
+echo make -j$(getconf _NPROCESSORS_ONLN)
+echo
+echo Have fun!
+
-- 
2.4.5




Mehr Informationen über die Mailingliste franken-dev