freedombone-app-icecast 27KB

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