From 3bd8b80e8c141174f62e93a8d7096d6bb96d4871 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Thu, 5 Jan 2012 15:43:54 -0500 Subject: Improve device handling a bit for Nut package --- config/nut/nut.inc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/config/nut/nut.inc b/config/nut/nut.inc index 6b7b02ac..28ff3999 100644 --- a/config/nut/nut.inc +++ b/config/nut/nut.inc @@ -94,18 +94,26 @@ function before_form_nut($pkg) { /* return available serial ports */ - $handle = popen('dmesg | grep \'^sio[0-9]: type\'','r'); - $read = fread($handle, 2096); - pclose($handle); - /* explode at the newlines */ - $read = explode("\n",$read); - - /* parse resulting text */ - foreach($read as $line) { - if($line!= '') { - $names[] = 'ttyd'.$line{3}.' (COM'.($line{3}+1).')'; - $values[] = '/dev/ttyd'.$line{3}; + $serial_types = array("sio", "cua", "tty"); + $ignore_files = array(".lock", ".init"); + + foreach($serial_types as $st) { + $devices = glob("/dev/{$st}*"); + foreach($devices as $line) { + if($line != '') { + $ignore = false; + foreach($ignore_files as $if) { + if(strstr($line, $if)) { + $ignore = true; + continue; + } + } + if($ignore == false) { + $names[] = str_replace("/dev/", "", $line); + $values[] = $line; + } + } } } -- cgit v1.2.3