You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.1 KiB
Bash

#!/bin/bash
#ajw v1.10 - jukebox for asterisk wizard
#Jay Moore/NQ4T - https://git.pickmy.org/dewdude/ajw
#Twitter: @Music_OnHold
#Licensed under GPL-3.0-or-later
# Works like this:
# Put all your albums in your Asterisk sounds directory: /var/lib/asterisk/sounds/en/(jukeboxesdir)/jukebox root/album/track#.ulaw
# Run script, enter prompts. (jukeboxesdir) is an optional sub-folder in case your jukeboxes are in a extra subdirectory
# Copy .conf, include in extensions.conf, assign extension.
# asd defines the default location of your asterisk sounds
asd=/var/lib/asterisk/sounds/en/
# main context configuation
setup() {
printf "[$name-main]\nexten = s,1,Answer()\nsame =n,Set(VOLUME(TX)=$vol)\nsame = n,Set(c=$name-main)\nsame = n(return),Set(m=1)\nsame = n(loop),Background($rootfolder/$introfile)\n"
[ -n "$delay" ] && printf "same = n,WaitExten($delay)\n"
printf "same = n,Set(m=\$[\${m} + 1])\nsame = n,GoToIf(\$[\"\${m}\" > \"$loop\"]?loop)\nsame = n(goodbye),Background($rootfolder/$goodbye)\nsame = n,Hangup()\n\n"
} >> $name-juke.conf
# album selections
album() {
printf "exten = _%02dXX,1,Set(aa=$rootfolder/$folder)\n" $a
[ "$lz" -eq 0 ] && printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" = \"00\"]?8track-player,#$tc,1)\n" || printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" = \"00\"]?8track-player,*$tc,1)\n"
printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" > \"$limit\"]?9999)\n"
[ "$lz" -eq 0 ] && printf "same = n,GoToIf(\$[\"\${EXTEN:-2}\" < \"10\"]?cart-player,#\${EXTEN:-1},1)\n"
printf "same = n,GoTo(cart-player,*\${EXTEN:-2},1)\nsame = 9999,Playback(option-is-invalid)\nsame =n,GoTo($name-main,s,1)\n\n"
} >> $name-juke.conf
# main
printf "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n |a|j|w| - asterisk jukebox wizard\n version 1.10 - Jay Moore/NQ4T\n https://git.pickmy.org/dewdude/jaw\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\n\n"
printf "Pick a name/identifier for this jukebox: "
read name
printf "\nEnter the folder your jukebox roots live under. (Leave blank if they're under $ast): "
read sd
printf "\nEnter the name of the root folder your jukebox albums live under: "
read rootfolder
printf "\nEnter the filename of your menu/intro: "
read introfile
printf "\nHow many times do you want it to play? "
read loop
printf "\nHow many seconds between intro play? (Leave blank for no delay): "
read delay
printf "\nEnter the filename of your exit file: "
read goodbye
printf "\nEnter a channel volume. (I recommend -3, also the default if you leave this blank): "
read vol
[ -n "$vol" ] && vol="-3"
printf "\nWriting Basic Configuration.\n\nAuto-Generating Albums\n\n"
[ -n "$sd" ] && rootfolder=$sd/$rootfolder
setup;
# album context loop
dir=$(ls $asd/$rootfolder -l | awk '/^d/ {print $9}')
a=0
for folder in $dir
do
limit=$(ls $asd/$rootfolder/$folder -l | grep "ulaw" | wc -l)
tracks=$((limit + 1))
tc=$(printf "%02d" $tracks)
ld=$(ls $asd/$rootfolder/$folder -l | grep "ulaw" | awk '{print $9}' | awk '/^0/')
[ -z "$ld" ] && lz=0 || lz=1
album;
a=$((a + 1))
done
printf "\n\nDone.\n\n\nYour jukebox is located at $name-juke.conf.\n"
printf "Make sure to include it and the player conf in your dial plan somewhere.\n\n\n\n"