freedombone/src/freedombone-app-icecast

762 lines
27 KiB
Plaintext
Raw Normal View History

2017-11-25 20:11:05 +01:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2017-11-25 20:11:05 +01:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2017-11-25 20:11:05 +01:00
#
# Icecast application
#
2017-11-26 20:25:13 +01:00
# Notes: An attempt was made to get ices2 running with systemd, but that
# was very unsuccessful. Instead there's a hacky cron entry which
# starts icecast2 and ices2 if necessary
#
2017-11-25 20:11:05 +01:00
# License
# =======
#
2018-01-25 19:35:39 +01:00
# Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
2017-11-25 20:11:05 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
VARIANTS='full'
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
SHOW_ICANN_ADDRESS_ON_ABOUT=0
ICECAST_DOMAIN_NAME=
ICECAST_CODE=
ICECAST_PORT=8005
ICECAST_ONION_PORT=8146
ICECAST_DIR=/icestream
ICECAST_PLAYLIST_FILE=/etc/ices2/playlist.txt
ICECAST_LOGIN_TEXT=$"Icecast login"
icecast_variables=(MY_USERNAME
2017-11-25 22:57:59 +01:00
MY_EMAIL_ADDRESS
2017-11-25 20:11:05 +01:00
ONION_ONLY
ICECAST_DOMAIN_NAME
ICECAST_CODE
DEFAULT_LANGUAGE)
2017-11-26 20:58:40 +01:00
function icecast_rescan {
if [ -d $ICECAST_DIR ]; then
if [ -f $ICECAST_PLAYLIST_FILE ]; then
rm $ICECAST_PLAYLIST_FILE
fi
icecast_add_file_to_playlist $ICECAST_DIR
fi
}
2017-11-25 20:11:05 +01:00
function icecast_update_daemon {
2017-11-25 22:06:27 +01:00
systemctl stop icecast2
if [ -f /etc/init.d/icecast2 ]; then
rm /etc/init.d/icecast2
fi
2018-02-27 15:11:56 +01:00
{ echo '#!/bin/sh';
echo "kill \$(pidof ices2)";
echo 'systemctl stop icecast2'; } > /usr/bin/stop_icecast
2017-11-26 20:25:13 +01:00
chmod +x /usr/bin/stop_icecast
# Note that the sleep here actually is important
2018-02-27 15:11:56 +01:00
{ echo '#!/bin/bash';
echo "isrunning=\$(ps aux | grep ices2)";
echo "if [[ \"\$isrunning\" != *\"ices-playlist\"* ]]; then";
echo ' systemctl start icecast2';
echo ' sleep 3';
echo ' cd /etc/ices2';
echo ' ices2 ices-playlist.xml';
echo 'fi'; } > /usr/bin/start_icecast
2017-11-26 20:25:13 +01:00
chmod +x /usr/bin/start_icecast
2018-02-27 15:11:56 +01:00
{ echo '[Unit]';
echo 'Description=Icecast';
echo 'After=network.target';
echo 'After=tor.service';
echo '';
echo '[Service]';
echo 'User=icecast2';
echo 'Group=icecast';
echo 'ExecStart=/usr/bin/icecast2 -c /etc/icecast2/icecast.xml';
echo 'Restart=on-failure';
echo 'RestartSec=10';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/icecast2.service
2017-11-25 22:06:27 +01:00
2017-11-26 20:25:13 +01:00
chown -R icecast2:icecast /etc/ices2
chown -R icecast2:icecast /etc/icecast2
2017-11-25 20:11:05 +01:00
systemctl daemon-reload
2017-11-25 22:06:27 +01:00
systemctl enable icecast2
2017-11-26 20:25:13 +01:00
if ! grep -q "start_icecast" /etc/crontab; then
2018-02-21 22:40:30 +01:00
cron_add_mins 1 '/usr/bin/start_icecast 2> /dev/null'
2017-11-26 20:25:13 +01:00
fi
2017-11-25 20:11:05 +01:00
}
function change_password_icecast {
curr_username="$1"
new_user_password="$2"
2017-11-26 20:25:13 +01:00
stop_icecast
2017-11-25 20:11:05 +01:00
sed -i -e "s|<source-password>[^<]*</source-password>|<source-password>$new_user_password</source-password>|" \
-e "s|<relay-password>[^<]*</relay-password>|<relay-password>$new_user_password</relay-password>|" \
-e "s|<admin-password>[^<]*</admin-password>|<admin-password>$new_user_password</admin-password>|" \
/etc/icecast2/icecast.xml
2017-11-26 20:25:13 +01:00
sed -i "s|<password>.*|<password>${new_user_password}</password>|g" /etc/ices2/ices-playlist.xml
2017-11-25 20:11:05 +01:00
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$curr_username" -a icecast -p "$new_user_password"
2017-11-26 20:25:13 +01:00
start_icecast
2017-11-25 20:11:05 +01:00
}
function logging_on_icecast {
echo -n ''
}
function logging_off_icecast {
echo -n ''
}
function reconfigure_icecast {
echo -n ''
}
function icecast_convert_files {
clear
2018-02-27 15:11:56 +01:00
cd "${1}" || exit 2346824648
2017-11-25 20:11:05 +01:00
echo $'Converting any mp3 files to ogg format'
2017-11-25 23:21:52 +01:00
find . -type f -name '*.mp3' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${0/%mp3/ogg}"' '{}' \;
find . -name "*.mp3" -print0 | xargs -0 rm -f
2017-11-25 20:11:05 +01:00
echo $'Converting any mp4 files to ogv format'
2017-11-25 23:21:52 +01:00
find . -type f -name '*.mp4' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${0/%mp3/ogv}"' '{}' \;
find . -name "*.mp4" -print0 | xargs -0 rm -f
2017-11-25 20:11:05 +01:00
2017-11-25 22:06:27 +01:00
chown -R icecast2:icecast $ICECAST_DIR
2017-11-25 20:11:05 +01:00
}
function icecast_add_file_to_playlist {
2018-02-27 15:11:56 +01:00
files_dir="${1}"
if [ ! -d "$files_dir" ]; then
2017-11-25 20:11:05 +01:00
return
fi
echo $'Adding ogg files to playlist'
2018-02-27 15:11:56 +01:00
find "$files_dir" -type f -name '*.ogg' -print0 | while read -r -d $'\0' file; do
2017-11-25 20:11:05 +01:00
if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
echo "$file" >> $ICECAST_PLAYLIST_FILE
fi
done
echo $'Adding ogv files to playlist'
2018-02-27 15:11:56 +01:00
find "$files_dir" -type f -name '*.ogv' -print0 | while read -r -d $'\0' file; do
2017-11-25 20:11:05 +01:00
if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
echo "$file" >> $ICECAST_PLAYLIST_FILE
fi
done
2017-11-25 22:06:27 +01:00
chown icecast2:icecast $ICECAST_PLAYLIST_FILE
2017-11-26 20:25:13 +01:00
stop_icecast
start_icecast
2017-11-25 20:11:05 +01:00
}
function icecast_import_from_directory {
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
dialog --title "Choose a directory containing stream files" --dselect "/home/$MY_USERNAME/" 30 60 2> "$data"
selected_dir=$(cat "$data")
rm -f "$data"
2017-11-25 20:11:05 +01:00
if [[ "$selected_dir" == "$ICECAST_DIR" ]]; then
return
fi
2018-02-27 15:11:56 +01:00
if [ ! -d "$selected_dir" ]; then
2017-11-25 20:11:05 +01:00
return
fi
if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
return
fi
if [[ "$selected_dir" == "/home/$MY_USERNAME/."* ]]; then
return
fi
if [[ "$selected_dir" == *"/Maildir" || "$selected_dir" == *"/Sync" ]]; then
return
fi
dialog --title $"Import stream files directory into Icecast" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-02-27 15:11:56 +01:00
--yesno $"\\nImport the directory:\\n\\n $selected_dir" 12 75
2017-11-25 20:11:05 +01:00
sel=$?
case $sel in
1) return;;
255) return;;
esac
if [ ! -d $ICECAST_DIR ]; then
mkdir -p $ICECAST_DIR
fi
dest_dir=$(basename "$selected_dir")
# shellcheck disable=SC2086
mv $selected_dir $ICECAST_DIR
2017-11-25 20:11:05 +01:00
2018-02-27 15:11:56 +01:00
icecast_convert_files "$ICECAST_DIR/$dest_dir"
icecast_add_file_to_playlist "$ICECAST_DIR/$dest_dir"
2017-11-25 20:11:05 +01:00
dialog --title $"Import stream files directory into Icecast" \
--msgbox $"Import success" 6 40
}
function icecast_import_from_usb {
clear
detect_usb_drive
2018-02-27 15:11:56 +01:00
if [ ! -b "$USB_DRIVE" ]; then
2017-11-25 20:11:05 +01:00
dialog --title $"Import stream files from USB drive" --msgbox $'No USB drive found' 6 50
return
fi
2018-02-27 15:11:56 +01:00
backup_mount_drive "${USB_DRIVE}"
if [ ! -d "$USB_MOUNT$ICECAST_DIR" ]; then
2017-11-25 20:11:05 +01:00
dialog --title $"Import stream files from USB drive" --msgbox $'No stream files directory found on USB drive' 6 50
2018-02-27 15:11:56 +01:00
backup_unmount_drive "${USB_DRIVE}"
2017-11-25 20:11:05 +01:00
fi
2018-03-03 12:49:17 +01:00
cp -ru "$USB_MOUNT$ICECAST_DIR/"* $ICECAST_DIR
2018-02-27 15:11:56 +01:00
backup_unmount_drive "${USB_DRIVE}"
2017-11-25 20:11:05 +01:00
icecast_convert_files $ICECAST_DIR
dialog --title $"Import stream files from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
}
function icecast_export_to_usb {
clear
detect_usb_drive
2018-02-27 15:11:56 +01:00
if [ ! -b "$USB_DRIVE" ]; then
2017-11-25 20:11:05 +01:00
dialog --title $"Export stream files to USB drive" --msgbox $'No USB drive found' 6 50
return
fi
2018-02-27 15:11:56 +01:00
backup_mount_drive "${USB_DRIVE}"
if [ ! -d "$USB_MOUNT$ICECAST_DIR" ]; then
mkdir -p "$USB_MOUNT$ICECAST_DIR"
2017-11-25 20:11:05 +01:00
fi
2018-03-03 12:49:17 +01:00
cp -ru "$ICECAST_DIR/"* "$USB_MOUNT$ICECAST_DIR"
2018-02-27 15:11:56 +01:00
backup_unmount_drive "${USB_DRIVE}"
2017-11-25 20:11:05 +01:00
dialog --title $"Export stream files to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
}
function icecast_format_drive {
detect_usb_drive
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
2017-11-25 20:11:05 +01:00
dialog --title $"Format USB drive $USB_DRIVE for stream file storage" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-02-27 15:11:56 +01:00
--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
2017-11-25 20:11:05 +01:00
sel=$?
case $sel in
2018-02-27 15:11:56 +01:00
1) rm -f "$data"
return;;
255) rm -f "$data"
return;;
2017-11-25 20:11:05 +01:00
esac
2018-02-27 15:11:56 +01:00
rm -f "$data"
2017-11-25 20:11:05 +01:00
clear
echo ''
echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
echo ''
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-format" "$USB_DRIVE"
2017-11-25 20:11:05 +01:00
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
}
function icecast_edit_playlist {
editor $ICECAST_PLAYLIST_FILE
2017-11-26 20:25:13 +01:00
stop_icecast
start_icecast
2017-11-25 20:11:05 +01:00
}
function icecast_change_login {
2018-02-27 15:11:56 +01:00
read_config_param "$MY_USERNAME"
ICECAST_USER_PASSWORD=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser)
2017-11-25 20:11:05 +01:00
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
2017-11-25 20:11:05 +01:00
dialog --title $"Change Icecast stream visitor login" \
--backtitle $"Freedombone Control Panel" \
2018-02-27 15:11:56 +01:00
--inputbox $"Enter the new login password for stream visitors" 8 60 "$ICECAST_USER_PASSWORD" 2>"$data"
2017-11-25 20:11:05 +01:00
sel=$?
case $sel in
2018-02-27 15:11:56 +01:00
0) ICECAST_USER_PASSWORD=$(<"$data")
2017-11-25 20:11:05 +01:00
if [[ "$ICECAST_USER_PASSWORD" != *' '* ]]; then
if [ ${#ICECAST_USER_PASSWORD} -gt 8 ]; then
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser -p "$ICECAST_USER_PASSWORD"
2017-11-25 20:11:05 +01:00
dialog --title $"Change Icecast stream visitor login" \
--msgbox $"Password changed to $ICECAST_USER_PASSWORD" 6 75
fi
fi
;;
esac
2018-02-27 15:11:56 +01:00
rm -f "$data"
2017-11-25 20:11:05 +01:00
}
function icecast_enable_login {
dialog --title $"Enable Icecast login" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-02-27 15:11:56 +01:00
--yesno $"\\nDo you want to add a login so that random web users can't access your stream?" 10 60
2017-11-25 20:11:05 +01:00
sel=$?
case $sel in
0) if grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/icecast
systemctl restart nginx
fi
2018-02-27 15:11:56 +01:00
read_config_param "$MY_USERNAME"
ICECAST_USER_PASSWORD=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser)
2017-11-25 20:11:05 +01:00
dialog --title $"Enable Icecast login" \
--msgbox $"Icecast logins are now enabled with the password $ICECAST_USER_PASSWORD" 6 65
ICECAST_USER_PASSWORD=
;;
1) if ! grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
sed -i 's|auth_basic|#auth_basic|g' /etc/nginx/sites-available/icecast
systemctl restart nginx
fi
dialog --title $"Disable Icecast login" \
--msgbox $"Icecast logins are now disabled. Anyone can access your stream." 6 65
;;
esac
}
2017-11-26 22:06:03 +01:00
function icecast_set_stream_name {
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
2017-11-26 22:06:03 +01:00
dialog --backtitle $"Freedombone Control Panel" \
--title $"Change Icecast stream details" \
2018-02-27 15:11:56 +01:00
--form "\\n" 8 60 4 \
2017-11-26 22:06:03 +01:00
$"Stream name:" 1 1 "Example stream name" 1 18 40 1000 \
$"Description:" 2 1 "A short description of your stream" 2 18 40 1000 \
$"Genre:" 3 1 "Example genre" 3 18 40 1000 \
2018-02-27 15:11:56 +01:00
2> "$data"
2017-11-26 22:06:03 +01:00
sel=$?
case $sel in
2018-02-27 15:11:56 +01:00
1) rm -f "$data"
return;;
255) rm -f "$data"
return;;
2017-11-26 22:06:03 +01:00
esac
2018-02-27 15:11:56 +01:00
stream_name=$(sed -n 1p < "$data")
stream_description=$(sed -n 2p < "$data")
stream_genre=$(sed -n 3p < "$data")
2017-11-26 22:06:03 +01:00
if [ ${#stream_name} -gt 2 ]; then
sed -i "s|<name>.*|<name>${stream_name}</name>|g" /etc/ices2/ices-playlist.xml
fi
if [ ${#stream_description} -gt 2 ]; then
sed -i "s|<description>.*|<description>${stream_description}</description>|g" /etc/ices2/ices-playlist.xml
fi
if [ ${#stream_genre} -gt 2 ]; then
sed -i "s|<genre>.*|<genre>${stream_genre}</genre>|g" /etc/ices2/ices-playlist.xml
fi
2018-02-27 15:11:56 +01:00
rm -f "$data"
2017-11-26 22:06:03 +01:00
stop_icecast
start_icecast
}
2017-11-27 12:02:16 +01:00
function icecast_set_maximum_streams {
2018-02-27 15:11:56 +01:00
data=$(mktemp 2>/dev/null)
2017-11-27 12:02:16 +01:00
dialog --title $"Set the maximum clients" \
--backtitle $"Freedombone Control Panel" \
2018-02-27 15:11:56 +01:00
--inputbox $"Maximum number of clients" 8 40 "10" 2>"$data"
2017-11-27 12:02:16 +01:00
sel=$?
case $sel in
0)
2018-02-27 15:11:56 +01:00
max_clients=$(<"$data")
2017-11-27 12:02:16 +01:00
if [ ${#max_clients} -gt 0 ]; then
if [[ "$max_clients" != *' '* ]]; then
2018-02-27 15:11:56 +01:00
# shellcheck disable=SC2076
if [[ "$max_clients" =~ '^[0-9]+$' ]] ; then
2017-11-27 12:02:16 +01:00
sed -i "s|<clients>.*|<clients>${max_clients}</clients>|g" /etc/icecast2/icecast.xml
stop_icecast
start_icecast
dialog --title $"Set the maximum clients" \
2018-02-27 15:11:56 +01:00
--msgbox $"\\nMaximum Icecast clients was set to ${max_clients}" 8 50
2017-11-27 12:02:16 +01:00
fi
fi
fi
;;
esac
2018-02-27 15:11:56 +01:00
rm -f "$data"
2017-11-27 12:02:16 +01:00
}
2017-11-25 20:11:05 +01:00
function configure_interactive_icecast {
2018-04-04 14:03:03 +02:00
W=(1 $"Import stream files from directory"
2 $"Import stream files from USB drive"
3 $"Format a USB drive for stream file storage"
4 $"Export stream files to USB drive"
5 $"Manually edit playlist"
6 $"Enable login for stream visitors"
7 $"Change password for stream visitors"
8 $"Re-scan playlist"
9 $"Restart stream"
10 $"Set Stream Name/Description/Genre"
11 $"Set maximum number of clients/streams")
2017-11-25 20:11:05 +01:00
while true
do
2018-04-04 14:03:03 +02:00
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Icecast" --menu $"Choose an operation, or ESC to exit:" 20 60 11 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
break
fi
case $selection in
2017-11-25 20:11:05 +01:00
1) icecast_import_from_directory;;
2) icecast_import_from_usb;;
2017-11-27 13:21:06 +01:00
3) icecast_format_drive;;
2017-11-27 13:21:48 +01:00
4) icecast_export_to_usb;;
5) icecast_edit_playlist;;
2017-11-25 20:11:05 +01:00
6) icecast_enable_login;;
7) icecast_change_login;;
2017-11-26 20:58:40 +01:00
8) clear
2017-11-26 21:02:04 +01:00
echo $'Rescanning Icecast playlist'
2017-11-26 20:58:40 +01:00
icecast_rescan;;
2017-11-26 21:02:04 +01:00
9) clear
echo $'Restarting Icecast stream'
2017-11-26 22:06:03 +01:00
stop_icecast
2017-11-26 21:02:04 +01:00
start_icecast;;
2017-11-26 22:06:03 +01:00
10) icecast_set_stream_name;;
2017-11-27 12:02:16 +01:00
11) icecast_set_maximum_streams;;
2017-11-25 20:11:05 +01:00
esac
done
}
function upgrade_icecast {
icecast_update_daemon
}
function backup_local_icecast {
if [ ! -d $ICECAST_DIR ]; then
return
fi
stop_icecast
2017-11-25 20:11:05 +01:00
cp /etc/nginx/.icepasswd $ICECAST_DIR
cp /etc/ices2/ices-playlist.xml $ICECAST_DIR
2017-11-25 20:11:05 +01:00
function_check backup_directory_to_usb
backup_directory_to_usb $ICECAST_DIR icecast
rm $ICECAST_DIR/.icepasswd
start_icecast
2017-11-25 20:11:05 +01:00
}
function restore_local_icecast {
if [ ! -d $ICECAST_DIR ]; then
return
fi
stop_icecast
2017-11-25 20:11:05 +01:00
temp_restore_dir=/root/tempicecast
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir icecast
if [ -d $temp_restore_dir$ICECAST_DIR ]; then
cp -r $temp_restore_dir$ICECAST_DIR $ICECAST_DIR/
else
cp -r $temp_restore_dir/* $ICECAST_DIR/*
fi
cp $ICECAST_DIR/.icepasswd /etc/nginx/.icepasswd
rm $ICECAST_DIR/.icepasswd
cp $ICECAST_DIR/ices-playlist.xml /etc/ices2
rm $ICECAST_DIR/ices-playlist.xml
2017-11-25 22:06:27 +01:00
chown -R icecast2:icecast $ICECAST_DIR
chown -R icecast2:icecast /etc/ices2
2017-11-25 20:11:05 +01:00
start_icecast
2017-11-25 20:11:05 +01:00
rm -rf $temp_restore_dir
}
function backup_remote_icecast {
if [ ! -d $ICECAST_DIR ]; then
return
fi
stop_icecast
2017-11-25 20:11:05 +01:00
cp /etc/nginx/.icepasswd $ICECAST_DIR
cp /etc/ices2/ices-playlist.xml $ICECAST_DIR
2017-11-25 20:11:05 +01:00
function_check backup_directory_to_friend
backup_directory_to_friend $ICECAST_DIR icecast
rm $ICECAST_DIR/.icepasswd
start_icecast
2017-11-25 20:11:05 +01:00
}
function restore_remote_icecast {
if [ ! -d $ICECAST_DIR ]; then
return
fi
stop_icecast
2017-11-25 20:11:05 +01:00
temp_restore_dir=/root/tempicecast
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir icecast
if [ -d $temp_restore_dir$ICECAST_DIR ]; then
cp -r $temp_restore_dir$ICECAST_DIR $ICECAST_DIR/
else
cp -r $temp_restore_dir/* $ICECAST_DIR/*
fi
cp $ICECAST_DIR/.icepasswd /etc/nginx/.icepasswd
rm $ICECAST_DIR/.icepasswd
cp $ICECAST_DIR/ices-playlist.xml /etc/ices2
rm $ICECAST_DIR/ices-playlist.xml
2017-11-25 22:06:27 +01:00
chown -R icecast2:icecast $ICECAST_DIR
2017-11-25 20:11:05 +01:00
start_icecast
2017-11-25 20:11:05 +01:00
rm -rf $temp_restore_dir
}
function remove_icecast {
nginx_dissite icecast
2017-11-26 20:25:13 +01:00
sed -i '/start_icecast/d' /etc/crontab
stop_icecast
systemctl disable icecast2
rm /etc/systemd/system/icecast2.service
rm /usr/bin/start_icecast
rm /usr/bin/stop_icecast
2017-11-25 20:11:05 +01:00
if [ -f /etc/nginx/sites-available/icecast ]; then
rm /etc/nginx/sites-available/icecast
fi
if [ -d /var/www/icecast ]; then
rm -rf /var/www/icecast
fi
apt-get -yq remove --purge icecast2
2017-11-26 20:25:13 +01:00
if [ -d /etc/icecast2 ]; then
rm -rf /etc/icecast2
fi
if [ -d /etc/ices2 ]; then
rm -rf /etc/ices2
fi
2017-11-26 22:35:30 +01:00
function_check remove_onion_service
remove_onion_service icecast ${ICECAST_ONION_PORT}
2018-02-27 15:11:56 +01:00
sed -i '/icecast/d' "$COMPLETION_FILE"
2017-11-25 20:11:05 +01:00
}
function install_icecast {
apt-get -yq install software-properties-common debconf-utils
apt-get -yq update
debconf-set-selections <<< "icecast2 icecast2/icecast-setup boolean false"
2017-11-26 22:35:30 +01:00
apt-get -yq install icecast2
2017-11-26 22:37:03 +01:00
apt-get -yq install ices2 ffmpeg apache2-utils
2017-11-25 20:11:05 +01:00
if [ ! -f /etc/icecast2/icecast.xml ]; then
echo $'Icecast not installed'
exit 7923528
fi
2018-02-27 15:11:56 +01:00
if [ ! "${ICECAST_PASSWORD}" ]; then
if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
ICECAST_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
2017-11-25 20:11:05 +01:00
else
2018-02-27 15:11:56 +01:00
ICECAST_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
2017-11-25 20:11:05 +01:00
fi
fi
2017-11-25 22:38:32 +01:00
ICECAST_ONION_HOSTNAME=$(add_onion_service icecast 80 ${ICECAST_ONION_PORT})
2017-11-25 20:11:05 +01:00
sed -i -e "s|<source-password>[^<]*</source-password>|<source-password>$ICECAST_PASSWORD</source-password>|" \
-e "s|<relay-password>[^<]*</relay-password>|<relay-password>$ICECAST_PASSWORD</relay-password>|" \
-e "s|<admin-password>[^<]*</admin-password>|<admin-password>$ICECAST_PASSWORD</admin-password>|" \
-e "s|<hostname>[^<]*</hostname>|<hostname>$ICECAST_ONION_HOSTNAME</hostname>|" \
/etc/icecast2/icecast.xml
sed -i "s|<clients>.*|<clients>10</clients>|g" /etc/icecast2/icecast.xml
2017-11-25 20:11:05 +01:00
sed -i "s|<port>.*|<port>$ICECAST_PORT</port>|g" /etc/icecast2/icecast.xml
2017-11-25 22:57:59 +01:00
sed -i "s|<admin-user>.*|<admin-user>$MY_USERNAME</admin-user>|g" /etc/icecast2/icecast.xml
sed -i "s|<admin>.*|<admin>$MY_EMAIL_ADDRESS</admin>|g" /etc/icecast2/icecast.xml
sed -i "s|<location>.*|<location>The Interwebs</location>|g" /etc/icecast2/icecast.xml
2017-11-26 20:25:13 +01:00
#sed -i 's|<!-- <bind-address>.*|<bind-address>127.0.0.1</bind-address>|g' /etc/icecast2/icecast.xml
2017-11-25 20:11:05 +01:00
if [ ! -d /var/www/icecast/htdocs ]; then
mkdir -p /var/www/icecast/htdocs
fi
icecast_nginx_site=/etc/nginx/sites-available/icecast
2018-02-27 15:11:56 +01:00
{ echo 'server {';
echo " listen 127.0.0.1:$ICECAST_ONION_PORT default_server;";
echo " server_name $ICECAST_ONION_HOSTNAME;";
echo '';
echo ' # Logs';
echo ' access_log /dev/null;';
echo ' error_log /dev/null;';
echo '';
echo ' location / {'; } > $icecast_nginx_site
2017-11-25 20:11:05 +01:00
function_check nginx_limits
2018-02-27 15:11:56 +01:00
nginx_limits "$ICECAST_ONION_HOSTNAME" '15m'
{ echo " proxy_pass http://localhost:$ICECAST_PORT;";
echo " #auth_basic \"${ICECAST_LOGIN_TEXT}\";";
echo ' #auth_basic_user_file /etc/nginx/.icepasswd;';
echo ' }';
echo '}'; } >> $icecast_nginx_site
2017-11-25 20:11:05 +01:00
if [ ! -d /var/log/ices ]; then
mkdir -p /var/log/ices
fi
if [ ! -d /etc/ices2 ]; then
mkdir -p /etc/ices2
fi
2018-02-27 15:11:56 +01:00
{ echo '<?xml version="1.0"?>';
echo '<ices>';
echo ' <!-- run in background -->';
echo ' <background>1</background>';
echo ' <!-- where logs, etc go. -->';
echo ' <logpath>/var/log/ices</logpath>';
echo ' <logfile>ices.log</logfile>';
echo ' <!-- 1=error,2=warn,3=info,4=debug -->';
echo ' <loglevel>1</loglevel>';
echo ' <!-- set this to 1 to log to the console instead of to the file above -->';
echo ' <consolelog>0</consolelog>';
echo '';
echo ' <!-- optional filename to write process id to -->';
echo ' <!-- <pidfile>/home/ices/ices.pid</pidfile> -->';
echo '';
echo ' <stream>';
echo ' <!-- metadata used for stream listing (not currently used) -->';
echo ' <metadata>';
echo ' <name>Example stream name</name>';
echo ' <genre>Example genre</genre>';
echo ' <description>A short description of your stream</description>';
echo ' </metadata>';
echo '';
echo ' <!-- input module';
echo '';
echo ' The module used here is the playlist module - it has ';
echo ' "submodules" for different types of playlist. There are';
echo ' two currently implemented, "basic", which is a simple';
echo ' file-based playlist, and "script" which invokes a command';
echo ' to returns a filename to start playing. -->';
echo '';
echo ' <input>';
echo ' <module>playlist</module>';
echo ' <param name="type">basic</param>';
echo " <param name=\"file\">$ICECAST_PLAYLIST_FILE</param>";
echo ' <!-- random play -->';
echo ' <param name="random">0</param>';
echo ' <!-- if the playlist get updated that start at the beginning -->';
echo ' <param name="restart-after-reread">0</param>';
echo ' <!-- if set to 1 , plays once through, then exits. -->';
echo ' <param name="once">0</param>';
echo ' </input>';
echo '';
echo ' <!-- Stream instance';
echo ' You may have one or more instances here. This allows you to ';
echo ' send the same input data to one or more servers (or to different';
echo ' mountpoints on the same server). Each of them can have different';
echo ' parameters. This is primarily useful for a) relaying to multiple';
echo ' independent servers, and b) encoding/reencoding to multiple';
echo ' bitrates.';
echo ' If one instance fails (for example, the associated server goes';
echo ' down, etc), the others will continue to function correctly.';
echo ' This example defines two instances as two mountpoints on the';
echo ' same server. -->';
echo ' <instance>';
echo ' <!-- Server details:';
echo ' You define hostname and port for the server here, along with';
echo ' the source password and mountpoint. -->';
echo ' <hostname>localhost</hostname>';
echo " <port>$ICECAST_PORT</port>";
echo " <password>$ICECAST_PASSWORD</password>";
echo ' <mount>/example1.ogg</mount>';
echo ' <!-- Reconnect parameters:';
echo ' When something goes wrong (e.g. the server crashes, or the';
echo ' network drops) and ices disconnects from the server, these';
echo ' control how often it tries to reconnect, and how many times';
echo ' it tries to reconnect. Delay is in seconds.';
echo ' If you set reconnectattempts to -1, it will continue ';
echo ' indefinately. Suggest setting reconnectdelay to a large value';
echo ' if you do this.';
echo ' -->';
echo ' <reconnectdelay>2</reconnectdelay>';
echo ' <reconnectattempts>5</reconnectattempts> ';
echo '';
echo ' <!-- maxqueuelength:';
echo ' This describes how long the internal data queues may be. This';
echo ' basically lets you control how much data gets buffered before';
echo ' ices decides it cant send to the server fast enough, and ';
echo ' either shuts down or flushes the queue (dropping the data)';
echo ' and continues. ';
echo ' For advanced users only.';
echo ' -->';
echo ' <maxqueuelength>80</maxqueuelength>';
echo '';
echo ' <!-- Live encoding/reencoding:';
echo ' Currrently, the parameters given here for encoding MUST';
echo ' match the input data for channels and sample rate. That ';
echo ' restriction will be relaxed in the future.';
echo ' Remove this section if you dont want your files getting reencoded.';
echo ' -->';
echo ' <encode> ';
echo ' <nominal-bitrate>64000</nominal-bitrate>';
echo ' <samplerate>22050</samplerate>';
echo ' <channels>1</channels>';
echo ' </encode>';
echo ' </instance>';
echo '';
echo ' </stream>';
echo '</ices>'; } > /etc/ices2/ices-playlist.xml
2017-11-25 20:11:05 +01:00
sed -i 's|ENABLE=.*|ENABLE=true|g' /etc/default/icecast2
if [ ! -d $ICECAST_DIR ]; then
mkdir $ICECAST_DIR
fi
2017-11-25 22:06:27 +01:00
chown -R icecast2:icecast $ICECAST_DIR
2017-11-25 20:11:05 +01:00
# create a password for users
2018-02-27 15:11:56 +01:00
ICECAST_USER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
2017-11-25 20:11:05 +01:00
if grep -q "$MY_USERNAME:" /etc/nginx/.icepasswd; then
sed -i "/$MY_USERNAME:/d" /etc/nginx/.icepasswd
fi
2018-02-27 15:11:56 +01:00
echo "$ICECAST_USER_PASSWORD" | htpasswd -i -s -c /etc/nginx/.icepasswd "$MY_USERNAME"
2017-11-25 20:11:05 +01:00
if [ ! -f /etc/nginx/.icepasswd ]; then
echo $'/etc/nginx/.icepasswd not found'
exit 73528235
fi
2018-02-27 15:11:56 +01:00
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecast -p "$ICECAST_PASSWORD"
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser -p "$ICECAST_USER_PASSWORD"
2017-11-25 20:11:05 +01:00
2017-11-25 22:06:27 +01:00
groupadd icecast
useradd -c "Icecast system account" -d /etc/icecast2 -m -r -g icecast icecast2
2017-11-25 20:11:05 +01:00
icecast_update_daemon
nginx_ensite icecast
systemctl restart nginx
2017-11-26 20:58:40 +01:00
icecast_rescan
2017-11-26 20:25:13 +01:00
start_icecast
2017-11-25 20:11:05 +01:00
APP_INSTALLED=1
}
function install_interactive_icecast {
install_icecast
}
# NOTE: deliberately no exit 0