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