-
Bob Mottram authoredBob Mottram authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
freedombone-app-dlna 9.23 KiB
#!/bin/bash
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Freedom in the Cloud
#
# DLNA application
#
# Deprecated because there are no DLNA clients within F-droid
# and Android is the main reason that DLNA was useful
#
# License
# =======
#
# Copyright (C) 2014-2019 Bob Mottram <bob@freedombone.net>
#
# 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 full-vim media'
APP_CATEGORY=media
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=0
SHOW_CLEARNET_ADDRESS_ON_ABOUT=0
SHOW_DOMAIN_IN_WEBADMIN=0
NOT_ON_HOMEPAGE=1
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/
dlna_variables=(SYSTEM_TYPE
MY_USERNAME)
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
1) attach-dlna;;
2) unmount-dlna;;
esac
done
}
function install_interactive_dlna {
echo -n ''
APP_INSTALLED=1
}
function reconfigure_dlna {
echo ''
}
function upgrade_dlna {
echo ''
}
function configure_firewall_for_dlna {
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
return
fi
firewall_add DLNAP $DLNA_PRESENTATION_PORT tcp
firewall_add DLNA $DLNA_PORT udp
{ 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 ' <type>_dlna._udp</type>';
echo " <port>$DLNA_PORT</port>";
echo ' </service>';
echo '</service-group>'; } > /etc/avahi/services/dlna.service
systemctl restart avahi-daemon
mark_completed "${FUNCNAME[0]}"
}
function backup_local_dlna {
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
}
function restore_local_dlna {
if [ -d /var/cache/minidlna ]; then
if [ -d "$USB_MOUNT_DLNA/backup/dlna" ]; then
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
# shellcheck disable=SC2181
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 98
fi
rm -rf $temp_restore_dir
fi
fi
}
function backup_remote_dlna {
echo -n ''
}
function restore_remote_dlna {
echo -n ''
}
function remove_dlna {
systemctl stop minidlna
$REMOVE_PACKAGES_PURGE minidlna
if [ -f /etc/minidlna.conf ]; then
rm /etc/minidlna.conf
fi
rm /usr/bin/attach-dlna
rm /usr/bin/unmount-dlna
remove_completion_param install_dlna
firewall_remove $DLNA_PORT udp
firewall_remove $DLNA_PRESENTATION_PORT tcp
rm /etc/avahi/services/dlna.service
systemctl restart avahi-daemon
}
function install_dlna_main {
if [[ $(app_is_installed dlna_main) == "1" ]]; then
return
fi
increment_app_install_progress
$INSTALL_PACKAGES_BACKPORTS minidlna
increment_app_install_progress
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
fi
if [ ! -d /videos ]; then
mkdir /videos
fi
increment_app_install_progress
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
fi
if ! grep -q "=V,/videos" /etc/minidlna.conf; then
echo "media_dir=V,/videos" >> /etc/minidlna.conf
fi
if ! grep -q "$USB_MOUNT_DLNA/Music" /etc/minidlna.conf; then
echo "media_dir=A,$USB_MOUNT_DLNA/Music" >> /etc/minidlna.conf
fi
if ! grep -q "$USB_MOUNT_DLNA/Pictures" /etc/minidlna.conf; then
echo "media_dir=P,$USB_MOUNT_DLNA/Pictures" >> /etc/minidlna.conf
fi
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 [[ $SYSTEM_TYPE != "mesh"* ]]; then
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
else
sed -i "s/#network_interface=/network_interface=$WIFI_INTERFACE/g" /etc/minidlna.conf
fi
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
systemctl reload minidlna
increment_app_install_progress
sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
if ! grep -q "max_user_watches" "$COMPLETION_FILE"; then
echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
fi
/sbin/sysctl -p -q
increment_app_install_progress
function_check configure_firewall_for_dlna
configure_firewall_for_dlna
increment_app_install_progress
install_completed dlna_main
}
function script_for_attaching_usb_drive {
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
return
fi
{ 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 '';
echo "if [ ! -d $USB_MOUNT_DLNA ]; then";
echo " mkdir $USB_MOUNT_DLNA";
echo 'fi';
echo "mount \$USB_DRIVE $USB_MOUNT_DLNA";
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
mark_completed "${FUNCNAME[0]}"
}
function install_dlna {
install_dlna_main
increment_app_install_progress
script_for_attaching_usb_drive
APP_INSTALLED=1
}
# NOTE: deliberately no exit 0