#!/bin/sh
#
#    Copyright (C) 2017.2022 Ruben Rodriguez <ruben@trisquel.info>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

VERSION=7

. ./config

replace "Ubuntu MATE" "Trisquel" .
replace "Ubuntu-MATE" "Trisquel" usr/share/glib-2.0/schemas/30_ubuntu-mate.gschema.override

for a in usr/share/ubuntu-mate/settings-overlay/config/ usr/share/glib-2.0/schemas/
do
    for b in $(grep -rl 'font' $a)
    do
        echo "> Modify Ubuntu font at: $i"
        sed -i '/font/s|Ubuntu|Sans|' $b
    done
done

cat << EOF > usr/share/applications/mate-mimeapps.list
[Default Applications]
x-scheme-handler/apt=apturl.desktop;
x-scheme-handler/http=abrowser.desktop;
x-scheme-handler/https=abrowser.desktop;
x-scheme-handler/about=abrowser.desktop;
x-scheme-handler/mailto=thunderbird.desktop;
application/x-deb=gdebi.desktop;
application/x-debian-package=gdebi.desktop;
application/x-extension-eml=thunderbird.desktop;
message/rfc822=thunderbird.desktop;
inode/directory=caja-folder-handler.desktop;
text/plain=pluma.desktop;
audio/mpeg=rhythmbox.desktop;
audio/x-mpegurl=rhythmbox.desktop;
audio/x-scpls=rhythmbox.desktop;
audio/x-vorbis+ogg=rhythmbox.desktop;
audio/x-wav=rhythmbox.desktop;
x-content/audio-cdda=rhythmbox-device.desktop;
x-content/audio-player=rhythmbox-device.desktop;
video/mp4=vlc.desktop;
video/mpeg=vlc.desktop;
video/mp2t=vlc.desktop;
video/msvideo=vlc.desktop;
video/quicktime=vlc.desktop;
video/webm=vlc.desktop;
video/x-avi=vlc.desktop;
video/x-flv=vlc.desktop;
video/x-matroska=vlc.desktop;
video/x-mpeg=vlc.desktop;
video/x-ogm+ogg=vlc.desktop;
x-content/video-bluray=vlc.desktop;
x-content/video-dvd=vlc.desktop;
x-content/video-hddvd=vlc.desktop;
x-content/video-vcd=vlc.desktop;
x-content/video-svcd=vlc.desktop;
application/pdf=atril.desktop;
image/jpeg=viewnior.desktop;gimp.desktop;
image/x-pcx=viewnior.desktop;gimp.desktop;
image/gif=viewnior.desktop;gimp.desktop;
image/png=viewnior.desktop;gimp.desktop;
image/jpg=viewnior.desktop;gimp.desktop;
image/tiff=viewnior.desktop;gimp.desktop;
image/x-portable-bitmap=viewnior.desktop;gimp.desktop;
image/vnd.wap.wbmp=viewnior.desktop;
image/x-xpixmap=viewnior.desktop;gimp.desktop;
image/x-bmp=viewnior.desktop;gimp.desktop;
image/bmp=viewnior.desktop;gimp.desktop;
image/x-icb=viewnior.desktop;
image/x-portable-graymap=viewnior.desktop;gimp.desktop;
image/x-ico=viewnior.desktop;gimp.desktop;
image/x-xbitmap=viewnior.desktop;gimp.desktop;
image/x-portable-pixmap=viewnior.desktop;gimp.desktop;
image/pjpeg=viewnior.desktop;gimp.desktop;
image/x-portable-anymap=viewnior.desktop;gimp.desktop;
image/x-png=viewnior.desktop;gimp.desktop;
image/x-gray=viewnior.desktop;gimp.desktop;
image/svg+xml=viewnior.desktop;
EOF

sed '/fonts-ubuntu/d' -i debian/control

#Remove caja's dropbox autostart.
rm $(find -name caja-dropbox-autostart)
rm $(find -name caja-dropbox-autostart.desktop)
sed '/dropbox/d' -i debian/ubuntu-mate-default-settings.install

#Remove abrowser/firefox policies (starting on Jammy/Aramo).
rm etc/firefox/policies/policies.json

# Do not customize arctica-greeter
sed '/org.ArcticaProject.arctica-greeter/,/^$/d' -i usr/share/glib-2.0/schemas/30_ubuntu-mate.gschema.override

# Remove upstream firefox policies.json file.
sed -i '/exit/i if [ -f /etc/firefox/policies/policies.json ]; then' debian/ubuntu-mate-default-settings.postinst \
                                                                     debian/ubuntu-mate-default-settings.postrm
sed -i '/exit/i    rm -f /etc/firefox/policies/policies.json' debian/ubuntu-mate-default-settings.postinst \
                                                              debian/ubuntu-mate-default-settings.postrm
sed -i '/exit/i fi' debian/ubuntu-mate-default-settings.postinst \
                    debian/ubuntu-mate-default-settings.postrm

changelog "Customized for Trisquel"

package
