All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: zimmermach@gmail.com
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH BlueZ 1/2] Added config conversion for Bluez4 as shell script during install
Date: Tue, 27 Nov 2018 13:50:09 +0200	[thread overview]
Message-ID: <CABBYNZJ72pzUOG2ukReBVNhwiwLFW7Zzts96HvF+WHHdKWfBEQ@mail.gmail.com> (raw)
In-Reply-To: <20181126164907.15659-1-zimmermach@gmail.com>

Hi Christian,
On Mon, Nov 26, 2018 at 6:53 PM Christian Zimmermann
<zimmermach@gmail.com> wrote:
>
> ---
>  Makefile.am                                |  8 +++
>  tools/bluez4_conversion/convert_config.sh  | 89 ++++++++++++++++++++++++++++++
>  tools/bluez4_conversion/convert_devices.sh |  3 +
>  3 files changed, 100 insertions(+)
>  create mode 100755 tools/bluez4_conversion/convert_config.sh
>  create mode 100644 tools/bluez4_conversion/convert_devices.sh

The permission of the convert_config.sh look incorrect, besides that
we normally avoid having extra directories so I would put them under
tools, or better yet scripts since these are not written in C. Id also
don't want to make them specific to a version so they might carry over
other all the legacy formats and always convert to the latest, for
that reason perhaps we should have unit test for the conversion tools.

> diff --git a/Makefile.am b/Makefile.am
> index 0b26ccc3e..6dc5711d9 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -477,6 +477,8 @@ endif
>
>  EXTRA_DIST += $(manual_pages:.1=.txt)
>
> +EXTRA_DIST += tools/bluez4_conversion/convert_config.sh tools/bluez4_conversion/convert_devices.sh
> +
>  DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles --enable-library \
>                                                 --enable-health \
>                                                 --enable-midi \
> @@ -535,3 +537,9 @@ clean-local:
>         -find $(top_builddir) -name "*.gcda" -delete
>         $(RM) -r lib/bluetooth
>  endif
> +
> +BLUEZ4_CONFIG_CONVERSION = $(srcdir)/tools/bluez4_conversion/convert_config.sh
> +BLUEZ4_DEVICE_CONVERSION = $(srcdir)/tools/bluez4_conversion/convert_devices.sh
> +install-exec-hook:
> +       $(BLUEZ4_CONFIG_CONVERSION)
> +       $(BLUEZ4_DEVICE_CONVERION)
> \ No newline at end of file
> diff --git a/tools/bluez4_conversion/convert_config.sh b/tools/bluez4_conversion/convert_config.sh
> new file mode 100755
> index 000000000..477e18fae
> --- /dev/null
> +++ b/tools/bluez4_conversion/convert_config.sh
> @@ -0,0 +1,89 @@
> +!/bin/sh
> +
> +CONFIG_DIR="/var/lib/bluetooth"
> +
> +convert_on_mode()
> +{
> +    config_file=$1
> +    #Read on_mode from config file
> +    on_mode=$( cat $config_file | grep -Po 'mode \K(.*)')
> +    if [ ! -z "$on_mode" ]
> +    then
> +        if [ $on_mode == "discoverable" ]
> +        then
> +            #Write on mode to new INI file
> +            echo -e "Discoverable=true" >> settings
> +        else
> +            #Write on mode to new INI file
> +            echo -e "Discoverable=false" >> settings
> +        fi
> +    else
> +        echo "On mode not found"
> +    fi
> +}
> +
> +convert_discoverable_timeout()
> +{
> +    config_file=$1
> +    #Read discoverable timeout from config file
> +    discoverable_timeout=$( cat $config_file | grep -Po 'discovto \K([0-9]+)')
> +    if [ ! -z "$discoverable_timeout" ]
> +    then
> +        #Write discoverable timeout to new INI file
> +        echo -e "DiscoverableTimeout=$discoverable_timeout" >> settings
> +    else
> +        echo "Discoverable Timeout not found"
> +    fi
> +}
> +
> +convert_pairable_timeout()
> +{
> +    config_file=$1
> +    #Read pairable timeout from config file
> +    pairable_timeout=$( cat $config_file | grep -Po 'pairto \K([0-9]+)')
> +    if [ ! -z "$pairable_timeout" ]
> +    then
> +        #Write discoverable timeout to new INI file
> +        echo -e "PairableTimeout=$pairable_timeout" >> settings
> +    else
> +        echo "Pairable Timeout not found"
> +    fi
> +}
> +
> +convert_local_name()
> +{
> +    config_file=$1
> +    #Read local name from config file
> +    local_name=$( cat $config_file | grep -Po 'name \K(.*)')
> +    if [ ! -z "$local_name" ]
> +    then
> +        #Write local_name to new INI file
> +        echo -e "Alias=$local_name" >> settings
> +    else
> +        echo "Local name not found"
> +    fi
> +}
> +
> +###
> +# Main script body
> +###
> +for entry in `ls $CONFIG_DIR`; do
> +    cd $CONFIG_DIR
> +    cd $entry
> +    if [ -f "config" ]
> +    then
> +        if [ ! -f "settings" ]
> +        then
> +            #Create new settings INI file
> +            touch settings
> +            echo -e "[General]" >> settings
> +            convert_pairable_timeout config
> +            convert_discoverable_timeout config
> +            convert_on_mode config
> +            convert_local_name config
> +            rm config
> +        else
> +            echo "Settings already available"
> +        fi
> +    fi
> +done
> diff --git a/tools/bluez4_conversion/convert_devices.sh b/tools/bluez4_conversion/convert_devices.sh
> new file mode 100644
> index 000000000..a8a013b06
> --- /dev/null
> +++ b/tools/bluez4_conversion/convert_devices.sh
> @@ -0,0 +1,3 @@
> +# TODO
> +# This file is intended for replacing the conversion of Bluez4 device datas when upgrading to Bluez5 INI format
> +# This is currently checked at every bluetoothd startup in src/adapter.c
> \ No newline at end of file
> --
> 2.11.0
>


-- 
Luiz Augusto von Dentz

      parent reply	other threads:[~2018-11-27 11:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26 16:49 [PATCH BlueZ 1/2] Added config conversion for Bluez4 as shell script during install Christian Zimmermann
2018-11-26 16:49 ` [PATCH BlueZ 2/2] Removed obsolete conversion functions, since the conversion is now done once " Christian Zimmermann
2018-11-27 11:50 ` Luiz Augusto von Dentz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABBYNZJ72pzUOG2ukReBVNhwiwLFW7Zzts96HvF+WHHdKWfBEQ@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=zimmermach@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.