freedombone/src/freedombone-app-dlna

236 lines
7.6 KiB
Plaintext
Raw Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# DLNA application
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# 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/>.
2016-07-06 17:47:55 +02:00
VARIANTS='full media'
2016-07-09 12:36:12 +02:00
function reconfigure_dlna {
echo ''
}
2016-07-06 16:01:28 +02:00
function upgrade_dlna {
2016-07-07 11:05:27 +02:00
echo ''
2016-07-06 16:01:28 +02:00
}
function configure_firewall_for_dlna {
if grep -Fxq "configure_firewall_for_dlna" $COMPLETION_FILE; then
return
fi
if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
# docker does its own firewalling
return
fi
iptables -A INPUT -p udp --dport 1900 -j ACCEPT
iptables -A INPUT -p tcp --dport 8200 -j ACCEPT
function_check save_firewall_settings
save_firewall_settings
OPEN_PORTS+=('DLNA 1900')
OPEN_PORTS+=('DLNA 8200')
echo 'configure_firewall_for_dlna' >> $COMPLETION_FILE
}
2016-07-06 15:55:09 +02:00
function backup_local_dlna {
2016-07-07 11:05:27 +02:00
source_directory=/var/cache/minidlna
if [ -d $source_directory ]; then
dest_directory=dlna
echo $"Backing up $source_directory to $dest_directory"
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
echo $"Backup to $dest_directory complete"
fi
2016-07-06 15:55:09 +02:00
}
2016-07-08 17:38:26 +02:00
function restore_local_dlna {
if [ -d /var/cache/minidlna ]; then
if [ -d $USB_MOUNT/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
cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
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 982572
fi
rm -rf $temp_restore_dir
fi
fi
}
2016-07-06 15:55:09 +02:00
function backup_remote_dlna {
2016-07-09 22:40:11 +02:00
if [ -d /var/cache/minidlna ]; then
echo $"Backing up DLNA cache"
backup_directory_to_friend /var/cache/minidlna dlna
echo $"Backup of DLNA cache complete"
fi
2016-07-08 17:38:26 +02:00
}
function restore_remote_dlna {
2016-07-10 15:56:02 +02:00
if [ -d /var/cache/minidlna ]; then
if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
echo $"Restoring DLNA cache"
temp_restore_dir=/root/tempdlna
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir dlna
cp -r $temp_restore_dir/var/cache/minidlna/* /var/cache/minidlna/
if [ ! "$?" = "0" ]; then
exit 982
fi
rm -rf $temp_restore_dir
echo $"Restore of DLNA complete"
fi
fi
2016-07-04 22:02:22 +02:00
}
2016-07-05 21:07:43 +02:00
function remove_dlna {
if ! grep -Fxq "install_dlna" $COMPLETION_FILE; then
2016-07-03 21:29:52 +02:00
return
fi
service minidlna stop
apt-get -y remove --purge minidlna
if [ -f /etc/minidlna.conf ]; then
rm /etc/minidlna.conf
fi
iptables -D INPUT -p udp --dport 1900 -j ACCEPT
iptables -D INPUT -p tcp --dport 8200 -j ACCEPT
function_check save_firewall_settings
save_firewall_settings
2016-07-05 21:07:43 +02:00
sed -i '/install_dlna/d' $COMPLETION_FILE
2016-07-03 21:29:52 +02:00
}
2016-07-06 15:43:20 +02:00
function install_dlna_main {
if grep -Fxq "install_dlna_main" $COMPLETION_FILE; then
2016-07-03 17:13:34 +02:00
return
fi
2016-07-03 17:13:34 +02:00
apt-get -y install minidlna
if [ ! -f /etc/minidlna.conf ]; then
echo $"ERROR: minidlna does not appear to have installed. $CHECK_MESSAGE"
exit 55
fi
sed -i "s|media_dir=/var/lib/minidlna|media_dir=A,/home/$MY_USERNAME/Music|g" /etc/minidlna.conf
if ! grep -q "/home/$MY_USERNAME/Pictures" /etc/minidlna.conf; then
echo "media_dir=P,/home/$MY_USERNAME/Pictures" >> /etc/minidlna.conf
fi
if ! grep -q "/home/$MY_USERNAME/Videos" /etc/minidlna.conf; then
echo "media_dir=V,/home/$MY_USERNAME/Videos" >> /etc/minidlna.conf
fi
if ! grep -q "$USB_MOUNT/Music" /etc/minidlna.conf; then
echo "media_dir=A,$USB_MOUNT/Music" >> /etc/minidlna.conf
fi
if ! grep -q "$USB_MOUNT/Pictures" /etc/minidlna.conf; then
echo "media_dir=P,$USB_MOUNT/Pictures" >> /etc/minidlna.conf
fi
if ! grep -q "$USB_MOUNT/Videos" /etc/minidlna.conf; then
echo "media_dir=V,$USB_MOUNT/Videos" >> /etc/minidlna.conf
fi
sed -i 's/#root_container=./root_container=B/g' /etc/minidlna.conf
if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; 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/#friendly_name=/friendly_name=\"${PROJECT_NAME} Media\"/g" /etc/minidlna.conf
sed -i 's|#db_dir=/var/cache/minidlna|db_dir=/var/cache/minidlna|g' /etc/minidlna.conf
sed -i 's/#inotify=yes/inotify=yes/g' /etc/minidlna.conf
sed -i 's/#notify_interval=895/notify_interval=300/g' /etc/minidlna.conf
sed -i "s|#presentation_url=/|presentation_url=http://localhost:8200|g" /etc/minidlna.conf
service minidlna force-reload
service minidlna reload
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
function_check configure_firewall_for_dlna
configure_firewall_for_dlna
2016-07-06 15:43:20 +02:00
echo 'install_dlna_main' >> $COMPLETION_FILE
2016-07-03 17:13:34 +02:00
}
function script_for_attaching_usb_drive {
if grep -Fxq "script_for_attaching_usb_drive" $COMPLETION_FILE; then
return
fi
echo '#!/bin/bash' > /usr/bin/attach-music
echo 'remove-music' >> /usr/bin/attach-music
echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/attach-music
echo " mkdir $USB_MOUNT" >> /usr/bin/attach-music
echo 'fi' >> /usr/bin/attach-music
echo "mount /dev/sda1 $USB_MOUNT" >> /usr/bin/attach-music
echo "chown root:root $USB_MOUNT" >> /usr/bin/attach-music
echo "chown -R minidlna:minidlna $USB_MOUNT/*" >> /usr/bin/attach-music
echo 'service minidlna restart' >> /usr/bin/attach-music
echo 'minidlnad -R' >> /usr/bin/attach-music
chmod +x /usr/bin/attach-music
ln -s /usr/bin/attach-music /usr/bin/attach-usb
ln -s /usr/bin/attach-music /usr/bin/attach-videos
ln -s /usr/bin/attach-music /usr/bin/attach-pictures
ln -s /usr/bin/attach-music /usr/bin/attach-media
echo '#!/bin/bash' > /usr/bin/remove-music
echo "if [ -d $USB_MOUNT ]; then" >> /usr/bin/remove-music
echo " umount $USB_MOUNT" >> /usr/bin/remove-music
echo " rm -rf $USB_MOUNT" >> /usr/bin/remove-music
echo 'fi' >> /usr/bin/remove-music
chmod +x /usr/bin/remove-music
ln -s /usr/bin/remove-music /usr/bin/detach-music
ln -s /usr/bin/remove-music /usr/bin/detach-usb
ln -s /usr/bin/remove-music /usr/bin/remove-usb
ln -s /usr/bin/remove-music /usr/bin/detach-media
ln -s /usr/bin/remove-music /usr/bin/remove-media
ln -s /usr/bin/remove-music /usr/bin/detach-videos
ln -s /usr/bin/remove-music /usr/bin/remove-videos
ln -s /usr/bin/remove-music /usr/bin/detach-pictures
ln -s /usr/bin/remove-music /usr/bin/remove-pictures
echo 'script_for_attaching_usb_drive' >> $COMPLETION_FILE
}
2016-07-06 15:43:20 +02:00
function install_dlna {
if grep -Fxq "install_dlna" $COMPLETION_FILE; then
return
fi
install_dlna_main
script_for_attaching_usb_drive
echo 'install_dlna' >> $COMPLETION_FILE
}
2016-07-03 17:13:34 +02:00
# NOTE: deliberately no exit 0