-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from ae-utbm/xapian-from-sources
Xapian from sources and fix CVE
- Loading branch information
Showing
8 changed files
with
878 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- coding:utf-8 -* | ||
# | ||
# Copyright 2024 © AE UTBM | ||
# [email protected] / [email protected] | ||
# | ||
# This file is part of the website of the UTBM Student Association (AE UTBM), | ||
# https://ae.utbm.fr. | ||
# | ||
# You can find the source code of the website at https://github.com/ae-utbm/sith3 | ||
# | ||
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3) | ||
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE | ||
# OR WITHIN THE LOCAL FILE "LICENSE" | ||
# | ||
# | ||
|
||
import os | ||
import tomli | ||
import subprocess | ||
from django.core.management.base import BaseCommand, CommandParser | ||
from pathlib import Path | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Install xapian" | ||
|
||
def add_arguments(self, parser: CommandParser): | ||
parser.add_argument( | ||
"-f", | ||
"--force", | ||
action="store_true", | ||
help="Force installation even if already installed", | ||
) | ||
|
||
def _current_version(self) -> str | None: | ||
try: | ||
import xapian | ||
except ImportError: | ||
return None | ||
return xapian.version_string() | ||
|
||
def _desired_version(self) -> str: | ||
with open( | ||
Path(__file__).parent.parent.parent.parent / "pyproject.toml", "rb" | ||
) as f: | ||
pyproject = tomli.load(f) | ||
return pyproject["tool"]["xapian"]["version"] | ||
|
||
def handle(self, force: bool, *args, **options): | ||
if not os.environ.get("VIRTUAL_ENV", None): | ||
print("No virtual environment detected, this command can't be used") | ||
return | ||
|
||
desired = self._desired_version() | ||
if desired == self._current_version(): | ||
if not force: | ||
print( | ||
f"Version {desired} is already installed, use --force to re-install" | ||
) | ||
return | ||
print(f"Version {desired} is already installed, re-installing") | ||
print(f"Installing xapian version {desired} at {os.environ['VIRTUAL_ENV']}") | ||
subprocess.run( | ||
[str(Path(__file__).parent / "install_xapian.sh"), desired], | ||
env=dict(os.environ), | ||
).check_returncode() | ||
print("Installation success") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
# Originates from https://gist.github.com/jorgecarleitao/ab6246c86c936b9c55fd | ||
# first argument of the script is Xapian version (e.g. 1.2.19) | ||
VERSION=$1 | ||
|
||
# Cleanup env vars for auto discovery mechanism | ||
export CPATH= | ||
export LIBRARY_PATH= | ||
export CFLAGS= | ||
export LDFLAGS= | ||
export CCFLAGS= | ||
export CXXFLAGS= | ||
export CPPFLAGS= | ||
|
||
# prepare | ||
rm -rf "$VIRTUAL_ENV/packages" | ||
mkdir -p "$VIRTUAL_ENV/packages" && cd "$VIRTUAL_ENV/packages" || exit 1 | ||
|
||
CORE=xapian-core-$VERSION | ||
BINDINGS=xapian-bindings-$VERSION | ||
|
||
# download | ||
echo "Downloading source..." | ||
curl -O "https://oligarchy.co.uk/xapian/$VERSION/${CORE}.tar.xz" | ||
curl -O "https://oligarchy.co.uk/xapian/$VERSION/${BINDINGS}.tar.xz" | ||
|
||
# extract | ||
echo "Extracting source..." | ||
tar xf "${CORE}.tar.xz" | ||
tar xf "${BINDINGS}.tar.xz" | ||
|
||
# install | ||
echo "Installing Xapian-core..." | ||
cd "$VIRTUAL_ENV/packages/${CORE}" || exit 1 | ||
./configure --prefix="$VIRTUAL_ENV" && make && make install | ||
|
||
PYTHON_FLAG=--with-python3 | ||
|
||
echo "Installing Xapian-bindings..." | ||
cd "$VIRTUAL_ENV/packages/${BINDINGS}" || exit 1 | ||
./configure --prefix="$VIRTUAL_ENV" $PYTHON_FLAG XAPIAN_CONFIG="$VIRTUAL_ENV/bin/xapian-config" && make && make install | ||
|
||
# clean | ||
rm -rf "$VIRTUAL_ENV/packages" | ||
|
||
# test | ||
python -c "import xapian" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.