freedombone-app-icecast 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Icecast application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS='full'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. SHOW_ICANN_ADDRESS_ON_ABOUT=0
  34. ICECAST_DOMAIN_NAME=
  35. ICECAST_CODE=
  36. ICECAST_PORT=8005
  37. ICECAST_ONION_PORT=8146
  38. ICECAST_DIR=/icestream
  39. ICECAST_PLAYLIST_FILE=/etc/ices2/playlist.txt
  40. ICECAST_LOGIN_TEXT=$"Icecast login"
  41. icecast_variables=(MY_USERNAME
  42. ONION_ONLY
  43. ICECAST_DOMAIN_NAME
  44. ICECAST_CODE
  45. DEFAULT_LANGUAGE)
  46. function icecast_update_daemon {
  47. systemctl stop icecast2
  48. if [ -f /etc/init.d/icecast2 ]; then
  49. rm /etc/init.d/icecast2
  50. fi
  51. echo '[Unit]' > /etc/systemd/system/icecast2.service
  52. echo 'Description=Icecast' >> /etc/systemd/system/icecast2.service
  53. echo 'After=network.target' >> /etc/systemd/system/icecast2.service
  54. echo 'After=tor.service' >> /etc/systemd/system/icecast2.service
  55. echo '' >> /etc/systemd/system/icecast2.service
  56. echo '[Service]' >> /etc/systemd/system/icecast2.service
  57. echo 'User=icecast2' >> /etc/systemd/system/icecast2.service
  58. echo 'Group=icecast' >> /etc/systemd/system/icecast2.service
  59. echo "ExecStart=/usr/bin/icecast2 -c /etc/icecast2/icecast.xml" >> /etc/systemd/system/icecast2.service
  60. echo 'Restart=on-failure' >> /etc/systemd/system/icecast2.service
  61. echo 'RestartSec=10' >> /etc/systemd/system/icecast2.service
  62. echo '' >> /etc/systemd/system/icecast2.service
  63. echo '[Install]' >> /etc/systemd/system/icecast2.service
  64. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/icecast2.service
  65. echo '[Unit]' > /etc/systemd/system/ices2.service
  66. echo 'Description=Icecast' >> /etc/systemd/system/ices2.service
  67. echo 'After=network.target' >> /etc/systemd/system/ices2.service
  68. echo 'After=tor.service' >> /etc/systemd/system/ices2.service
  69. echo 'After=icecast2.service' >> /etc/systemd/system/ices2.service
  70. echo '' >> /etc/systemd/system/ices2.service
  71. echo '[Service]' >> /etc/systemd/system/ices2.service
  72. echo 'User=icecast2' >> /etc/systemd/system/ices2.service
  73. echo 'Group=icecast' >> /etc/systemd/system/ices2.service
  74. echo "ExecStart=/usr/bin/ices2 /etc/ices2/ices-playlist.xml" >> /etc/systemd/system/ices2.service
  75. echo 'Restart=on-failure' >> /etc/systemd/system/ices2.service
  76. echo 'RestartSec=10' >> /etc/systemd/system/ices2.service
  77. echo '' >> /etc/systemd/system/ices2.service
  78. echo '[Install]' >> /etc/systemd/system/ices2.service
  79. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ices2.service
  80. systemctl daemon-reload
  81. systemctl enable icecast2
  82. systemctl enable ices2
  83. systemctl restart icecast2
  84. systemctl restart ices2
  85. }
  86. function change_password_icecast {
  87. curr_username="$1"
  88. new_user_password="$2"
  89. sed -i -e "s|<source-password>[^<]*</source-password>|<source-password>$new_user_password</source-password>|" \
  90. -e "s|<relay-password>[^<]*</relay-password>|<relay-password>$new_user_password</relay-password>|" \
  91. -e "s|<admin-password>[^<]*</admin-password>|<admin-password>$new_user_password</admin-password>|" \
  92. /etc/icecast2/icecast.xml
  93. ${PROJECT_NAME}-pass -u "$curr_username" -a icecast -p "$new_user_password"
  94. systemctl restart icecast2
  95. }
  96. function logging_on_icecast {
  97. echo -n ''
  98. }
  99. function logging_off_icecast {
  100. echo -n ''
  101. }
  102. function reconfigure_icecast {
  103. echo -n ''
  104. }
  105. function icecast_convert_files {
  106. clear
  107. cd ${1}
  108. echo $'Converting any mp3 files to ogg format'
  109. find . -type f -name '*.mp3' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${f/%mp3/ogg}' '{}' \;
  110. echo $'Converting any mp4 files to ogv format'
  111. find . -type f -name '*.mp4' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${f/%mp4/ogv}' '{}' \;
  112. chown -R icecast2:icecast $ICECAST_DIR
  113. }
  114. function icecast_add_file_to_playlist {
  115. files_dir=${1}
  116. if [ ! -d $files_dir ]; then
  117. return
  118. fi
  119. echo $'Adding ogg files to playlist'
  120. find $files_dir -type f -name '*.ogg' -print0 | while read -d $'\0' file; do
  121. if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
  122. echo "$file" >> $ICECAST_PLAYLIST_FILE
  123. fi
  124. done
  125. echo $'Adding ogv files to playlist'
  126. find $files_dir -type f -name '*.ogv' -print0 | while read -d $'\0' file; do
  127. if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
  128. echo "$file" >> $ICECAST_PLAYLIST_FILE
  129. fi
  130. done
  131. chown icecast2:icecast $ICECAST_PLAYLIST_FILE
  132. systemctl restart icecast2
  133. }
  134. function icecast_import_from_directory {
  135. data=$(tempfile 2>/dev/null)
  136. dialog --title "Choose a directory containing stream files" --dselect /home/$MY_USERNAME/ 30 60 2> $data
  137. selected_dir=$(cat $data)
  138. rm $data
  139. if [[ "$selected_dir" == "$ICECAST_DIR" ]]; then
  140. return
  141. fi
  142. if [ ! -d $selected_dir ]; then
  143. return
  144. fi
  145. if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
  146. return
  147. fi
  148. if [[ "$selected_dir" == "/home/$MY_USERNAME/."* ]]; then
  149. return
  150. fi
  151. if [[ "$selected_dir" == *"/Maildir" || "$selected_dir" == *"/Sync" ]]; then
  152. return
  153. fi
  154. dialog --title $"Import stream files directory into Icecast" \
  155. --backtitle $"Freedombone Control Panel" \
  156. --defaultno \
  157. --yesno $"\nImport the directory:\n\n $selected_dir" 12 75
  158. sel=$?
  159. case $sel in
  160. 1) return;;
  161. 255) return;;
  162. esac
  163. if [ ! -d $ICECAST_DIR ]; then
  164. mkdir -p $ICECAST_DIR
  165. fi
  166. dest_dir=$(basename "$selected_dir")
  167. mv "$selected_dir" $ICECAST_DIR
  168. icecast_convert_files $ICECAST_DIR/$dest_dir
  169. icecast_add_file_to_playlist $ICECAST_DIR/$dest_dir
  170. dialog --title $"Import stream files directory into Icecast" \
  171. --msgbox $"Import success" 6 40
  172. }
  173. function icecast_import_from_usb {
  174. clear
  175. detect_usb_drive
  176. if [ ! -b $USB_DRIVE ]; then
  177. dialog --title $"Import stream files from USB drive" --msgbox $'No USB drive found' 6 50
  178. return
  179. fi
  180. backup_mount_drive ${USB_DRIVE}
  181. if [ ! -d $USB_MOUNT$ICECAST_DIR ]; then
  182. dialog --title $"Import stream files from USB drive" --msgbox $'No stream files directory found on USB drive' 6 50
  183. backup_unmount_drive ${USB_DRIVE}
  184. fi
  185. cp -ru $USB_MOUNT$ICECAST_DIR/* $ICECAST_DIR
  186. backup_unmount_drive ${USB_DRIVE}
  187. icecast_convert_files $ICECAST_DIR
  188. dialog --title $"Import stream files from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
  189. }
  190. function icecast_export_to_usb {
  191. clear
  192. detect_usb_drive
  193. if [ ! -b $USB_DRIVE ]; then
  194. dialog --title $"Export stream files to USB drive" --msgbox $'No USB drive found' 6 50
  195. return
  196. fi
  197. backup_mount_drive ${USB_DRIVE}
  198. if [ ! -d $USB_MOUNT$ICECAST_DIR ]; then
  199. mkdir -p $USB_MOUNT$ICECAST_DIR
  200. fi
  201. cp -ru $ICECAST_DIR/* $USB_MOUNT$ICECAST_DIR
  202. backup_unmount_drive ${USB_DRIVE}
  203. dialog --title $"Export stream files to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
  204. }
  205. function icecast_format_drive {
  206. detect_usb_drive
  207. data=$(tempfile 2>/dev/null)
  208. trap "rm -f $data" 0 1 2 5 15
  209. dialog --title $"Format USB drive $USB_DRIVE for stream file storage" \
  210. --backtitle $"Freedombone Control Panel" \
  211. --defaultno \
  212. --yesno $"\nPlease confirm that you wish to format drive\n\n ${USB_DRIVE}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
  213. sel=$?
  214. case $sel in
  215. 1) return;;
  216. 255) return;;
  217. esac
  218. rm $data
  219. clear
  220. echo ''
  221. echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
  222. echo ''
  223. ${PROJECT_NAME}-format $USB_DRIVE
  224. dialog --title $"Format USB drive $USB_DRIVE for stream file storage" --msgbox $'Format complete. You may now export stream files or remove the USB drive' 6 50
  225. }
  226. function icecast_edit_playlist {
  227. editor $ICECAST_PLAYLIST_FILE
  228. systemctl restart icecast2
  229. }
  230. function icecast_change_login {
  231. read_config_param $MY_USERNAME
  232. ICECAST_USER_PASSWORD=$(${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser)
  233. data=$(tempfile 2>/dev/null)
  234. trap "rm -f $data" 0 1 2 5 15
  235. dialog --title $"Change Icecast stream visitor login" \
  236. --backtitle $"Freedombone Control Panel" \
  237. --inputbox $"Enter the new login password for stream visitors" 8 60 "$ICECAST_USER_PASSWORD" 2>$data
  238. sel=$?
  239. case $sel in
  240. 0) ICECAST_USER_PASSWORD=$(<$data)
  241. if [[ "$ICECAST_USER_PASSWORD" != *' '* ]]; then
  242. if [ ${#ICECAST_USER_PASSWORD} -gt 8 ]; then
  243. ${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser -p $ICECAST_USER_PASSWORD
  244. dialog --title $"Change Icecast stream visitor login" \
  245. --msgbox $"Password changed to $ICECAST_USER_PASSWORD" 6 75
  246. fi
  247. fi
  248. ;;
  249. esac
  250. rm $data
  251. }
  252. function icecast_enable_login {
  253. dialog --title $"Enable Icecast login" \
  254. --backtitle $"Freedombone Control Panel" \
  255. --defaultno \
  256. --yesno $"\nDo you want to add a login so that random web users can't access your stream?" 10 60
  257. sel=$?
  258. case $sel in
  259. 0) if grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
  260. sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/icecast
  261. systemctl restart nginx
  262. fi
  263. read_config_param $MY_USERNAME
  264. ICECAST_USER_PASSWORD=$(${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser)
  265. dialog --title $"Enable Icecast login" \
  266. --msgbox $"Icecast logins are now enabled with the password $ICECAST_USER_PASSWORD" 6 65
  267. ICECAST_USER_PASSWORD=
  268. ;;
  269. 1) if ! grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
  270. sed -i 's|auth_basic|#auth_basic|g' /etc/nginx/sites-available/icecast
  271. systemctl restart nginx
  272. fi
  273. dialog --title $"Disable Icecast login" \
  274. --msgbox $"Icecast logins are now disabled. Anyone can access your stream." 6 65
  275. ;;
  276. esac
  277. }
  278. function configure_interactive_icecast {
  279. while true
  280. do
  281. data=$(tempfile 2>/dev/null)
  282. trap "rm -f $data" 0 1 2 5 15
  283. dialog --backtitle $"Freedombone Control Panel" \
  284. --title $"Icecast" \
  285. --radiolist $"Choose an operation:" 15 70 8 \
  286. 1 $"Import stream files from directory" off \
  287. 2 $"Import stream files from USB drive" off \
  288. 3 $"Manually edit playlist" off \
  289. 4 $"Export stream files to USB drive" off \
  290. 5 $"Format a USB drive for stream file storage" off \
  291. 6 $"Enable login for stream visitors" off \
  292. 7 $"Change password for stream visitors" off \
  293. 8 $"Exit" on 2> $data
  294. sel=$?
  295. case $sel in
  296. 1) break;;
  297. 255) break;;
  298. esac
  299. case $(cat $data) in
  300. 1) icecast_import_from_directory;;
  301. 2) icecast_import_from_usb;;
  302. 3) icecast_edit_playlist;;
  303. 4) icecast_export_to_usb;;
  304. 5) icecast_format_drive;;
  305. 6) icecast_enable_login;;
  306. 7) icecast_change_login;;
  307. 8) break;;
  308. esac
  309. done
  310. }
  311. function upgrade_icecast {
  312. icecast_update_daemon
  313. }
  314. function backup_local_icecast {
  315. if [ ! -d $ICECAST_DIR ]; then
  316. return
  317. fi
  318. systemctl stop icecast2
  319. cp /etc/nginx/.icepasswd $ICECAST_DIR
  320. function_check backup_directory_to_usb
  321. backup_directory_to_usb $ICECAST_DIR icecast
  322. rm $ICECAST_DIR/.icepasswd
  323. systemctl start icecast2
  324. }
  325. function restore_local_icecast {
  326. if [ ! -d $ICECAST_DIR ]; then
  327. return
  328. fi
  329. systemctl stop icecast2
  330. temp_restore_dir=/root/tempicecast
  331. function_check restore_directory_from_usb
  332. restore_directory_from_usb $temp_restore_dir icecast
  333. if [ -d $temp_restore_dir$ICECAST_DIR ]; then
  334. cp -r $temp_restore_dir$ICECAST_DIR $ICECAST_DIR/
  335. else
  336. cp -r $temp_restore_dir/* $ICECAST_DIR/*
  337. fi
  338. cp $ICECAST_DIR/.icepasswd /etc/nginx/.icepasswd
  339. rm $ICECAST_DIR/.icepasswd
  340. chown -R icecast2:icecast $ICECAST_DIR
  341. systemctl start icecast2
  342. rm -rf $temp_restore_dir
  343. }
  344. function backup_remote_icecast {
  345. if [ ! -d $ICECAST_DIR ]; then
  346. return
  347. fi
  348. systemctl stop icecast2
  349. cp /etc/nginx/.icepasswd $ICECAST_DIR
  350. function_check backup_directory_to_friend
  351. backup_directory_to_friend $ICECAST_DIR icecast
  352. rm $ICECAST_DIR/.icepasswd
  353. systemctl start icecast2
  354. }
  355. function restore_remote_icecast {
  356. if [ ! -d $ICECAST_DIR ]; then
  357. return
  358. fi
  359. systemctl stop icecast2
  360. temp_restore_dir=/root/tempicecast
  361. function_check restore_directory_from_friend
  362. restore_directory_from_friend $temp_restore_dir icecast
  363. if [ -d $temp_restore_dir$ICECAST_DIR ]; then
  364. cp -r $temp_restore_dir$ICECAST_DIR $ICECAST_DIR/
  365. else
  366. cp -r $temp_restore_dir/* $ICECAST_DIR/*
  367. fi
  368. cp $ICECAST_DIR/.icepasswd /etc/nginx/.icepasswd
  369. rm $ICECAST_DIR/.icepasswd
  370. chown -R icecast2:icecast $ICECAST_DIR
  371. systemctl start icecast2
  372. rm -rf $temp_restore_dir
  373. }
  374. function remove_icecast {
  375. nginx_dissite icecast
  376. if [ -f /etc/nginx/sites-available/icecast ]; then
  377. rm /etc/nginx/sites-available/icecast
  378. fi
  379. if [ -d /var/www/icecast ]; then
  380. rm -rf /var/www/icecast
  381. fi
  382. apt-get -yq remove --purge icecast2
  383. }
  384. function install_icecast {
  385. apt-get -yq install software-properties-common debconf-utils
  386. apt-get -yq update
  387. debconf-set-selections <<< "icecast2 icecast2/icecast-setup boolean false"
  388. apt-get -yq install icecast2 ices2 ffmpeg apache2-utils
  389. if [ ! -f /etc/icecast2/icecast.xml ]; then
  390. echo $'Icecast not installed'
  391. exit 7923528
  392. fi
  393. if [ ! ${ICECAST_PASSWORD} ]; then
  394. if [ -f ${IMAGE_PASSWORD_FILE} ]; then
  395. ICECAST_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  396. else
  397. ICECAST_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  398. fi
  399. fi
  400. ICECAST_ONION_HOSTNAME=$(add_onion_service icecast ${ICECAST_PORT} ${ICECAST_ONION_PORT})
  401. sed -i -e "s|<source-password>[^<]*</source-password>|<source-password>$ICECAST_PASSWORD</source-password>|" \
  402. -e "s|<relay-password>[^<]*</relay-password>|<relay-password>$ICECAST_PASSWORD</relay-password>|" \
  403. -e "s|<admin-password>[^<]*</admin-password>|<admin-password>$ICECAST_PASSWORD</admin-password>|" \
  404. -e "s|<hostname>[^<]*</hostname>|<hostname>$ICECAST_ONION_HOSTNAME</hostname>|" \
  405. /etc/icecast2/icecast.xml
  406. sed -i "s|<port>.*|<port>$ICECAST_PORT</port>|g" /etc/icecast2/icecast.xml
  407. if [ ! -d /var/www/icecast/htdocs ]; then
  408. mkdir -p /var/www/icecast/htdocs
  409. fi
  410. icecast_nginx_site=/etc/nginx/sites-available/icecast
  411. echo 'server {' > $icecast_nginx_site
  412. echo " listen 127.0.0.1:$ICECAST_ONION_PORT default_server;" >> $icecast_nginx_site
  413. echo " server_name $ICECAST_ONION_HOSTNAME;" >> $icecast_nginx_site
  414. echo '' >> $icecast_nginx_site
  415. echo ' # Logs' >> $icecast_nginx_site
  416. echo ' access_log /dev/null;' >> $icecast_nginx_site
  417. echo ' error_log /dev/null;' >> $icecast_nginx_site
  418. echo '' >> $icecast_nginx_site
  419. echo ' location / {' >> $icecast_nginx_site
  420. function_check nginx_limits
  421. nginx_limits $ICECAST_ONION_HOSTNAME '15m'
  422. echo " proxy_pass http://localhost:$ICECAST_PORT;" >> $icecast_nginx_site
  423. echo " #auth_basic \"${ICECAST_LOGIN_TEXT}\";" >> $icecast_nginx_site
  424. echo ' #auth_basic_user_file /etc/nginx/.icepasswd;' >> $icecast_nginx_site
  425. echo ' }' >> $icecast_nginx_site
  426. echo '}' >> $icecast_nginx_site
  427. if [ ! -d /var/log/ices ]; then
  428. mkdir -p /var/log/ices
  429. fi
  430. if [ ! -d /etc/ices2 ]; then
  431. mkdir -p /etc/ices2
  432. fi
  433. echo '<?xml version="1.0"?>' > /etc/ices2/ices-playlist.xml
  434. echo '<ices>' >> /etc/ices2/ices-playlist.xml
  435. echo ' <!-- run in background -->' >> /etc/ices2/ices-playlist.xml
  436. echo ' <background>1</background>' >> /etc/ices2/ices-playlist.xml
  437. echo ' <!-- where logs, etc go. -->' >> /etc/ices2/ices-playlist.xml
  438. echo ' <logpath>/var/log/ices</logpath>' >> /etc/ices2/ices-playlist.xml
  439. echo ' <logfile>ices.log</logfile>' >> /etc/ices2/ices-playlist.xml
  440. echo ' <!-- 1=error,2=warn,3=info,4=debug -->' >> /etc/ices2/ices-playlist.xml
  441. echo ' <loglevel>1</loglevel>' >> /etc/ices2/ices-playlist.xml
  442. echo ' <!-- set this to 1 to log to the console instead of to the file above -->' >> /etc/ices2/ices-playlist.xml
  443. echo ' <consolelog>0</consolelog>' >> /etc/ices2/ices-playlist.xml
  444. echo '' >> /etc/ices2/ices-playlist.xml
  445. echo ' <!-- optional filename to write process id to -->' >> /etc/ices2/ices-playlist.xml
  446. echo ' <!-- <pidfile>/home/ices/ices.pid</pidfile> -->' >> /etc/ices2/ices-playlist.xml
  447. echo '' >> /etc/ices2/ices-playlist.xml
  448. echo ' <stream>' >> /etc/ices2/ices-playlist.xml
  449. echo ' <!-- metadata used for stream listing (not currently used) -->' >> /etc/ices2/ices-playlist.xml
  450. echo ' <metadata>' >> /etc/ices2/ices-playlist.xml
  451. echo ' <name>Example stream name</name>' >> /etc/ices2/ices-playlist.xml
  452. echo ' <genre>Example genre</genre>' >> /etc/ices2/ices-playlist.xml
  453. echo ' <description>A short description of your stream</description>' >> /etc/ices2/ices-playlist.xml
  454. echo ' </metadata>' >> /etc/ices2/ices-playlist.xml
  455. echo '' >> /etc/ices2/ices-playlist.xml
  456. echo ' <!-- input module' >> /etc/ices2/ices-playlist.xml
  457. echo '' >> /etc/ices2/ices-playlist.xml
  458. echo ' The module used here is the playlist module - it has ' >> /etc/ices2/ices-playlist.xml
  459. echo ' "submodules" for different types of playlist. There are' >> /etc/ices2/ices-playlist.xml
  460. echo ' two currently implemented, "basic", which is a simple' >> /etc/ices2/ices-playlist.xml
  461. echo ' file-based playlist, and "script" which invokes a command' >> /etc/ices2/ices-playlist.xml
  462. echo ' to returns a filename to start playing. -->' >> /etc/ices2/ices-playlist.xml
  463. echo '' >> /etc/ices2/ices-playlist.xml
  464. echo ' <input>' >> /etc/ices2/ices-playlist.xml
  465. echo ' <module>playlist</module>' >> /etc/ices2/ices-playlist.xml
  466. echo ' <param name="type">basic</param>' >> /etc/ices2/ices-playlist.xml
  467. echo ' <param name="file">playlist.txt</param>' >> /etc/ices2/ices-playlist.xml
  468. echo ' <!-- random play -->' >> /etc/ices2/ices-playlist.xml
  469. echo ' <param name="random">0</param>' >> /etc/ices2/ices-playlist.xml
  470. echo ' <!-- if the playlist get updated that start at the beginning -->' >> /etc/ices2/ices-playlist.xml
  471. echo ' <param name="restart-after-reread">0</param>' >> /etc/ices2/ices-playlist.xml
  472. echo ' <!-- if set to 1 , plays once through, then exits. -->' >> /etc/ices2/ices-playlist.xml
  473. echo ' <param name="once">0</param>' >> /etc/ices2/ices-playlist.xml
  474. echo ' </input>' >> /etc/ices2/ices-playlist.xml
  475. echo '' >> /etc/ices2/ices-playlist.xml
  476. echo ' <!-- Stream instance' >> /etc/ices2/ices-playlist.xml
  477. echo ' You may have one or more instances here. This allows you to ' >> /etc/ices2/ices-playlist.xml
  478. echo ' send the same input data to one or more servers (or to different' >> /etc/ices2/ices-playlist.xml
  479. echo ' mountpoints on the same server). Each of them can have different' >> /etc/ices2/ices-playlist.xml
  480. echo ' parameters. This is primarily useful for a) relaying to multiple' >> /etc/ices2/ices-playlist.xml
  481. echo ' independent servers, and b) encoding/reencoding to multiple' >> /etc/ices2/ices-playlist.xml
  482. echo ' bitrates.' >> /etc/ices2/ices-playlist.xml
  483. echo ' If one instance fails (for example, the associated server goes' >> /etc/ices2/ices-playlist.xml
  484. echo ' down, etc), the others will continue to function correctly.' >> /etc/ices2/ices-playlist.xml
  485. echo ' This example defines two instances as two mountpoints on the' >> /etc/ices2/ices-playlist.xml
  486. echo ' same server. -->' >> /etc/ices2/ices-playlist.xml
  487. echo ' <instance>' >> /etc/ices2/ices-playlist.xml
  488. echo ' <!-- Server details:' >> /etc/ices2/ices-playlist.xml
  489. echo ' You define hostname and port for the server here, along with' >> /etc/ices2/ices-playlist.xml
  490. echo ' the source password and mountpoint. -->' >> /etc/ices2/ices-playlist.xml
  491. echo ' <hostname>localhost</hostname>' >> /etc/ices2/ices-playlist.xml
  492. echo " <port>$ICECAST_PORT</port>" >> /etc/ices2/ices-playlist.xml
  493. echo " <password>$ICECAST_PASSWORD</password>" >> /etc/ices2/ices-playlist.xml
  494. echo ' <mount>/example1.ogg</mount>' >> /etc/ices2/ices-playlist.xml
  495. echo ' <!-- Reconnect parameters:' >> /etc/ices2/ices-playlist.xml
  496. echo ' When something goes wrong (e.g. the server crashes, or the' >> /etc/ices2/ices-playlist.xml
  497. echo ' network drops) and ices disconnects from the server, these' >> /etc/ices2/ices-playlist.xml
  498. echo ' control how often it tries to reconnect, and how many times' >> /etc/ices2/ices-playlist.xml
  499. echo ' it tries to reconnect. Delay is in seconds.' >> /etc/ices2/ices-playlist.xml
  500. echo ' If you set reconnectattempts to -1, it will continue ' >> /etc/ices2/ices-playlist.xml
  501. echo ' indefinately. Suggest setting reconnectdelay to a large value' >> /etc/ices2/ices-playlist.xml
  502. echo ' if you do this.' >> /etc/ices2/ices-playlist.xml
  503. echo ' -->' >> /etc/ices2/ices-playlist.xml
  504. echo ' <reconnectdelay>2</reconnectdelay>' >> /etc/ices2/ices-playlist.xml
  505. echo ' <reconnectattempts>5</reconnectattempts> ' >> /etc/ices2/ices-playlist.xml
  506. echo '' >> /etc/ices2/ices-playlist.xml
  507. echo ' <!-- maxqueuelength:' >> /etc/ices2/ices-playlist.xml
  508. echo ' This describes how long the internal data queues may be. This' >> /etc/ices2/ices-playlist.xml
  509. echo ' basically lets you control how much data gets buffered before' >> /etc/ices2/ices-playlist.xml
  510. echo ' ices decides it cant send to the server fast enough, and ' >> /etc/ices2/ices-playlist.xml
  511. echo ' either shuts down or flushes the queue (dropping the data)' >> /etc/ices2/ices-playlist.xml
  512. echo ' and continues. ' >> /etc/ices2/ices-playlist.xml
  513. echo ' For advanced users only.' >> /etc/ices2/ices-playlist.xml
  514. echo ' -->' >> /etc/ices2/ices-playlist.xml
  515. echo ' <maxqueuelength>80</maxqueuelength>' >> /etc/ices2/ices-playlist.xml
  516. echo '' >> /etc/ices2/ices-playlist.xml
  517. echo ' <!-- Live encoding/reencoding:' >> /etc/ices2/ices-playlist.xml
  518. echo ' Currrently, the parameters given here for encoding MUST' >> /etc/ices2/ices-playlist.xml
  519. echo ' match the input data for channels and sample rate. That ' >> /etc/ices2/ices-playlist.xml
  520. echo ' restriction will be relaxed in the future.' >> /etc/ices2/ices-playlist.xml
  521. echo ' Remove this section if you dont want your files getting reencoded.' >> /etc/ices2/ices-playlist.xml
  522. echo ' -->' >> /etc/ices2/ices-playlist.xml
  523. echo ' <encode> ' >> /etc/ices2/ices-playlist.xml
  524. echo ' <nominal-bitrate>64000</nominal-bitrate> <!-- bps. e.g. 64000 for 64 kbps -->' >> /etc/ices2/ices-playlist.xml
  525. echo ' <samplerate>44100</samplerate>' >> /etc/ices2/ices-playlist.xml
  526. echo ' <channels>2</channels>' >> /etc/ices2/ices-playlist.xml
  527. echo ' </encode>' >> /etc/ices2/ices-playlist.xml
  528. echo ' </instance>' >> /etc/ices2/ices-playlist.xml
  529. echo '' >> /etc/ices2/ices-playlist.xml
  530. echo ' </stream>' >> /etc/ices2/ices-playlist.xml
  531. echo '</ices>' >> /etc/ices2/ices-playlist.xml
  532. sed -i 's|ENABLE=.*|ENABLE=true|g' /etc/default/icecast2
  533. if [ ! -d $ICECAST_DIR ]; then
  534. mkdir $ICECAST_DIR
  535. fi
  536. chown -R icecast2:icecast $ICECAST_DIR
  537. # create a password for users
  538. ICECAST_USER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  539. if grep -q "$MY_USERNAME:" /etc/nginx/.icepasswd; then
  540. sed -i "/$MY_USERNAME:/d" /etc/nginx/.icepasswd
  541. fi
  542. echo "$ICECAST_USER_PASSWORD" | htpasswd -i -s -c /etc/nginx/.icepasswd $MY_USERNAME
  543. if [ ! -f /etc/nginx/.icepasswd ]; then
  544. echo $'/etc/nginx/.icepasswd not found'
  545. exit 73528235
  546. fi
  547. ${PROJECT_NAME}-pass -u $MY_USERNAME -a icecast -p "$ICECAST_PASSWORD"
  548. ${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser -p "$ICECAST_USER_PASSWORD"
  549. groupadd icecast
  550. useradd -c "Icecast system account" -d /etc/icecast2 -m -r -g icecast icecast2
  551. icecast_update_daemon
  552. nginx_ensite icecast
  553. systemctl restart nginx
  554. systemctl restart icecast2
  555. APP_INSTALLED=1
  556. }
  557. function install_interactive_icecast {
  558. install_icecast
  559. }
  560. # NOTE: deliberately no exit 0