├── README.md ├── LICENSE ├── .gitignore └── makefake /README.md: -------------------------------------------------------------------------------- 1 | # makefake 2 | 3 | Create fake pacman packages to satisfy dependencies that should be optdepends in the first place! 4 | 5 | This script generates a PKGBUILD for an almost empty package, then builds and installs it with makepkg. Run `./makefake --help` for usage, or just run `./makefake --version 1.2.3 legitpackage` for the most common scenario. Your fake package can provide multiple packages, just add more package names. 6 | 7 | Note that `IgnorePkg` in `/etc/pacman.conf` achieves similar results - this script should be used only if that solution doesn't satisfy you for some reason. In my case that's because I sync `/etc/pacman.conf` between all my computers and cannot install certain packages on one of them due to odd constraints on that machine. Just faking some packages is easier this way. 8 | 9 | **DON'T REPORT BUGS IN ARCH PACKAGES IF YOU HAVE FAKED ANY DEPENDENCIES IN THEIR PACTREE. DON'T FAKE BASE OR BASE-DEVEL PACKAGES.** If you want to fake install `gtk3`, sure, you can do that, but don't be surprised when all Gtk+3 apps stop working. This is a dangerous tool - use it wisely and sparingly. 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Dragoon Aethis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /makefake: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import argparse, string, tempfile, subprocess 3 | from urllib.parse import urlparse 4 | from typing import List 5 | 6 | VALID_NAME = string.ascii_letters + string.digits + '@._+-' 7 | VALID_VERSION = string.ascii_letters + string.digits + '@._+' 8 | VALID_DESCRIPTION = string.ascii_letters + string.digits + string.punctuation + ' ' 9 | 10 | PKGBUILD_TEMPLATE = """ 11 | pkgname={name} 12 | pkgver={version} 13 | pkgrel={pkgrel} 14 | pkgdesc="{description}" 15 | arch=('any') 16 | url="{url}" 17 | provides=({provides}) 18 | 19 | package() {opbracket} 20 | mkdir -p "$pkgdir/usr/share/makefake" 21 | touch "$pkgdir/usr/share/makefake/{name}" 22 | {endbracket}""" 23 | 24 | 25 | class FakePackage(object): 26 | """Class representing the fake package being built.""" 27 | def __init__(self, provides: List[str], 28 | name: str = None, 29 | version: str = "1.0.0", 30 | pkgrel: int = 1, 31 | description: str = None, 32 | url: str = "https://github.com/DragoonAethis/makefake"): 33 | super(FakePackage, self).__init__() 34 | 35 | self.provides = provides 36 | if len(self.provides) < 1: 37 | raise Exception("At least one package or resource must be provided by a fake package.") 38 | 39 | for provide in provides: 40 | if not all(char in VALID_NAME for char in provide): 41 | raise Exception(f"{provide} is not a valid provides name (range: {VALID_NAME})") 42 | 43 | first_provides = provides[0] 44 | 45 | if not name: 46 | self.name = f"fake-{first_provides}" 47 | else: 48 | if not all(char in VALID_NAME for char in name): 49 | raise Exception(f"{name} is not a valid package name (range: {VALID_NAME})") 50 | 51 | if name.startswith('-') or name.startswith('.'): 52 | raise Exception(f"{name} is not a valid package name (cannot start with a hyphen/dot)") 53 | 54 | self.name = str(name) 55 | 56 | if not all(char in VALID_VERSION for char in version): 57 | raise Exception(F"{version} is nto a valid package version (range: {VALID_VERSION}") 58 | 59 | self.version = version 60 | self.pkgrel = pkgrel 61 | 62 | if not description: 63 | self.description = f"Fake package providing {self.name} (generated with makefake)" 64 | else: 65 | if not all(char in VALID_DESCRIPTION for char in description): 66 | raise Exception(f"{description} is not a valid package description (range: {VALID_DESCRIPTION}") 67 | 68 | self.description = str(description) 69 | 70 | parsed_url = urlparse(url) 71 | if not(parsed_url.scheme) or not(parsed_url.netloc): 72 | raise Exception("{url} is not a valid URL.") 73 | 74 | self.url = url 75 | 76 | def generate_pkgbuild(self): 77 | provides = " ".join([f"'{x}'" for x in self.provides]) 78 | return PKGBUILD_TEMPLATE.format(provides=provides, name=self.name, description=self.description, 79 | version=self.version, pkgrel=self.pkgrel, url=self.url, 80 | opbracket='{', endbracket='}') # mmm lazy workarounds 81 | 82 | 83 | if __name__ == "__main__": 84 | parser = argparse.ArgumentParser( 85 | description="Creates and installs a fake pacman package providing given packages.", 86 | epilog="See https://github.com/DragoonAethis/makefake for more information.") 87 | parser.add_argument('provides', metavar='PROVIDES', type=str, nargs='+', help="packages or resourcs to provide") 88 | parser.add_argument('--name', default=None, type=str, help="fake package name") 89 | parser.add_argument('--version', metavar="VER", default="1.0.0", type=str, help="fake version") 90 | parser.add_argument('--pkgrel', metavar="REL", default=1, type=str, help="fake pkgrel") 91 | parser.add_argument('--description', metavar="DESC", default=None, type=str, help="fake package description") 92 | parser.add_argument('--url', default="https://github.com/DragoonAethis/makefake", type=str, help="fake package URL") 93 | parser.add_argument('--print-only', action='store_true', help="display the generated PKGBUILD only") 94 | args = parser.parse_args() 95 | 96 | fake_pkg = FakePackage(args.provides, name=args.name, version=args.version, 97 | pkgrel=args.pkgrel, description=args.description, url=args.url) 98 | 99 | contents = fake_pkg.generate_pkgbuild() 100 | 101 | if args.print_only: 102 | print(contents) 103 | else: 104 | with tempfile.TemporaryDirectory() as tempdir: 105 | with open(f"{tempdir}/PKGBUILD", 'wt') as pkgbuild: 106 | pkgbuild.write(contents) 107 | 108 | subprocess.run(["makepkg", "-si"], cwd=tempdir) 109 | --------------------------------------------------------------------------------