luci-0.11: merge r9559 - r9569
[project/luci.git] / applications / luci-pbx / root / etc / init.d / pbx-asterisk
index fdd01d76be7781b0843f0f497d4c1276d1956d20..99663a971a43f2fee72210dfa85fe80575c33d93 100755 (executable)
 #    You should have received a copy of the GNU General Public License
 #    along with luci-pbx.  If not, see <http://www.gnu.org/licenses/>.
 
-. /etc/functions.sh
+. /lib/functions.sh
 
 START=60
 
 # Some global variables
 MODULENAME=pbx
 USERAGENT="PBX"
-DEFAULTOUTCNTXT=default-outgoing-call-context
-HANGUPCNTXT=hangup
+HANGUPCNTXT=hangup-call-context
 GTALKUNVL=unavailable
 
 ASTUSER=nobody
 ASTGROUP=nogroup
 ASTDIRSRECURSIVE="/var/run/asterisk /var/log/asterisk /var/spool/asterisk"
 ASTDIRS="/usr/lib/asterisk"
+ASTSOUNDSDIR="/usr/lib/asterisk/sounds"
 
 TEMPLATEDIR=/etc/${MODULENAME}-asterisk
+PBXSOUNDSDIR=$TEMPLATEDIR/sounds
 VMTEMPLATEDIR=/etc/${MODULENAME}-voicemail
+VMSOUNDSDIR=$VMTEMPLATEDIR/sounds
 ASTERISKDIR=/etc/asterisk
 WORKDIR=/tmp/$MODULENAME.$$
 MD5SUMSFILE=/tmp/$MODULENAME-sums.$$
@@ -576,6 +578,22 @@ pbx_cook_rtp_template()
             sed "s/|RTPEND|/$rtpend/"               > $WORKDIR/rtp.conf
 }
 
+# Links any sound files found in $PBXSOUNDSDIR and $VMSOUNDSDIR
+# into $ASTSOUNDSDIR for use by Asterisk. Does not overwrite files.
+pbx_link_sounds()
+{
+    mkdir -p $ASTSOUNDSDIR
+
+    for dir in $PBXSOUNDSDIR $VMSOUNDSDIR ; do
+        if [ -d $dir ] ; then
+            for f in $dir/* ; do
+                ln -s $f $ASTSOUNDSDIR 2>/dev/null
+            done
+        fi
+    done
+}
+
+
 # Makes sure the ownership of specified directories is proper.
 pbx_fix_ownership()
 {
@@ -601,7 +619,7 @@ pbx_configure_voicemail()
     config_get enabled global_voicemail enabled
 
     # First check if voicemail is enabled.
-    [ "$enabled" != "yes" ] && exit
+    [ "$enabled" != "yes" ] && return
 
     config_get global_timeout         global_voicemail global_timeout
     #config_get global_email_addresses global_voicemail global_email_addresses
@@ -665,16 +683,19 @@ start() {
     pbx_cook_sip_template
     pbx_cook_rtp_template
 
-    # Prepare sip.conf using settings from the "advanced" section.
+    # Prepare voicemail config.
     config_unset
     config_load ${MODULENAME}-voicemail
-    pbx_configure_voicemail    
+    pbx_configure_voicemail
 
     # Assemble the configuration, and copy changed files over.
     config_unset
     config_load ${MODULENAME}-advanced
     pbx_assemble_and_copy_config
 
+    # Link sound files
+    pbx_link_sounds
+
     # Enforce ownership of specified files and directories.
     pbx_fix_ownership
 }