View Single Post
Posts: 177 | Thanked: 427 times | Joined on Sep 2017
#9
As rinigus suggested the script for packaging keyboards wasn't very happy with what I'm trying to do, so I had to modify it. In doing so I found the .spec needed changing too, but that made it inflexible...

My solution (which I'm sure is far from best practice) is to write the .spec file from the script with modified name and descriptions based on an optional 6th argument, resulting in a file called "keyboard-presage-colemak-en_US-1.0.0-1.noarch.rpm"

Not sure anyone's interested in alternate layouts but if you are here it is. Criticism welcome, I want to learn

Code:
#!/bin/bash

set -e

PROGPATH=$(dirname "$0")

if [ "$#" -lt 5 ]; then
    echo "Usage: $0 Language langcode version keyboard.qml keyboard.conf [layout name]"
    echo
    echo "Language: Specify language in English starting with the capital letter, ex 'Estonian'"
    echo "langcode: Specify language code, ex 'en_US'. Use the same notation as Hunspell dictionaries."
    echo "version: Version of the language package, ex '1.0.0'"
    echo "keyboard.qml: Keyboard QML file"
    echo "keyboard.conf: Keyboard Configuration file referencing the QML file"
    echo "layout name: Optional, for alternate layouts (BÉPO, Colemak, Dvorak...)"
    echo
    echo "When finished, the keyboard support will be packaged into RPM in the current directory"
    echo
    echo "The script requires rpmbuild to be installed. Note that rpmbuild can be installed on distributions that don't use RPM for packaging"
    echo
    exit 0
fi

L=$1
CODE=$2
VERSION=$3
KQML=$4
KCONF=$5
if [ $6 != "" ]; then
LAYOUT="-$6"
fi

NAME=keyboard-presage$LAYOUT-$CODE
LAYOUT=" ${LAYOUT:1:50}"

TMPDIR=`mktemp -d`

mkdir -p $TMPDIR/$NAME-$VERSION/keyboard
mkdir -p $TMPDIR/$NAME-$VERSION/rpm
cp "$KQML" $TMPDIR/$NAME-$VERSION/keyboard
cp "$KCONF" $TMPDIR/$NAME-$VERSION/keyboard

echo "# Template for generation of keyboard RPMs
# for Presage on Sailfish. This temlate is used
# by package-keyboard.sh script

# Prevent brp-python-bytecompile from running.
%define __os_install_post %{___build_post}

# \"Harbour RPM packages should not provide anything.\"
%define __provides_exclude_from ^%{_datadir}/.*$

Name: "$NAME"
Version: __version__
Release: 1
Summary: Keyboard layout for"$LAYOUT" __Language__ with Presage support
License: MIT
URL: https://github.com/martonmiklos/sailfishos-presage-predictor
Source: %{name}-%{version}.tar.xz
BuildArch: noarch
Requires: presage-lang-__langcode__
Requires: hunspell-lang-__langcode__
Requires: maliit-plugin-presage

%description
Keyboard layout for"$LAYOUT" __Language__ language with Presage text predictions

%prep
%setup -q

%install
mkdir -p %{buildroot}/usr/share/maliit/plugins/com/jolla/layouts
cp -r keyboard/* %{buildroot}/usr/share/maliit/plugins/com/jolla/layouts

%files
%defattr(-,root,root,-)
%{_datadir}/maliit/plugins/com/jolla/layouts" > $TMPDIR/$NAME-$VERSION/rpm/$NAME.spec

sed -i "s/__langcode__/$CODE/"  $TMPDIR/$NAME-$VERSION/rpm/$NAME.spec
sed -i "s/__Language__/$L/"  $TMPDIR/$NAME-$VERSION/rpm/$NAME.spec
sed -i "s/__version__/$VERSION/"  $TMPDIR/$NAME-$VERSION/rpm/$NAME.spec

tar -C $TMPDIR -cJf $TMPDIR/$NAME-$VERSION.tar.xz $NAME-$VERSION

mkdir -p $HOME/rpmbuild/SOURCES
mkdir -p $HOME/rpmbuild/SPECS

cp $TMPDIR/$NAME-$VERSION.tar.xz $HOME/rpmbuild/SOURCES
cp $TMPDIR/$NAME-$VERSION/rpm/$NAME.spec $HOME/rpmbuild/SPECS

rm -rf $TMPDIR

rm -rf $HOME/rpmbuild/BUILD/$NAME-$VERSION
rpmbuild -ba --nodeps $HOME/rpmbuild/SPECS/$NAME.spec

mkdir -p RPMS
cp $HOME/rpmbuild/RPMS/noarch/$NAME-$VERSION-*.rpm .
 

The Following 6 Users Say Thank You to suicidal_orange For This Useful Post: