Skip to content

Instantly share code, notes, and snippets.

@somelinguist
Last active April 30, 2024 22:36
Show Gist options
  • Save somelinguist/a6cdfdf42d8ab15a163ee6496148a896 to your computer and use it in GitHub Desktop.
Save somelinguist/a6cdfdf42d8ab15a163ee6496148a896 to your computer and use it in GitHub Desktop.
attempt flextools compatibility with flatpak
#!/bin/bash
# Be sure to set execute permission for the script.
# Configure how to call python here:
CALLPYTHON=python
# Configure the prefix to the path where FieldWorks is installed.
# /usr is the default for installing via the apt package manager on Ubuntu:
# /app is the default for flatpak
prefix=/app
# In order to function correctly on Linux,
# we need to source a shell script (environ), which
# erases the path and several other environment variables.
# This function is called after the variables needed by FLEx
# are sourced in order to reset any variables needed by
# the caller which were erased.
resetenviron() {
echo "Resetting environment"
# Reset pyenv variables
export PATH="$HOME/.pyenv/bin:$PATH"
# Try setting path to libc.so.6, etc needed by python installed by pyenv (2.34),
# otherwise flatpack only finds its internal version of libc (2.30)
# However, after setting this, it crashes with "Segmentation fault (core dumped)"
export LD_LIBRARY_PATH="/var/run/host/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
}
# The following is adapted from the run-app shell script
# used to run an installed version of FLEx on Linux.
scriptdir=$(/bin/pwd)
lib=$prefix/lib/fieldworks
share=$prefix/share/fieldworks
sharedWsRoot=/var/lib/fieldworks
sharedWs=$sharedWsRoot/SIL/WritingSystemStore
# "$share/setup-user"
cd "$lib"; RUNMODE="INSTALLED" . environ;
cd $scriptdir
# reset environment as defined above
resetenviron
exec $CALLPYTHON ../scripts/RunFlexTools.py DEBUG
@somelinguist
Copy link
Author

Install the Flex flatpak (https://flathub.org/apps/org.sil.FieldWorks).

Download the latest version of flextools and extract it to a new directory (https://github.com/cdfarrow/flextools/releases).

Navigate to the directory where flextools was extracted.

Using pyenv, setup a virtual environment for flextools (something like pyenv virtualenv flextools using the currently set version of python)

Use pyenv to set the local python for the flextools directory to the new virtualenv: pyenv local flextools.

Run python -m pip install --upgrade -r scripts\requirements.txt

Install this script in $FLEXTOOLSBASE/FlexTools and set permissions.

Run flatpak run --command=sh org.sil.FieldWorks

Navigate to $FLEXTOOLSBASE/FlexTools while in the flatpak shell

Run ./flextools.sh

The script finds sources Flex's environ script, then resets environment variables needed by pyenv, then calls python to run ../scripts/RunFlexTools.py DEBUG

@somelinguist
Copy link
Author

See this issue with PyCharm for related bugs when trying to use pyenv with its flatpak version: flathub/com.jetbrains.PyCharm-Community#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment