Script for generating BRouter profiles on Android device

Started by poutnikl, August 18, 2019, 12:28:32

0 Members and 2 Guests are viewing this topic.

poutnikl

I have recently written and tested the  Linux port of Windows batch sedbatch.bat, used for mass generation of my BRouter profiles from respective templates.

It creates very interesting possibility to create profiles directly on an Android device, using termux, a great Linux terminal emulator for Android.
( It e.g. allows you to install and use the git command, python, ipython and more.)

It works with all bike/foot/car repositories,
additionally to Windows version optionally with develop GitHub branch as well.

Link to the script on GitHub:

https://github.com/poutnikl/Brouter-profiles/blob/master/sedbatch

Below is copied the current legend comment from the script:

#!/bin/bash
#
#**********************
# Ver 1.1 Fixed generation for Hiking-wet profiles ( by error identical to dry ones )
# Ver 1.2 Parameter "main" generates only main/major profiles
# Ver 1.2.1 Fixed names of Trekking-Dry/Wet profiles ( Was Poutnik instead of Trekking ])
# Ver 1.3.1 Added Shortest-P profile
# Ver 1.3.2 windows batch ported to Linux Bash
# Ver 1.4 Improved script parameter logic. Action paramaters are bike/car/foot, modifiers are master/develop and all/main
#         Implemented termux path specifics and profike copying
#
# automatically generates a bunch of Brouter profiles
# based on the bike/car/foot profile templates by Poutnik
#
# When launched,
#   1/  it create a working subfolder in a folder where the script resides
#   2/  it downloads latest bike/car/foot profile template from GitHub depository
#   3/  it generates end user profiles by automatic subtitution of parameters
#   4/  it packs them into a single ZIP archive and deletes the working subfolder content.
#   5/  it optionally copies profiles to the scriot folder
#          or from termux private space to Android storage.
#
# ******************************************************
#                     P R E R E Q U I S I T I E S
# ******************************************************
# 0 This bash script can be run
#   either on a desktop Linux
#   either on Android within Linux terminal emulator termux.
#
# Points 1-5 applies only if to be run on an Android device
#
# 1 Install termux ( Linux terminal emulator for Android )
#   https://play.google.com/store/apps/details?id=com.termux
#   Read links below for more
#   https://termux.com
#   https://wiki.termux.com/wiki/Main_Page
#   https://wiki.termux.com/wiki/Community
#   https://github.com/termux
#
# 2 Run termux, what open Linux terminal emulator
# 3 Execute "termux-setup-storage"
#   if you want to grant termux permissions to write profile files out of its sandbox
#   to be able to copy profiles to Android storage.
#   It is recommendec not to copy directly to live profiles2 folder.
#   (run "apt update && apt upgrade" to make sure that this tool is available)
#   See  more at https://wiki.termux.com/wiki/Termux-setup-storage
# 4 Check if sed and wget commands are available.
#   If not, install them by "pkg install sed" resp. "pkg install wget"
# 5 Check and define withing the script code
#   your desired target folder for copying profiles.
#   
# 6 If run on Linux, or on termux without jailbreak
#   ( the script is testing both )
#   the optional (aside of zip with profiles)
#   is redirected to the folder the scriot resides.
#
# 7 Both Linux and termux expects placing the sedbatch script
#    (subject of later renaming, remsins for historical reasons )
#
# 8 
# The sedbatch.sh expects particular command line parameters to do anything.
# "sedbatch.sh" without parameters lists this legend.
# "sedbatch.sh" can be provided by arbitrary sequence of keywords:
# bike car foot main all master develop copy nocopy           
#
# bike, car, foot are "action" keywords, generating respective profiles from a profile template
# all(default), main are  modifiers, setting scope of generated profiles ( all or the most important)
# master(default), develop are modifiers determining the github repository branch, where the profile template is located
# nocopy(default), copy, copies profiles to Android storage ( jailbroken termux )
# or to the script folder.
#
# Examples of usage'
# "sedbatch.sh bike" generates all profiles from bike trekking template
# and stores them in BR-Bike-Profiles-master-all.zip
# and generates the all profiles for all car, bike and foot transportation modes
#
# "sedbatch.sh main develop bike" generates only selected major profiles from bike trekking template
# from develop branch
#
# "sedbatch.sh copy main foot all bike develop main car"
# generates  major profiles for hiking, all profiles for bike trekking
# and selected profiles from car template develop branch.
# Additionally, profiles are copied to selected folder
#

Sent from my Xiaomi MI A2 via Tapatalk


poutnikl

Similarly, I have a script in use for termux, that downloads and properly places RD5 files of BRouter and Mapsforge compatible MAP files for OpenAndroMaps or osm.paws.cz ( useful for central Europe, with frequent updates ).

The download is intelligent enough, skipping downloading if the local files are "new enough", with threshold set in the script.

https://github.com/poutnikl/Brouter-profiles/blob/master/getmap.sh

It is driven by a list of abbreviated parameters.

E.g.:
"./getmap.sh 0 1 cz"
downloads to the target folders
RD5 files for Czech Republic
and Czech Republic map from osm.paws.cz

For different locations, it may not be directly usable, until modified to download relevant files.

For this case, take it as inspiration and a template to modify.

Sent from my Xiaomi MI A2 via Tapatalk

poutnikl

Largely improved beta version of Linux / Android termux script "sedbatch",

originated from the Windows batch,  for generation  of  ( not only ) my BRouter profiles.

It can e.g. generate directly on the phone release and development versions of my profiles, or  standard 2 variants of Jacob's streetbike profiles and 4 variants of zossebart's MTB profiles.

It can be done either from GitHub links,
either from your local git repositories.

Extensive comments are inside the script.

The stript cannot be used as us, as you have to configure for your environment, at least the folder constants.

Constructive feedback is welcome.



Sent from my Xiaomi MI A2 via Tapatalk
http://cloud.tapatalk.com/s/5d66d473a2e3a/sedbatch6.sh.zip

zossebart

Thanks for the script! And thanks for including my mtb profiles!

I tried it on linux and it worked flawlessly out of the box with 'nocopy' and 'remote'. Very handy!
I have yet to try it on Android (thanks btw. for the tip for termux app, seems very sophisticated and powerful!).

Although with the help of this script it's very easy (at least for a somewhat tech-interested person) to generate all the profile variants, I still dream of client apps like Locus making the profile parameters switcheable in the UI (as it is already the case for limited paramers like is_wet, avoid_unpaved etc.).
On the other side, it could complicate things for example with sophisticated profile templates like yours because of the many parameters. Maybe hide the complexity from normal users in an "expert menu"?

This topic is btw. currently discussed for brouter-web (https://github.com/nrenner/brouter-web/issues/223).
  •  

poutnikl

I have idea about high level parameters, influencing multiple low level parameters at once ( well, it is already partially done e.g with MTB_factor ), where their non default value would override eventual explicit settings by low level parameters.

These parameters could be exposed to Locus by already existing syntax

assign parameter default # %parameter% short desc | long desc

as is done at Locus internal profikes
( but must be hardcoded in Locus, it is not dynamic )

Sent from my Xiaomi MI A2 via Tapatalk

poutnikl

I have currently modified the development not yet submitted script and the bike template.

assign   is_wet     0 # %is_wet% Wet_conditions

If there is used the scope parameter "locus" instead of "all", the script does not generate both dry and wet profile variants, but just the universal version.

The %is_wet% parameter ( original iswet was not recognized ) is switchable in Locus ( tested in beta ).

I will do the same for generation of other bike profiles.

Full generation is kept for Brouter-web uploads ( for now?) and for other applications.

I have experimentally added another parameter, recognized by the Locus dialogue, to the bike template:

%avoid_unpaved%

as the stronger version of %is_wet%.


Sent from my Xiaomi MI A2 via Tapatalk

poutnikl

Attached set of the generated Locus-aimed development profiles for testing, involving previously implemented  %is_wet% and %avoid_unpaved% Locus dialog parameter.

There are no -dry and -wet versions anymore*), as it is addressed by the dialog settings.

There remains Trekking-Dry just to distinguish itself from the original BRouter profile.

Works already for Locus release version.
(originally thought beta is needed).

*) For BRouter-web and other application, full set including wet profiles will be generated.

http://cloud.tapatalk.com/s/5d74b87471208/BR-Bike-Profiles-develop-locus.zip

Sent from my Xiaomi MI A2 via Tapatalk

tommi

  •  

poutnikl

Well, it was a false alarm.

I know 4 %X% parameters have been implemented in Locus some 2 years ago, but I kind of thought it was hardcoded to internal embedded variants of my car and bike profiles.

I remember recent discussion in the forum or BRouter Github repository about enhancing the implementation.

I have originally tested the %X% parameters on the Locus beta only.

Now, I have tested it on Locus release version, and it works as well.

But I still think only is_wet, avoid_unpaved and 2 other car related parameters ( avoid_toll?, avoid_motorways?) have been implemented.

Sent from my Xiaomi MI A2 via Tapatalk

zossebart

I tested the script with termux on android now.
After checking that wget and sed are available in termux, the script failed with invalid parameters for wget and sed :-(
After some investigation, I found out that the limited versions of these tools from the underlying android busybox where the problem. After installing full-featured versions via the package manager, the script works fine! Of course, you have this covered already in your in-script documentation...I just ignored it first :-)
Is the modified version of the script available somewhere? Maybe you could push the development branch to github?
  •  

poutnikl

It is already in Brouter-profiles repository, at least last RC version.

Perhaps, zip may need to be installed as well.

Sent from my Xiaomi MI A2 / Android 9, via Tapatalk

zossebart

Yes, you are right, I had to install zip.

Ok, I thought with the latest version there should only be generated 2 versions of my mtb profile, because the is_wet parameter is handled by the client? Or did I misunderstand something?
  •  

poutnikl

Well, I guess that is addressed by the development script version. I may post it to the forum later today.


Sent from my Xiaomi MI A2 / Android 9, via Tapatalk


poutnikl

I am attaching the development version of the sedbatch script, I do not want to add it to the github, as it is not finished yet.

There is another scope option locus, that is currently implemented just for for profile option bike ( my bike profile generation ) and mtb (your ). It creates just 1 universal profile for both dry/wet condition.

It replaces function

function mtbexec {

replaceone is_wet 0 0 $src     mtbzoss-dry
replaceone is_wet 0 1 $src     mtbzoss-wet

replaceone mtb_hard_factor 0 1 mtbzoss-dry    mtbzoss-hard-dry
replaceone mtb_hard_factor 0 1 mtbzoss-wet    mtbzoss-hard-wet

}


by

function mtbexec {

replaceone is_wet 0 0 $src     mtbzoss
replaceone mtb_hard_factor 0 1 mtbzoss   mtbzoss-hard

}