Replace mkringlist.sh with mkringlist.php

Move from tftpboot/ringtones to Tools
Use PHP instead of Bash to simplify output
Eliminate executables in tftpboot
This commit is contained in:
steve-lad
2021-07-14 15:09:06 +02:00
parent b214fee18a
commit 9fc70cdbca
3 changed files with 95 additions and 83 deletions

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env bash
outfile=ringlist.xml
echo -e "<CiscoIPPhoneRingList>" >$outfile
if [ ! -z "`ls *.pcm 2>/dev/null`" ]; then
for filename in *.pcm;do
basename=`basename ${filename} .pcm`
echo -e "\t<Ring>" >>$outfile
echo -e "\t\t<DisplayName>${basename}</DisplayName>" >>$outfile
echo -e "\t\t<FileName>ringtones/${filename}</FileName>" >>$outfile
echo -e "\t</Ring>" >>$outfile
done
fi
if [ ! -z "`ls *.raw 2>/dev/null`" ]; then
for filename in *.raw;do
basename=`basename ${filename} .raw`
echo -e "\t<Ring>" >>$outfile
echo -e "\t\t<DisplayName>${basename}</DisplayName>" >>$outfile
echo -e "\t\t<FileName>ringtones/${filename}</FileName>" >>$outfile
echo -e "\t</Ring>" >>$outfile
done
fi
echo -e "</CiscoIPPhoneRingList>" >>$outfile

View File

@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CiscoIPPhoneRingList> <CiscoIPPhoneRingList>
<Ring> <Ring>
<DisplayName>drums1</DisplayName> <DisplayName>drums1</DisplayName>

34
tools/mkringlist.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
//Usage: php mkringlist.php;
function createCats($currDirPos){
$xml = '';
if(is_dir($currDirPos)){
// Remove unix ./..
foreach (array_diff(scandir($currDirPos),array('.','..')) as $subDir) {
//remove link information
$subDir = explode(' ', $subDir);
$displayName = explode('.',$subDir[0]);
$fileName = str_replace('../tftpboot/','',$currDirPos) .'/'. $subDir[0];
if (in_array($displayName[1], array('pcm','raw'))) {
$xml .= "<Ring><DisplayName>{$displayName[0]}</DisplayName><FileName>{$fileName}</FileName></Ring>";
}
}
}
return $xml;
}
function saveXml($xml, $filename) {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.'<CiscoIPPhoneRingList>' . $xml . '</CiscoIPPhoneRingList>';
$dom = new \DOMDocument("1.0");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml);
$dom->save($filename);
}
saveXml(createCats('../tftpboot/ringtones'),'../tftpboot/ringtones/ringlist.xml');
?>