#!/bin/bash MSG_ERROR_BLUE="Conecte el dispositivo Bluetooth." MSG_INFO_MESSAGE="Pulse los botones 1 y 2 del mando y cuando las luces azules parpadeen, pulse Aceptar" MSG_MIDDLE_MESSAGE="Vuelva a pulsar los botones 1 y 2 del mando y cuando las luces azules parpadeen, pulse Aceptar de nuevo" TMP_FILE="$(mktemp /tmp/fileWib.XXXXX)" MAC_ADDRESS="" _test_bluetooth() { rc=0 lsusb -v 2>/dev/null 2>/dev/null | grep -i "bluetooth" || rc=1 if [ $rc -eq 1 ] ; then zenity --error --text="$MSG_ERROR_BLUE" exit 1 fi } _show_info_startup() { zenity --info --text="$MSG_INFO_MESSAGE" } _show_info_middle() { zenity --info --text="$MSG_MIDDLE_MESSAGE" } _getting_mac() { if [ $(lswm | tee $TMP_FILE | egrep "^([0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}$" ) ]; then MAC_ADDRESS=$(cat $TMP_FILE | egrep "^([0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}$") echo "[DEBUG]: MAC is detected: $MAC_ADDRESS" else echo "[DEBUG]: MAC is NOT detected" zenity --error --text="Dispositivo no detectado, reintentelo" exit 1 fi } _start_wminput() { echo "[DEBUG]: MAC is $MAC_ADDRESS and launch wminput" _show_info_startup rc=0 wminput -c ir_ptr $MAC_ADDRESS || rc=1 if [ $rc -eq 1 ]; then zenity --error --text="Dispositivo no detectado, reintentelo" exit 1 else zenity --info --text="Su dispositivo ha sido capturado" fi } # MAIN _test_bluetooth _show_info_startup _getting_mac _start_wminput exit 0