{ "cells": [ { "cell_type": "markdown", "id": "0b397cbb-8db3-40d9-a0a9-27ba0a774021", "metadata": {}, "source": [ "## Automatically creating new binhost directories when profile or gcc version changes" ] }, { "cell_type": "markdown", "id": "97c6e8be-a571-4fea-84c4-b226f03f56c6", "metadata": {}, "source": [ "On Gentoo Linux packages are compiled which is a time and energy consuming.\n", "To minimise both, I have a binhost to share compiled binaries between devices.\n", "The issues occurs when gcc major version changes - or a profile bump happens.\n", "If I do not notice either - problem. Binaries might not be compatible.\n", "So I wanted to automate a process of detection of those changes and automatically create subfolder for new binaries.\n", "When investigating I learned a neat trick. For the wise ones this is trivial, for me it was enligtening.\n", "Here it comes." ] }, { "cell_type": "markdown", "id": "2a688afd-5f24-4eab-a1c7-119d372367b5", "metadata": {}, "source": [ "On a regular system, emerge resides here:" ] }, { "cell_type": "code", "execution_count": null, "id": "b1098db8-2f77-4b56-acef-f58113107dad", "metadata": {}, "outputs": [], "source": [ "$ which emerge\n", "/usr/bin/emerge" ] }, { "cell_type": "markdown", "id": "9a1dcd6c-3f8c-455f-9d56-21e5157d0846", "metadata": {}, "source": [ "On my box with binhost:" ] }, { "cell_type": "code", "execution_count": null, "id": "bcb9918c-20fb-49fd-baaf-b3b63356de5a", "metadata": {}, "outputs": [], "source": [ "$ which emerge\n", "/usr/local/bin/emerge" ] }, { "cell_type": "markdown", "id": "a84cf35c-e744-47c9-9500-d9b8c7d3bfef", "metadata": {}, "source": [ "And here is $PATH:" ] }, { "cell_type": "code", "execution_count": null, "id": "94092561-ae6b-41eb-831a-71bffcf30e6e", "metadata": {}, "outputs": [], "source": [ "$ echo $PATH\n", "/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin" ] }, { "cell_type": "markdown", "id": "eb05de7d-f2f3-4cd3-acc2-769e096a3a5b", "metadata": {}, "source": [ "So we see that on binhost box, there is emerge that resides in location preceeding regular emerge - so it gets called first.\n", "It contains a shell script as follows:" ] }, { "cell_type": "code", "execution_count": null, "id": "b9f78265-a1de-47eb-be21-bb66c1ed3bed", "metadata": {}, "outputs": [], "source": [ "#!/usr/bin/env bash\n", "#\n", "# Script checking that binhost path exists before running emerge and\n", "# creating it if not exists\n", "\n", "PROFILE=$(eselect profile show|sed -n 2p|cut -d '/' -f4)\n", "GCC_VERSION=$(eselect gcc show|cut -d '-' -f5)\n", "BINHOST_DIR=\"/var/cache/binpkgs/${PROFILE}/gcc-${GCC_VERSION}.x/armv8a\"\n", "\n", "if [ ! -d \"${BINHOST_DIR}\" ]; then\n", " echo \"${BINHOST_DIR} does not exist, creating\"\n", " mkdir -p \"${BINHOST_DIR}\"\n", "else echo \"Binhost directory ${BINHOST_DIR} exists, proceeding with emerge ...\"\n", "fi\n", "\n", "PKGDIR=\"${BINHOST_DIR}\" /usr/bin/emerge \"$@\"" ] }, { "cell_type": "markdown", "id": "d6d085ea-b68f-4220-adaf-00223393e58e", "metadata": {}, "source": [ "So on every profile change subfolder to /var/cache/binpkgs gets created,\n", "on every gcc major version change, subfolder to /var/cache/binpkgs/ gets created.\n", "If folder already exists script only prints a message.\n", "Then it calls /usr/bin/emerge - the regular emerge - with $PKGDIR variable, so binary packages are saved to the correct directory. " ] }, { "cell_type": "markdown", "id": "1d464645-b7ac-4cbc-b5cc-1bd4bd976f06", "metadata": {}, "source": [ "This is structure of /var/cache/binpkgs:" ] }, { "cell_type": "code", "execution_count": null, "id": "dee2b348-d16d-4709-a7cd-ac9424934009", "metadata": {}, "outputs": [], "source": [ "$ tree -L 3 /var/cache/binpkgs/\n", "/var/cache/binpkgs/\n", "├── 17.0\n", "│   └── gcc-13.x\n", "│   └── armv8a\n", "└── 23.0\n", " ├── gcc-13.x\n", " │   └── armv8a\n", " └── gcc-14.x\n", " └── armv8a" ] }, { "cell_type": "markdown", "id": "9f8f4a71-9fd1-4678-9cb0-a580c94f4582", "metadata": {}, "source": [ "One less thing to worry about." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 5 }