Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
radio_mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
azbyka
radio_mpd
Commits
3d93be34
Commit
3d93be34
authored
Mar 14, 2024
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
radio.sh: rewrite with socket support
parent
593b1c22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
47 deletions
+77
-47
radio.sh
radio.sh
+77
-47
No files found.
radio.sh
View file @
3d93be34
#!/bin/bash
export
LC_ALL
=
ru_RU.UTF-8
# get current port
source
./.port
ROOT_DIRECTORY
=
./
$2
ROOT_DIRECTORY
=
$(
pwd
)
fatal
()
{
echo
"
$*
"
>
&2
exit
1
}
function
usage
()
{
echo
"Использование : ./radio.sh <параметр> <имя>
...
...
@@ -9,55 +19,65 @@ function usage() {
-m - управление потоком
-d - удаление потока
-l - список запущенных потоков
-
p - порт потока"
-
r - перезапустить поток
"
}
function
get_port
()
{
local
CONFIG_FILE
=
./
$1
.mpd.conf
local
PORT
=
`
cat
$CONFIG_FILE
|
grep
port |
awk
'{ print $2 ; exit; }'
|
tr
-d
\"
`
echo
$PORT
elem_control
()
{
local
conf
local bind
conf
=
$ROOT_DIRECTORY
/
$1
.mpd.conf
[
-s
"
$conf
"
]
||
fatal
"
$conf
is missed"
# if socket
bind
=
`
cat
$conf
|
grep
"^bind_to_address"
|
awk
'{ print $2 ; exit; }'
|
tr
-d
\"
`
[
-e
"
$bind
"
]
&&
echo
"--host
$bind
"
&&
return
# if port
bind
=
`
cat
$conf
|
grep
"^port"
|
awk
'{ print $2 ; exit; }'
|
tr
-d
\"
`
echo
"-p
$bind
"
}
function
create_stream
()
{
local
CONFIG_FILE
=
./
$1
.mpd.conf
local
ROOT_DIRECTORY
=
$2
local
ABS_PATH_TO_CFG
=
`
pwd
`
/
$1
.mpd.conf
local
STREAM_DIRECTORY
=
$ROOT_DIRECTORY
/
$1
local
ABS_PATH_TO_CFG
=
$STREAM_DIRECTORY
/
$1
.mpd.conf
if
[[
!
-f
./
$1
.mpd.conf
]]
;
then
cp
-p
./template.mpd.conf
$
CONFIG_FILE
mkdir
-p
$
ROOT
_DIRECTORY
/playlists
mkdir
$ROOT
_DIRECTORY
/Music
touch
$
ROOT
_DIRECTORY
/mpd.log
touch
$
ROOT
_DIRECTORY
/mpdstate
touch
$
ROOT
_DIRECTORY
/mpd.db
touch
$
ROOT
_DIRECTORY
/mpd.pid
if
[[
!
-f
$ABS_PATH_TO_CFG
]]
;
then
cp
-p
./template.mpd.conf
$
ABS_PATH_TO_CFG
mkdir
-p
$
STREAM
_DIRECTORY
/playlists
#mkdir $STREAM
_DIRECTORY/Music
touch
$
STREAM
_DIRECTORY
/mpd.log
touch
$
STREAM
_DIRECTORY
/mpdstate
touch
$
STREAM
_DIRECTORY
/mpd.db
touch
$
STREAM
_DIRECTORY
/mpd.pid
sed
-i
's?#1?'
`
pwd
`
/
$1
'?'
./
$1
.mpd.conf
sed
-i
"s/#2/
$PORT
/g"
./
$1
.mpd.conf
sed
-i
"s/#3/
$1
/g"
./
$1
.mpd.conf
chown
-R
icecastradio
$
ROOT
_DIRECTORY
chgrp
-R
icecastradio
$
ROOT
_DIRECTORY
chmod
-R
777
$
ROOT
_DIRECTORY
chmod
+x
$
ROOT
_DIRECTORY
/playlists
chown
-R
icecastradio
$
STREAM
_DIRECTORY
chgrp
-R
icecastradio
$
STREAM
_DIRECTORY
chmod
-R
777
$
STREAM
_DIRECTORY
chmod
+x
$
STREAM
_DIRECTORY
/playlists
# Systemd configuration
cp
template.service /etc/systemd/system/
$1
.service
sed
-i
's?#1?'
$ABS_PATH_TO_CFG
'?'
/etc/systemd/system/
$1
.service
echo
PORT
=
$((
PORT+1
))
>
./.port
serv daemon-reload
serv start
$1
serv
enable
/etc/systemd/system/
$1
.service
serv
$1
on
# Enable playlist repeat
mpc
-q
-p
`
cat
$CONFIG_FILE
|
grep
port |
awk
'{ print $2 ; exit; }'
|
tr
-d
\"
`
repeat on
mpc
-q
$(
elem_control
$STREAM_NAME
)
repeat on
echo
"Файлы конфигураций cозданы успешно !"
echo
"Запущен mpd-поток под названием :
$1
по адресу : radio.azbyka.ru:80
00
/
$1
"
echo
"Для начала работы требуется обновить базу данных mpd"
echo
"Для работ
а
с потоком : ./radio -m
$1
"
echo
"Запущен mpd-поток под названием :
$1
по адресу : radio.azbyka.ru:80/
$1
"
#
echo "Для начала работы требуется обновить базу данных mpd"
echo
"Для работ
ы
с потоком : ./radio -m
$1
"
else
echo
-e
"Поток
\"
$1
\"
уже создан.
\n
Для работы с ним : ./radio -m
$1
"
fi
...
...
@@ -65,48 +85,58 @@ function create_stream() {
}
function
manage_stream
()
{
local
STREAM_NAME
=
$2
ncmpc
-p
`
$1
$STREAM_NAME
`
local
STREAM_NAME
=
$1
echo
"ncmpc
$(
elem_control
$STREAM_NAME
)
"
ncmpc
$(
elem_control
$STREAM_NAME
)
}
function
delete_stream
(){
systemctl stop
$1
rm
-drf
./
$1
*
rm
-f
/etc/systemd/system/
$1
.service
serv daemon-reload
serv stop
$1
rm
-rvf
./
$1
*
sudo rm
-f
/etc/systemd/system/
$1
.service
sudo
systemctl daemon-reload
}
function
restart_stream
(){
mpc
$(
elem_control
$1
)
update
serv restart
$1
}
function
get_streams
()
{
URL
=
http://radio.azbyka.ru/json.xsl
URL
=
http://radio
2
.azbyka.ru/json.xsl
CONTENT
=
$(
curl
$URL
2>&1 /dev/null
)
ACTIVE_STREAMS
=
`
grep
-oP
'(?<=/).*?(?=")'
<<<
$CONTENT
`
echo
"Список запущенных потоков:"
for
ELEM
in
$ACTIVE_STREAMS
;
do
local
ELEM_STATUS
=
`
mpc
-p
\`
./radio.sh
-p
$ELEM
\`
|
awk
'{print $1}'
|
sed
-n
2p
`
ELEM_STATUS
=
$(
mpc
$(
elem_control
$ELEM
)
|
awk
'{print $1}'
|
sed
-n
2p
)
echo
-e
"
$ELEM
\t
$ELEM_STATUS
"
done
echo
}
while
getopts
"c:m:d:lh
p
:"
opt
while
getopts
"c:m:d:lh
r
:"
opt
do
case
"
${
opt
}
"
in
c
)
create_stream
$2
$ROOT_DIRECTORY
;;
m
)
manage_stream get_port
$2
;;
d
)
delete_stream
$2
;;
l
)
get_streams
;;
h
)
usage
$ROOT_DIRECTORY
;;
p
)
get_port
$2
;;
*
)
usage
$ROOT_DIRECTORY
;;
c
)
create_stream
$2
;;
m
)
manage_stream
$2
;;
d
)
delete_stream
$2
;;
l
)
get_streams
;;
r
)
restart_stream
$2
;;
h
)
usage
;;
p
)
elem_control
$2
;;
*
)
usage
;;
esac
exit
done
usage
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment