[PATCH BlueZ 1/2] Added config conversion for Bluez4 as shell script during install

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 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

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux