[PATCH 3/3] adds prototype script to apply patches and package feed
Tim Niemeyer
tim.niemeyer at mastersword.de
Mi Jul 15 21:31:47 CEST 2015
Hi Tobias
Ich bin nicht ganz sicher, ob gleich am Anfang so ein Skript stehen
muss, ich denke wir müssen erstmal die Package sauber zusammen kriegen
und dann kann man sich Schritt für Schritt weitere Tools/Scripts drum
herum bauen.
Aber nun isses ja erstmal da. Schaut auch sehr brauchbar aus, trotzdem
unten paar Anmerkungen. Die meisten sind Details und einige kann man
sicher auch später nochmal angehen..
Am Mittwoch, den 15.07.2015, 19:33 +0200 schrieb tk+ff at meskal.net:
> 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
^ Leerstelle fehlt
> +
> 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"
MMn keine gute Vorauswahl, da wir hierdurch ständig und stetig
Änderungen rein kriegen. Wir sollten erstmal auf einem festen Standbein
unsere Sache aufbauen.
> +
> +SUPPORTED_BOARDS=""
Wird nicht verwendet.
> +
> +MYBOARD=""
Ein default Wert wäre gut.
> 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 @@
Hier sollte so ein schöner Header wie aus dem install Skript drin sein.
> +
> +##
> +#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"
Später greifst du auf diese "Error-Variable" zu. Das ist mMn
ungeschickt, weil man halt den Aufbau der Funktion kennen muss. Ich
stelle mir da gerade vor, dass man besser einen negativen return Value
zurück gibt und ggfs dann eine ERRSTR Varible mit Details füllt.
> + 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
Uh, hopla. Woher kommt das jetzt? ;)
> + 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
Hast du schon eine Präferenz welche GPL?
> +
> +#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
Hopla, nun sind wir in einer anderen Datei und kriegen diese neue
Variable rein.. Du hast da ja auch schon ein TODO dran geschrieben. Wäre
für einen ersten Wurf für mich ok, wenn du in dem TODO aus dem $FAILED
einfach einen negativen Rückgabewert machst. Das TODO wäre dann bei der
eigentlich Funktion ebenfalls unterzubringen.
Tim
> + 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