File kbd.spec of Package kbd

# spec file for package kbd
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates

Name:           kbd
Version:        2.0.4
Release:        0
Summary:        Keyboard and Font Utilities
# git: git://
License:        GPL-2.0-or-later
Group:          System/Console
Source:         %{name}-%{version}-repack.tar.xz
Source1:        kbd_fonts.tar.bz2
Source2:        suse-add.tar.bz2
Source3:        README.SUSE
Source4:        vlock.pamd
Source8:        sysconfig.console
Source9:        sysconfig.keyboard
Source11:       fbtest.c
Source12:       fbtest.8
Source15:       cz-map.patch
Source20:       kbdsettings
Source21:       kbdsettings.service
Source22:       numlockbios.c
Source42:       convert-kbd-mac.sed
Patch0:         kbd-1.15.2-prtscr_no_sigquit.patch
Patch2:         kbd-1.15.2-unicode_scripts.patch
Patch3:         kbd-1.15.2-docu-X11R6-xorg.patch
Patch4:         kbd-1.15.2-sv-latin1-keycode10.patch
Patch5:         kbd-1.15.2-setfont-no-cruft.patch
# TODO: no ideas how to port it.
Patch6:         kbd-1.15.2-dumpkeys-C-opt.patch
Patch9:         kbd-2.0.2-comment-typo-qwerty.patch
Patch10:        kbd-2.0.2-doshell-reference.patch
Patch11:        kbd-2.0.2-euro-unicode.patch
Patch12:        kbd-2.0.2-fix-bashisms.patch
# Patch13: adds xkb and legacy keymaps subdirs to loadkyes search path
# (openSUSE FATE#318355, sle FATE#318426)
Patch13:        kbd-1.15.5-loadkeys-search-path.patch
# PATCH-FEATURE-OPENSUSE kbdsettings-nox86.patch -- Disable "bios" option for NumLock settings on non x86 platforms.
Patch14:        kbdsettings-nox86.patch
# PATCH-FIX-SLE kbd-unicode-fxxx.patch bsc1085432 -- Do not cause error on UNICODE characters >= 0xF000 (e. g. ligature fi)
Patch15:        kbd-unicode-fxxx.patch
BuildRequires:  automake
BuildRequires:  bison
BuildRequires:  check-devel
BuildRequires:  console-setup
BuildRequires:  flex
BuildRequires:  gcc >= 4.6
BuildRequires:  pam-devel
BuildRequires:  pkgconfig
BuildRequires:  suse-module-tools
BuildRequires:  xkeyboard-config
BuildRequires:  xz
# Temporarily require -legacy
Requires:       %{name}-legacy = %{version}-%{release}
Requires(post): coreutils
Requires(postun): coreutils
Requires(pre):  %fillup_prereq
Provides:       vlock = 2.2.3
Obsoletes:      vlock <= 2.2.3

Load and save keyboard mappings. This is needed if you are not using
the US keyboard map. This package also contains utilities for changing
your console fonts. If you install this package, YaST includes an extra
menu to allow you to choose between the different fonts. This package
also includes fonts from the kbd_fonts.tar.gz package (by Paul
Gortmaker) on Sunsite.

%package legacy
Summary:        Legacy data for kbd package
Group:          System/Console
BuildArch:      noarch

%description legacy
The %{name}-legacy package contains original keymaps for kbd package.
Please note that %{name}-legacy is not helpful without kbd.

%define kbd %{_datadir}/kbd

%setup -q -a 1 -a 2 -n kbd-%{version}

cp -fp %{SOURCE8} .
cp -fp %{SOURCE9} .
cp -fp %{SOURCE44} .
cp -fp %{SOURCE45} .
cp -fp %{SOURCE20} .
cp -fp %{SOURCE21} .
cp -fp %{SOURCE22} .
%patch0 -p1
%patch4 -p1
%patch5 -p1
# TODO: no ideas how to port it.
%patch12 -p1
%patch13 -p1
%ifnarch %{ix86} x86_64
%patch14 -p0
%patch15 -p1

for i in `find data/keymaps/mac -type f` ; do
sed -i -f %{SOURCE42} $i
# workaround ambiguous keymap names
pushd data/keymaps/i386
	# bnc#48301
	test -f qwerty/ || cp qwerty/ qwerty/
	# bnc#435121
	test -f olpc/ || mv olpc/ olpc/
	# Rename conflicting keymaps, as Fedora do
	test -f dvorak/ || mv dvorak/ dvorak/
	test -f fgGIod/ || mv fgGIod/ fgGIod/
	test -f olpc/ || mv olpc/ olpc/
	test -f qwerty/ || mv qwerty/ qwerty/
%configure \
	--disable-silent-rules \
	--datadir=%{kbd} \
	--enable-nls \
	--localedir=%{_datadir}/locale \
make %{?_smp_mflags}
gcc %{optflags} -o fbtest      $RPM_SOURCE_DIR/fbtest.c
%ifarch %{ix86} x86_64
gcc %{optflags} -o numlockbios $RPM_SOURCE_DIR/numlockbios.c
# fix lat2-16.psfu (bnc#340579)
./src/psfxtable -i $font -it  data/unimaps/lat2u.uni \
	-o t.psfu
mv t.psfu $font
make %{?_smp_mflags}

mkdir -p %{buildroot}%{_sbindir}
mkdir -p $K/consolefonts
# First install the fonts from the vfont package
# (allowing kbd to overwrite some of them)
mkdir -p $DOC/fonts
install -m 644 fonts/README $DOC/fonts/README.fonts
install -m 644 fonts/vfont-4.36/README $DOC/fonts/README.vfont-4.36
install -m 644 fonts/vfont-5.10/README $DOC/fonts/README.vfont-5.10
install -m 644 fonts/vfont-5.10/SCRIPT $DOC/fonts/SCRIPT.vfont-5.10
rm -f fonts/vfont-5.10/SCRIPT fonts/*/README
install -m 644 fonts/*/* $K/consolefonts/
# Now call kbd install
echo "# Now call kbd install DESTDIR=%{buildroot} DATA_DIR=%{kbd} MAN_DIR=%{_mandir}"
make DESTDIR=%{buildroot} DATA_DIR=%{kbd} MAN_DIR=%{_mandir} install
# ln -s iso01-12x22.psfu $K/consolefonts/suse12x22.psfu
install -m 644 data/consolefonts/README* $DOC/fonts/
mkdir -p $DOC/doc/
install -m 644 docs/doc/ docs/doc/kbd.FAQ.txt docs/doc/kbd.FAQ*.html docs/doc/README* docs/doc/TODO $DOC/doc/
install -m 644 docs/doc/as400.kbd docs/doc/ docs/doc/repeat/set_kbd_repeat-2 $DOC/doc/
echo "See %{_datadir}/i18/charmaps for a description of char maps" >$DOC/doc/README.charmaps
install -m 644 COPYING ChangeLog CREDITS README $DOC/
install -m 644 %{SOURCE3} $DOC/
rm -f $K/consolefonts/README* $K/consolefonts/ERRORS.gz
if ls $K/consolefonts/Agafari-* > /dev/null 2>&1; then
  echo "";
  echo "ERROR: Ethiopian Agafari fonts are for noncommercial distribution only."
  echo "please run";
  echo "";
  exit 1
ln -sf $K/keymaps/i386/qwerty/
ln -sf $K/keymaps/i386/qwerty/
ln -sf $K/keymaps/i386/qwerty/
ln -sf $K/keymaps/i386/qwerty/
ln -sf $K/keymaps/i386/qwerty/
ln -sf $K/keymaps/i386/qwerty/
# Compatability links; don't know what the first three are good for.
# The others are for yast/langselection and should be removed as soon as
# yast knows about it.
#ln -sf \
#  $K/keymaps/i386/qwertz/
#ln -sf $K/keymaps/i386/qwerty/
#ln -sf \
#  $K/keymaps/i386/qwertz/
# The next two links are for yast-language choise; should be obsolete
# with the next yast version (on 6.1)
#ln -sf lat1-16.psfu.gz $K/consolefonts/lat1u-16.psf.gz
#ln -sf lat2-16.psfu.gz $K/consolefonts/lat2u-16.psf.gz
# This is for stupid default font search
rm -f $K/consolefonts/default8x16.gz
ln -sf default8x16.psfu.gz $K/consolefonts/default8x16.gz
rm -f $K/keymaps/i386/qwerty/*~ $K/keymaps/i386/qwerty/*,v
# this is until the Cyr* font are not part of the package
rm -f $K/consolefonts/Cyr_a8x14.gz
ln -sf Cyr_a8x14.psfu.gz $K/consolefonts/Cyr_a8x14.gz
rm -f $K/consolefonts/Cyr_a8x16.gz
ln -sf Cyr_a8x16.psfu.gz $K/consolefonts/Cyr_a8x16.gz
rm -f $K/consolefonts/Cyr_a8x8.gz
ln -sf Cyr_a8x8.psfu.gz $K/consolefonts/Cyr_a8x8.gz
find $K -name \*.orig | xargs -r rm -vf
# add some missing maps to mac and remap french board
cd $K/keymaps/mac/all
#ln -s
#ln -s
for i in \ \ \ \ \ \ \ \ \ \ \ \ \
do test -f $i || ln -sv $i
mkdir -p $FILLUP_DIR
install -m 644 sysconfig.console $FILLUP_DIR/sysconfig.console
install -m 644 sysconfig.keyboard $FILLUP_DIR/sysconfig.keyboard
%ifnarch %{ix86} x86_64
   rm -f %{buildroot}%{_mandir}/man8/resizecons.8*
%ifarch %{sparc} m68k
rm -f %{buildroot}%{_mandir}/man8/getkeycodes.8*
rm -f %{buildroot}%{_mandir}/man8/setkeycodes.8*
install -m 755 fbtest      %{buildroot}%{_sbindir}
%ifarch %{ix86} x86_64
install -d %{buildroot}%{_libexecdir}/%{name}
install -m 755 numlockbios %{buildroot}%{_libexecdir}/%{name}
install -d %{buildroot}%{_sysconfdir}/pam.d
install -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/pam.d/vlock
install -m 644 %{SOURCE12} %{buildroot}%{_mandir}/man8/
install -m 755 %{SOURCE13} %{buildroot}%{_bindir}/guess_encoding
install -m 755 %{SOURCE14} %{buildroot}%{_bindir}/kbd
mkdir -p %{buildroot}/bin
mkdir -p %{buildroot}/sbin
ln -s %{_bindir}/chvt %{buildroot}/bin
ln -s %{_bindir}/clrunimap %{buildroot}/bin
ln -s %{_bindir}/deallocvt %{buildroot}/bin
ln -s %{_bindir}/dumpkeys %{buildroot}/bin
ln -s %{_bindir}/fgconsole %{buildroot}/bin
ln -s %{_bindir}/getunimap %{buildroot}/bin
ln -s %{_bindir}/guess_encoding %{buildroot}/bin
ln -s %{_bindir}/kbd_mode %{buildroot}/bin
ln -s %{_bindir}/kbdinfo %{buildroot}/bin
ln -s %{_bindir}/kbdrate %{buildroot}/bin
ln -s %{_bindir}/loadkeys %{buildroot}/bin
ln -s %{_bindir}/loadunimap %{buildroot}/bin
ln -s %{_bindir}/mapscrn %{buildroot}/bin
ln -s %{_bindir}/openvt %{buildroot}/bin
ln -s %{_bindir}/outpsfheader %{buildroot}/bin
ln -s %{_bindir}/psfaddtable %{buildroot}/bin
ln -s %{_bindir}/psfgettable %{buildroot}/bin
ln -s %{_bindir}/psfstriptable %{buildroot}/bin
ln -s %{_bindir}/psfxtable %{buildroot}/bin
ln -s %{_bindir}/screendump %{buildroot}/bin
ln -s %{_bindir}/setfont %{buildroot}/bin
ln -s %{_bindir}/setleds %{buildroot}/bin
ln -s %{_bindir}/setlogcons %{buildroot}/bin
ln -s %{_bindir}/setmetamode %{buildroot}/bin
ln -s %{_bindir}/setpalette %{buildroot}/bin
ln -s %{_bindir}/setvesablank %{buildroot}/bin
ln -s %{_bindir}/setvtrgb %{buildroot}/bin
ln -s %{_bindir}/showconsolefont %{buildroot}/bin
ln -s %{_bindir}/showkey %{buildroot}/bin
ln -s %{_bindir}/spawn_console %{buildroot}/bin
ln -s %{_bindir}/spawn_login %{buildroot}/bin
ln -s %{_bindir}/unicode_start %{buildroot}/bin
ln -s %{_bindir}/unicode_stop %{buildroot}/bin
ln -s %{_sbindir}/fbtest %{buildroot}/sbin
%ifnarch %{sparc} m68k
ln -s %{_bindir}/getkeycodes %{buildroot}/bin
ln -s %{_bindir}/setkeycodes %{buildroot}/bin
%ifarch %{ix86} x86_64
ln -s %{_bindir}/resizecons %{buildroot}/bin

# Move original keymaps to legacy directory
mkdir -p %{buildroot}%{kbd}/keymaps/legacy
mv %{buildroot}%{kbd}/keymaps/{amiga,atari,i386,include,mac,ppc,sun} %{buildroot}%{kbd}/keymaps/legacy

# Convert X keyboard layouts to console keymaps
mkdir -p %{buildroot}%{kbd}/keymaps/xkb
perl < %{_datadir}/X11/xkb/rules/base.xml > layouts-variants.lst
while read line; do
  XKBLAYOUT=`echo "$line" | cut -d " " -f 1`
  echo "$XKBLAYOUT" >> layouts-list.lst
  XKBVARIANT=`echo "$line" | cut -d " " -f 2`
  ckbcomp "$XKBLAYOUT" "$XKBVARIANT" | gzip -n9 > %{buildroot}%{kbd}/keymaps/xkb/"$XKBLAYOUT"-"$XKBVARIANT".map.gz
done < layouts-variants.lst

# Convert X keyboard layouts (plain, no variant)
cat layouts-list.lst | sort -u >> layouts-list-uniq.lst
while read line; do
  ckbcomp "$line" | gzip -n9 > %{buildroot}%{kbd}/keymaps/xkb/"$line".map.gz
done < layouts-list-uniq.lst

# wipe converted layouts which cannot input ASCII (rh#1031848)
zgrep -L "U+0041" %{buildroot}%{kbd}/keymaps/xkb/* | xargs rm -f

# Rename the converted default fi (kotoistus) layout (rh#1117891)
gunzip %{buildroot}%{kbd}/keymaps/xkb/
mv %{buildroot}%{kbd}/keymaps/xkb/ %{buildroot}%{kbd}/keymaps/xkb/
gzip -n9 %{buildroot}%{kbd}/keymaps/xkb/

# Fix converted cz layout - add compose rules (rh#1181581)
gunzip %{buildroot}%{kbd}/keymaps/xkb/
patch %{buildroot}%{kbd}/keymaps/xkb/ < %{SOURCE15}
gzip -n9 %{buildroot}%{kbd}/keymaps/xkb/

# Generate entries for systemd's /usr/share/systemd/kbd-model-map
mkdir -p  %{buildroot}%{_datadir}/systemd
sh ./ %{buildroot}%{kbd}/keymaps/xkb \
  > %{buildroot}%{_datadir}/systemd/kbd-model-map.xkb-generated

install -m0755 kbdsettings %{buildroot}%{_sbindir}/
install -d %{buildroot}%{_prefix}/lib/systemd/system
install -m0644 kbdsettings.service %{buildroot}%{_prefix}/lib/systemd/system

%find_lang %{name}

%{service_add_pre kbdsettings.service}

%{fillup_only -n console}
%{fillup_only -n keyboard}
# Variables deleted before Leap 15 and SLE 15
%{remove_and_set -n keyboard KEYTABLE COMPOSETABLE}
%ifnarch %{ix86} x86_64
# "bios" was accepted but ingnored on non-x86 platforms up to Leap 42.* and SLE 12.*
sed -i 's/^KBD_NUMLOCK="bios"/KBD_NUMLOCK="no"/' /etc/sysconfig/keyboard
%{service_add_post kbdsettings.service}

%{service_del_preun kbdsettings.service}

%{service_del_postun kbdsettings.service}


%files -f %{name}.lang
#config(noreplace) /etc/sysconfig/console
%doc %{_defaultdocdir}/kbd
%exclude %{kbd}/keymaps/legacy
%ifnarch %{sparc} m68k
%ifarch %{ix86} x86_64
%ifnarch %{sparc} m68k
%ifarch %{ix86} x86_64
%ifarch %{ix86} x86_64
%dir %{_libexecdir}/%{name}
%ifnarch %{sparc} m68k
%ifarch %{ix86} x86_64
%config(noreplace) %{_sysconfdir}/pam.d/vlock
%dir %{_datadir}/systemd

%files legacy

openSUSE Build Service is sponsored by