Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
# Deprecated because there are no DLNA clients within F-droid
# and Android is the main reason that DLNA was useful
#
#
# 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/>.
SHOW_ON_ABOUT=0
SHOW_CLEARNET_ADDRESS_ON_ABOUT=0
SHOW_DOMAIN_IN_WEBADMIN=0
Bob Mottram
committed
DLNA_PORT=1900
DLNA_PRESENTATION_PORT=8200
USB_MOUNT_DLNA=/mnt/dlna
DLNA_SHORT_DESCRIPTION=$'Play media from any UPNP/DLNA device on your local network'
DLNA_DESCRIPTION=$'Play media from any UPNP/DLNA device on your local network'
DLNA_MOBILE_APP_URL=https://f-droid.org/packages/de.yaacc/
function logging_on_dlna {
echo -n ''
}
function logging_off_dlna {
echo -n ''
}
function configure_interactive_dlna {
W=(1 $"Attach a drive containing playable media"
2 $"Remove a drive containing playable media")
while true
do
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Media Menu" --menu $"Choose an operation, or ESC to exit:" 10 60 2 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
break
fi
case $selection in
esac
done
}
function install_interactive_dlna {
echo -n ''
function configure_firewall_for_dlna {
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
{ echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->';
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">';
echo '<service-group>';
echo ' <name replace-wildcards="yes">%h DLNA</name>';
echo ' <service>';
echo ' <type>_dlna._tcp</type>';
echo " <port>$DLNA_PRESENTATION_PORT</port>";
echo ' </service>';
echo ' <service>';
echo ' </service>';
echo '</service-group>'; } > /etc/avahi/services/dlna.service
source_directory=/var/cache/minidlna
if [ -d $source_directory ]; then
dest_directory=dlna
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
fi
echo $"Restoring DLNA cache"
temp_restore_dir=/root/tempdlna
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir dlna
if [ -d $temp_restore_dir/var/cache/minidlna ]; then
cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
else
cp -r $temp_restore_dir/* /var/cache/minidlna/
fi
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
fi
rm -rf $temp_restore_dir
fi
fi
}
function restore_remote_dlna {
if [ -f /etc/minidlna.conf ]; then
rm /etc/minidlna.conf
fi
rm /etc/avahi/services/dlna.service
systemctl restart avahi-daemon
if [ ! -f /etc/minidlna.conf ]; then
echo $"ERROR: minidlna does not appear to have installed. $CHECK_MESSAGE"
exit 55
fi
if [ ! -d /music ]; then
mkdir /music
fi
if [ ! -d /pictures ]; then
mkdir /pictures
sed -i "s|media_dir=.*|media_dir=A,/music|g" /etc/minidlna.conf
if ! grep -q "=P,/pictures" /etc/minidlna.conf; then
echo "media_dir=P,/pictures" >> /etc/minidlna.conf
if ! grep -q "=V,/videos" /etc/minidlna.conf; then
echo "media_dir=V,/videos" >> /etc/minidlna.conf
if ! grep -q "$USB_MOUNT_DLNA/Music" /etc/minidlna.conf; then
echo "media_dir=A,$USB_MOUNT_DLNA/Music" >> /etc/minidlna.conf
if ! grep -q "$USB_MOUNT_DLNA/Pictures" /etc/minidlna.conf; then
echo "media_dir=P,$USB_MOUNT_DLNA/Pictures" >> /etc/minidlna.conf
if ! grep -q "$USB_MOUNT_DLNA/Videos" /etc/minidlna.conf; then
echo "media_dir=V,$USB_MOUNT_DLNA/Videos" >> /etc/minidlna.conf
fi
sed -i 's/#root_container=./root_container=B/g' /etc/minidlna.conf
if [[ $(config_param_exists WIFI_INTERFACE) == "0" ]]; then
sed -i 's/#network_interface=/network_interface=eth0/g' /etc/minidlna.conf
else
sed -i "s/#network_interface=/network_interface=$WIFI_INTERFACE/g" /etc/minidlna.conf
fi
sed -i "s/#network_interface=/network_interface=$WIFI_INTERFACE/g" /etc/minidlna.conf
sed -i "s/#friendly_name=.*/friendly_name=\"${PROJECT_NAME} Media\"/g" /etc/minidlna.conf
sed -i 's|#db_dir=.*|db_dir=/var/cache/minidlna|g' /etc/minidlna.conf
sed -i 's/#inotify=.*/inotify=yes/g' /etc/minidlna.conf
sed -i 's/#notify_interval=.*/notify_interval=300/g' /etc/minidlna.conf
sed -i "s|#presentation_url=.*/|presentation_url=http://localhost:$DLNA_PRESENTATION_PORT|g" /etc/minidlna.conf
sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
fi
function_check configure_firewall_for_dlna
configure_firewall_for_dlna
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
{ echo '#!/bin/bash';
echo "source /usr/local/bin/${PROJECT_NAME}-vars";
echo "UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*";
echo '';
echo "for f in \$UTILS_FILES";
echo 'do';
echo " source \$f";
echo 'done';
echo '';
echo "USB_DRIVE=\$(detect_connected_drives)";
echo "if [[ \"\$USB_DRIVE\" != 'sd'* ]]; then";
echo ' exit 1';
echo 'fi';
echo '';
echo "if [ -d $USB_MOUNT_DLNA ]; then";
echo " umount $USB_MOUNT_DLNA";
echo " rm -rf $USB_MOUNT_DLNA";
echo 'fi';
echo "chown root:root $USB_MOUNT_DLNA";
echo "chown -R minidlna:minidlna $USB_MOUNT_DLNA/*";
echo 'systemctl restart minidlna';
echo 'minidlnad -R';
echo 'exit 0'; } > /usr/bin/attach-dlna
chmod +x /usr/bin/attach-dlna
{ echo '#!/bin/bash';
echo "if [ -d $USB_MOUNT_DLNA ]; then";
echo " umount $USB_MOUNT_DLNA";
echo " rm -rf $USB_MOUNT_DLNA";
echo 'fi';
echo 'exit 0'; } > /usr/bin/unmount-dlna
chmod +x /usr/bin/unmount-dlna