65 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/sh
 | 
						|
 | 
						|
# Copyright (C) 2022 Canonical Ltd.
 | 
						|
#
 | 
						|
# This program is free software: you can redistribute it and/or modify
 | 
						|
# it under the terms of the GNU General Public License version 3, as
 | 
						|
# published by the Free Software Foundation.
 | 
						|
#
 | 
						|
# 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, see <https://www.gnu.org/licenses/>.
 | 
						|
 | 
						|
host_hunspell=/var/lib/snapd/hostfs/usr/share/hunspell
 | 
						|
 | 
						|
if [ ! -d  $host_hunspell ]; then
 | 
						|
    echo "No host hunspell, skipping"
 | 
						|
    exit 0
 | 
						|
fi
 | 
						|
 | 
						|
DICPATH=$SNAP_COMMON/snap-hunspell
 | 
						|
 | 
						|
if [ -d $DICPATH ]; then
 | 
						|
    # Clean up on each refresh to ensure we have an up-to-date list
 | 
						|
    # of host dictionaries.
 | 
						|
    find $DICPATH -type l -name "*.dic" -or -name "*.aff" | xargs rm
 | 
						|
else
 | 
						|
    mkdir -p $DICPATH
 | 
						|
fi
 | 
						|
 | 
						|
# We deliberately don't directly use the host dictionary files.
 | 
						|
# Instead, we use their names to know which ones the user has
 | 
						|
# installed on their system, and we use the corresponding ones
 | 
						|
# we primed in '$SNAP/usr/share/hunspell' in our 'hunspell' part.
 | 
						|
#
 | 
						|
# - We don't set DICPATH=/var/lib/snapd/hostfs/usr/share/hunspell
 | 
						|
#   to avoid potential incompatibility due to different hunspell
 | 
						|
#   versions inside the snap and outside on the host.  See:
 | 
						|
#   https://github.com/snapcore/snapd/pull/11025
 | 
						|
#
 | 
						|
# - We don't set DICPATH="$SNAP/usr/share/hunspell" because that
 | 
						|
#   would result in all available dictionaries we primed in our
 | 
						|
#   'hunspell' part being displayed in Firefox's interface,
 | 
						|
#   presenting an overwhelming number of options to the user.
 | 
						|
#   So instead we only use those that were installed on the host.
 | 
						|
#   This way, the user could affect the dictionaries available to
 | 
						|
#   Firefox snap similarly to how they could for non-snap Firefox.
 | 
						|
for dic in $(find $host_hunspell/ -name "*.dic"); do
 | 
						|
    dic_file=$(basename $dic)
 | 
						|
    aff_file="${dic_file%%.dic}.aff"
 | 
						|
    # Some dic,aff files in hunspell are themselves symlinks to other files,
 | 
						|
    # e.g. /usr/share/hunspell/fr_CH.dic -> fr.dic.
 | 
						|
    # That extra level of indirection somehow breaks spell checking.
 | 
						|
    # We therefore use readlink to link to the "real" file, not to a symlink.
 | 
						|
    if [ -e "$SNAP/usr/share/hunspell/${dic_file}" ]; then
 | 
						|
        ln -s "$(readlink -e $SNAP/usr/share/hunspell/${dic_file})" $DICPATH/${dic_file}
 | 
						|
    fi
 | 
						|
    if [ -e "$SNAP/usr/share/hunspell/${aff_file}" ]; then
 | 
						|
        ln -s "$(readlink -e $SNAP/usr/share/hunspell/${aff_file})" $DICPATH/${aff_file}
 | 
						|
    fi
 | 
						|
done
 |