diff --git a/.github/workflows/package_and_release.yml b/.github/workflows/package_and_release.yml new file mode 100644 index 0000000..200006a --- /dev/null +++ b/.github/workflows/package_and_release.yml @@ -0,0 +1,141 @@ +name: 'Test, package and draft release' +on: + workflow_dispatch: + push: + branches: + # If we don't specify a branch, the workflow will trigger itself when the release is published. + master +jobs: + build_and_test_apk: + uses: ./.github/workflows/packagetool.yml + with: + package_system: 'apk' + run_tests: true + produce_artifact: true + use_build_cache: true + build_and_test_deb: + uses: ./.github/workflows/packagetool.yml + with: + package_system: 'deb' + run_tests: true + produce_artifact: true + use_build_cache: true + build_and_test_rpm: + uses: ./.github/workflows/packagetool.yml + with: + package_system: 'rpm' + run_tests: true + produce_artifact: true + use_build_cache: true + prepare_release: + needs: + - build_and_test_apk + - build_and_test_deb + - build_and_test_rpm + runs-on: ubuntu-latest + env: + CURL_BOILERPLATE: | + curl -fsSL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" \ + steps: + - uses: actions/checkout@v3 + - name: Gather variables + id: jobenv + run: | + current_time="$(date -u '+%s')" + printf 'HUMAN_TIME=%s\n' "$(date -u -d "@$current_time" '+%Y-%m-%d %H:%M:%SZ')" | tee "$GITHUB_OUTPUT" + printf 'GIT_TAG_TIME=%s\n' "$(date -u -d "@$current_time" '+%Y-%m-%dT%H_%M_%SZ')" | tee -a "$GITHUB_OUTPUT" + commit_time="$(git log -1 --pretty=%ct ${{ github.sha }})" + printf 'HUMAN_COMMIT_TIME=%s\n' "$(date -u -d "@$commit_time" '+%Y-%m-%d %H:%M:%SZ')" | tee -a "$GITHUB_OUTPUT" + printf 'COMMIT_MESSAGE=%s\n' "$(git log -1 --pretty=%s ${{ github.sha }})" | tee -a "$GITHUB_OUTPUT" + - name: Download all artifacts + uses: actions/download-artifact@v3 + with: + path: /tmp/artifacts + - name: Create tarballs + run: | + mkdir -p /tmp/tarballs + for artifact_dir in /tmp/artifacts/*; do + artifact_name="${artifact_dir##*/}" + tar -C "$artifact_dir" -czvf "/tmp/tarballs/$artifact_name.tar.gz" . + done + - name: Create release draft + id: create_release + env: + RELEASE_TAG: snapshot-${{ steps.jobenv.outputs.GIT_TAG_TIME }} + RELEASE_TEXT_TITLE: Snapshot ${{ steps.jobenv.outputs.HUMAN_TIME }} - "${{ steps.jobenv.outputs.COMMIT_MESSAGE }}" + RELEASE_TEXT_BODY: | + Packaged commit: [`${{ github.sha }}`](../../tree/${{ github.sha }}) from `${{ steps.jobenv.outputs.HUMAN_COMMIT_TIME }}` + # Assets: + | Archive name | Contents | Notes | + | ------------ | -------- | ----- | + | `release-alpine-akms-apk.tar.gz` | Module and supporting files as Alpine Linux '.apk' packages. | | + | `release-alpine-akms-manual.tar.gz` | Module and supporting files for Alpine Linux via manual installation. | | + | `release-debian-dkms-deb.tar.gz` | Module as Debian '.deb' package. | Currently does not include package for `ignore_resource_conflict` option (can be configured manually in `/etc/modprobe.d/`). | + | `release-redhat-akmods-rpm.tar.gz` | Module and supporting files as Red Hat '.rpm' packages, also works with Fedora Silverblue & co. | | + | `release-redhat-akmods-source-rpm.tar.gz` | Source RPMs (for debugging and inspection). | | + + For more information, please see ["Package Overview"](../HEAD/packagetool_quickstart.md#package-overview) in `packagetool_quickstart.md`. + + # General information: + - For Alpine Linux with either method, installing the `linux-{flavor}-dev` (usually `linux-lts-dev`) package is recommended, otherwise `akms` will temporarily download it at the time of building, requiring an internet connection. + - The `ignore_resource_conflict` packages should only be installed if the module fails to load otherwise. + - In the manual Alpine Linux installation, `/etc/modprobe.d/it87-oot.conf` corresponds to the aforementioned package. + - A reboot is recommended after installing the module or (un)installing the `ignore_resource_conflict` package. + run: | + release_json_data="$(jq -n \ + --arg tag_name "$RELEASE_TAG" \ + --arg tag_commitish "${{ github.sha }}" \ + --arg name "$RELEASE_TEXT_TITLE" \ + --arg body "$RELEASE_TEXT_BODY" \ + --argjson draft true \ + --argjson prerelease false \ + '{ tag_name: $tag_name, target_commitish: $tag_commitish, name: $name, body: $body, draft: $draft, prerelease: $prerelease }' + )" + # If prerelease is true, the preview won't show in the sidebar on the repo's main page when published. + # Always insert strings with newlines, quotes, etc. as shell variables, not GH Actions contexts! + printf '%s\n' "-> Will send the following JSON data to the GitHub Releases API:" + printf '%s\n' "$release_json_data" | jq + + latest_release="$( + ${{ env.CURL_BOILERPLATE }} "https://api.github.com/repos/${{ github.repository }}/releases?per_page=1" + )" + printf '%s\n' "-> Latest release:" + printf '%s\n' "$latest_release" | jq + + # Should we create a new release or replace the latest draft? ('null' = no releases yet) + latest_release_is_draft="$(printf '%s\n' "$latest_release" | jq -r '.[0].draft')" + latest_release_is_snapshot="$(printf '%s\n' "$latest_release" | jq -r '.[0].tag_name' | grep -q '^snapshot-' && printf 'true' || printf 'false')" + printf '%s\n' "-> Is the latest release a draft? '$latest_release_is_draft'" "-> Is the latest release a snapshot? '$latest_release_is_snapshot'" + + if [ "$latest_release_is_draft" == 'true' ] && [ "$latest_release_is_snapshot" == 'true' ]; then + printf '%s\n' "-> Replacing latest snapshot draft." + latest_release_id="$(printf '%s\n' "$latest_release" | jq -r '.[0].id')" + # We could update the latest release, but deleting and making a new one is more efficient. + ${{ env.CURL_BOILERPLATE }} "https://api.github.com/repos/${{ github.repository }}/releases/$latest_release_id" -X DELETE + api_response="$( + ${{ env.CURL_BOILERPLATE }} "https://api.github.com/repos/${{ github.repository }}/releases" -X POST -d "$release_json_data" + )" + else + printf '%s\n' "-> Creating new snapshot draft." + api_response="$( + ${{ env.CURL_BOILERPLATE }} "https://api.github.com/repos/${{ github.repository }}/releases" -X POST -d "$release_json_data" + )" + fi + + printf '%s\n' "-> Response from the GitHub Releases API:" + printf '%s\n' "$api_response" | jq + + # We need to remove the {?name,label} part from the upload_url + release_upload_url="$(printf '%s\n' "$api_response" | jq -r '.upload_url' | sed 's/{.*$//')" + printf 'RELEASE_UPLOAD_URL=%s\n' "$release_upload_url" | tee -a "$GITHUB_OUTPUT" + - name: Upload release assets + run: | + for tarball in /tmp/tarballs/*; do + tarball_name="${tarball##*/}" + printf '%s\n' "-> Uploading '$tarball_name'" + api_response="$( + ${{ env.CURL_BOILERPLATE }} "${{ steps.create_release.outputs.RELEASE_UPLOAD_URL }}?name=$tarball_name" -X POST -H "Content-Type: application/gzip" --data-binary "@$tarball" + )" + printf '%s\n' "-> Response from the GitHub Releases Assets API:" + printf '%s\n' "$api_response" | jq + done diff --git a/.github/workflows/packagetool.yml b/.github/workflows/packagetool.yml new file mode 100644 index 0000000..39eb910 --- /dev/null +++ b/.github/workflows/packagetool.yml @@ -0,0 +1,131 @@ +name: 'packagetool.sh wrapper' +on: + workflow_call: + inputs: + package_system: + description: 'The package system to use' + required: true + type: string + run_tests: + description: 'Run tests after building the package' + required: false + default: true + type: boolean + produce_artifact: + description: 'Produce an artifact from the .release folder' + required: false + default: true + type: boolean + use_build_cache: + description: 'Use the weekly build cache' + required: false + default: true + type: boolean + workflow_dispatch: + inputs: + package_system: + description: 'The package system to use' + required: true + type: choice + options: + - 'apk' + - 'deb' + - 'rpm' + run_tests: + description: 'Run tests after building the package' + required: false + default: true + type: boolean + produce_artifact: + description: 'Produce an artifact from the .release folder' + required: false + default: true + type: boolean + use_build_cache: + description: 'Use the weekly build cache' + required: false + default: true + type: boolean +jobs: + packagetool: + runs-on: ubuntu-latest + env: + PACKAGE_SYSTEM: ${{ inputs.package_system }} + DOCKER_CACHE_DIR: ${{ format('/tmp/GitHubActions-DockerCache-{0}', inputs.package_system) }} + steps: + - uses: actions/checkout@v3 + - name: Set up job environment + id: jobenv + run: | + printf 'CACHE_YEAR_AND_WEEK=%s\n' "$(date -u '+Y%YW%V')" | tee -a "$GITHUB_OUTPUT" + docker buildx create --name packagetool-builder --use + mkdir -p "${{ env.DOCKER_CACHE_DIR }}" + - name: GitHub Actions Cache for Docker (no tests) + # Note: We separate the caches since we don't want to end up saving a cache without the build dependencies, which + # tend to be the largest part of the cache. This could be handled better, but it would be unnecessarily complex. + # The problem is mainly that once created, GitHub actions caches are read only. + if: ${{ !inputs.run_tests && inputs.use_build_cache }} + uses: actions/cache@v3 + with: + path: ${{ env.DOCKER_CACHE_DIR }} + key: docker-cache-${{ env.PACKAGE_SYSTEM }}-lite-${{ steps.jobenv.outputs.CACHE_YEAR_AND_WEEK }} + - name: Run packagetool.sh (no tests) + # Note: For some reason we get "permission denied" when trying to delete the temp dir after running with Docker. + # Fortunately we have an option for that and it's fine since the filesystem doesn't persist between runs. + if: ${{ !inputs.run_tests }} + run: | + ./packagetool.sh \ + --container_runtime=docker-buildx \ + --package_system=${{ env.PACKAGE_SYSTEM }} \ + $(if [ "${{ inputs.use_build_cache }}" == 'true' ]; then printf '%s' "--local_cache_dir=${{ env.DOCKER_CACHE_DIR }}"; fi) \ + $(if [ "${{ inputs.use_build_cache }}" == 'true' ]; then printf '%s' "--local_cache_ci_mode"; fi) \ + --keep_temp_dir \ + --print_temp_dir=normal + - name: GitHub Actions Cache for Docker (with tests) + if: ${{ inputs.run_tests && inputs.use_build_cache }} + uses: actions/cache@v3 + with: + path: ${{ env.DOCKER_CACHE_DIR }} + key: docker-cache-${{ env.PACKAGE_SYSTEM }}-${{ steps.jobenv.outputs.CACHE_YEAR_AND_WEEK }} + - name: Run packagetool.sh (with tests) + if: ${{ inputs.run_tests }} + run: | + ./packagetool.sh \ + --container_runtime=docker-buildx \ + --package_system=${{ env.PACKAGE_SYSTEM }} \ + --run_build_tests \ + $(if [ "${{ inputs.use_build_cache }}" == 'true' ]; then printf '%s' "--local_cache_dir=${{ env.DOCKER_CACHE_DIR }}"; fi) \ + $(if [ "${{ inputs.use_build_cache }}" == 'true' ]; then printf '%s' "--local_cache_ci_mode"; fi) \ + --keep_temp_dir \ + --container_security_privileged \ + --print_temp_dir=normal + - name: Upload package artifact (alpine-akms-apk) + if: ${{ inputs.produce_artifact && inputs.package_system == 'apk' }} + uses: actions/upload-artifact@v3 + with: + name: release-alpine-akms-apk + path: ./.release/apk + - name: Upload package artifact (alpine-akms-manual) + if: ${{ inputs.produce_artifact && inputs.package_system == 'apk' }} + uses: actions/upload-artifact@v3 + with: + name: release-alpine-akms-manual + path: ./.release/akms + - name: Upload package artifact (debian-dkms-deb) + if: ${{ inputs.produce_artifact && inputs.package_system == 'deb' }} + uses: actions/upload-artifact@v3 + with: + name: release-debian-dkms-deb + path: ./.release + - name: Upload package artifact (redhat-akmods-rpm) + if: ${{ inputs.produce_artifact && inputs.package_system == 'rpm' }} + uses: actions/upload-artifact@v3 + with: + name: release-redhat-akmods-rpm + path: ./.release/RPMS + - name: Upload package artifact (redhat-akmods-source-rpm) + if: ${{ inputs.produce_artifact && inputs.package_system == 'rpm' }} + uses: actions/upload-artifact@v3 + with: + name: release-redhat-akmods-source-rpm + path: ./.release/SRPMS \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9991e95..a1fdf19 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /Module.symvers /modules.order + +.release/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Makefile b/Makefile index 899e404..bbb6648 100644 --- a/Makefile +++ b/Makefile @@ -28,10 +28,10 @@ SYSTEM_MAP = /proc/kallsyms endif DRIVER := it87 +ifndef DRIVER_VERSION ifneq ("","$(wildcard .git/*)") DRIVER_VERSION := $(shell git describe --long).$(shell date -d "$(git show -s --format=%ci HEAD)" +%Y%m%d) -else -ifneq ("", "$(wildcard VERSION)") +else ifneq ("", "$(wildcard VERSION)") DRIVER_VERSION := $(shell cat VERSION) else DRIVER_VERSION := unknown diff --git a/README.md b/README.md new file mode 100644 index 0000000..c5bb14b --- /dev/null +++ b/README.md @@ -0,0 +1,248 @@ +# About the project + +The `it87` kernel module provides support for [certain ITE Super I/O chips](#supported-chips). This fork introduces support for more chips and functionality to the module. + +# Installing the module +## Installing with `make` +### Build +1. `make clean` +2. `make` + +### Install for current kernel +- `sudo make install` +### Install to DKMS +- `sudo make dkms` +### Remove from DKMS +- `sudo make dkms_clean` + +### Notes: +* The module does not provide a real version number, so `git describe --long` is used to create one. This means that anything that changes the git state will change the version. `make dkms_clean` should be run before making a commit or an update with `git pull` as the Makefile is currently unable to track the last installed version to replace it. If this doesn't happen, the old version will need to be manually removed from dkms, before installing the updated module. + + Something like `dkms remove -m it87 -v --all`, followed by `rm -rf /usr/src/it87-`, should do. + + `dkms status it87` can be used to list the installed versions. + +## Installing as a package: `.apk` (AKMS)/`.rpm` (akmods)/`.deb` (DKMS) +**Note:** `.apk` refers to Alpine Linux packages. The `.rpm` package also works with OSTree systems like Fedora Silverblue. + +* Pre-packaged versions via CI can be found on the repo's releases page: **[Latest Release](../../releases/latest)** (**[All Releases](../../releases)**, **[Workflow Status](../../actions)**) +* A quick start guide for building packages locally can be found **[here](/packagetool_quickstart.md)**. + +## Arch Linux AUR Package +* **https://aur.archlinux.org/packages/it87-dkms-git** + + **Note:** This package is maintained externally and may use a different repository than this one. + +# Module Parameters +* `fix_pwm_polarity=`*\[bool\]* + + If `true`, force PWM polarity to active high **(DANGEROUS)**. Some chips are misconfigured by the motherboard firmware, causing PWM values to be inverted. This option tries to correct this. Please contact your motherboard manufacturer and ask them for a fix. + +* `force_id=`*\[short, short\]* + + Force multiple chip ID to specified value, separated by `,`. For example `force_id=0x8689,0x8633`. A value of `0` is ignored for that chip. + + **Note:** A single force_id value (e.g. `force_id=0x8689`) is used for all chips, to only set the first chip use `force_id=0x8689,0`. Should only be used for testing. + +* `ignore_resource_conflict=`*\[bool\]* + + Similar to `acpi_enforce_resources=lax`, but only affects this driver. Provided since there are reports that system-wide `acpi_enfore_resources=lax` can result in boot failures on some systems. + + **Note:** This is inherently risky since it means that both ACPI and this driver may access the chip at the same time. This can result in race conditions and, worst case, result in unexpected system reboots. + +* `mmio=`*\[bool\]* + + If `true`, the driver uses MMIO to access the chip if supported. This is faster and less risky (untested!). + +* `update_vbat=`*\[bool\]* + + `false` if vbat should report power on value, `true` if vbat should be updated after each read. Default is `false`. On some boards the battery voltage is provided by either the battery or the onboard power supply. Only the first reading at power on will be the actual battery voltage (which the chip does automatically). On other boards the battery voltage is always fed to the chip so can be read at any time. Excessive reading may decrease battery life but no information is given in the datasheet. + +# Hardware Support +**Please note: The information below has been largely transferred from an older version of the readme and may be inaccurate or incomplete.** + +## Hardware Interfaces +All the chips supported by this driver are LPC Super-I/O chips, accessed through the LPC bus (ISA-like I/O ports). The IT8712F additionally has an SMBus interface to the hardware monitoring functions. This driver no longer supports this interface though, as it is slower and less reliable than the ISA access, and was only available on a small number of motherboard models. + +## Supported Chips +*Note about datasheets: Supposedly some used to be publicly available from the manufacturer. Nowadays they might be still available from third party sites, inclusion in this list is TBD.* + +*Note about the list: At the moment the list is incomplete and may contain errors.* + +| Chip | Prefix | Comments | Datasheet +| ---- | ------ | -------- | --------- +| IT8603E | `it8603` | | TBD | +| IT8606E | `it8606` | | TBD | +| IT8607E | `it8607` | | TBD | +| IT8613E | `it8613` | | TBD | +| IT8620E | `it8620` | | TBD | +| IT8622E | `it8622` | | TBD | +| IT8623E | `it8603` | | TBD | +| IT8625E | `it8625` | | TBD | +| IT8628E | `it8628` | | TBD | +| IT8528E | ??? | | TBD | +| IT8655E | `it8655` | | TBD | +| IT8665E | `it8665` | | TBD | +| IT8686E | `it8686` | | TBD | +| IT8688E | `it8688` | | TBD | +| IT8689E | `it8689` | | TBD | +| IT8695E | ??? | | TBD | +| IT8705F | `it87` | | TBD | +| IT8712F | `it8712` | | TBD | +| IT8716F | `it8716` | | TBD | +| IT8718F | `it8718` | | TBD | +| IT8720F | `it8720` | | TBD | +| IT8721F | `it8721` | | TBD | +| IT8726F | `it8716` | | TBD | +| IT8728F | `it8728` | | TBD | +| IT8732F | `it8732` | | TBD | +| IT8736F | `it8736` | | TBD | +| IT8738E | `it8738` | | TBD | +| IT8758E | `it8721` | | TBD | +| IT8771E | `it8771` | | TBD | +| IT8772E | `it8772` | | TBD | +| IT8781F | `it8781` | | TBD | +| IT8782F | `it8782` | | TBD | +| IT8783E | `it8783` | | TBD | +| IT8783F | `it8783` | | TBD | +| IT8786E | `it8786` | | TBD | +| IT8790E | `it8790` | | TBD | +| IT8792E | `it8792` | | TBD | +| IT8795E | `it8792` | | TBD | +| IT87952E | `it87952` | | TBD | +| Sis950 | `it87` | A clone of the IT8705F | TBD | + +These chips are "Super I/O chips", supporting floppy disks, infrared ports, joysticks and other miscellaneous stuff. For hardware monitoring, they include an "environment controller" with temperature sensors, fan rotation speed sensors, voltage sensors, associated alarms, and chassis intrusion detection. + +* IT8712F and IT8716F additionally feature VID inputs, used to report the Vcore voltage of the processor. The early IT8712F have 5 VID pins, the IT8716F and late IT8712F have 6. They are shared with other functions though, so the functionality may not be available on a given system. + +* IT8718F and IT8720F also features VID inputs (up to 8 pins) but the value is stored in the Super-I/O configuration space. Due to technical limitations, this value can currently only be read once at initialization time, so the driver won't notice and report changes in the VID value. The two upper VID bits share their pins with voltage inputs (in5 and in6) so you can't have both on a given board. + +* IT8716F, IT8718F, IT8720F, IT8721F/IT8758E and later IT8712F revisions have support for 2 additional fans. The additional fans are supported by the driver. + +* IT8716F, IT8718F, IT8720F, IT8721F/IT8758E, IT8732F, IT8781F, IT8782F, IT8783E/F, and late IT8712F and IT8705F also have optional 16-bit tachometer counters for fans 1 to 3. This is better (no more fan clock divider mess) but not compatible with the older chips and revisions. The 16-bit tachometer mode is enabled by the driver when one of the above chips is detected. + +* IT8726F is just bit enhanced IT8716F with additional hardware for AMD power sequencing. Therefore the chip will appear as IT8716F to userspace applications. + +* IT8728F, IT8771E, and IT8772E are considered compatible with the IT8721F, until a datasheet becomes available (hopefully.) + +* IT8603E/IT8623E is a custom design, hardware monitoring part is similar to IT8728F. It only supports 3 fans, 16-bit fan mode, and the full speed mode of the fan is not supported (value 0 of pwmX_enable). + +* IT8620E and IT8628E are custom designs, hardware monitoring part is similar to IT8728F. It only supports 16-bit fan mode. Both chips support up to 6 fans. + +* IT8790E supports up to 3 fans. 16-bit fan mode is always enabled. + +* IT8732F supports a closed-loop mode for fan control, but this is not currently implemented by the driver. + +* IT87xx only updates its values each 1.5 seconds; reading it more often will do no harm, but will return 'old' values. + +Temperatures are measured in degrees Celsius. An alarm is triggered once when the Overtemperature Shutdown limit is crossed. + +Fan rotation speeds are reported in RPM (rotations per minute). An alarm is triggered if the rotation speed has dropped below a programmable limit. When 16-bit tachometer counters aren't used, fan readings can be divided by a programmable divider (1, 2, 4 or 8) to give the readings more range or accuracy. With a divider of 2, the lowest representable value is around 2600 RPM. Not all RPM values can accurately be represented, so some rounding is done. + +Voltage sensors (also known as IN sensors) report their values in volts. An alarm is triggered if the voltage has crossed a programmable minimum or maximum limit. Note that minimum in this case always means 'closest to zero'; this is important for negative voltage measurements. On most chips, all voltage inputs can measure voltages between 0 and 4.08 volts, with a resolution of 0.016 volt. IT8603E, IT8721F/IT8758E and IT8728F can measure between 0 and 3.06 volts, with a resolution of 0.012 volt. IT8732F can measure between 0 and 2.8 volts with a resolution of 0.0109 volt. The battery voltage in8 does not have limit registers. + +On the IT8603E, IT8620E, IT8628E, IT8721F/IT8758E, IT8732F, IT8781F, IT8782F, and IT8783E/F, some voltage inputs are internal and scaled inside the chip: +* in3 (optional) +* in7 (optional for IT8781F, IT8782F, and IT8783E/F) +* in8 (always) +* in9 (relevant for IT8603E only) + +The driver handles this transparently so user-space doesn't have to care. + +The VID lines (IT8712F/IT8716F/IT8718F/IT8720F) encode the core voltage value: the voltage level your processor should work with. This is hardcoded by the mainboard and/or processor itself. It is a value in volts. + +If an alarm triggers, it will remain triggered until the hardware register is read at least once. This means that the cause for the alarm may already have disappeared! Note that in the current implementation, all hardware registers are read whenever any data is read (unless it is less than 1.5 seconds since the last update). This means that you can easily miss once-only alarms. + +Out-of-limit readings can also result in beeping, if the chip is properly wired and configured. Beeping can be enabled or disabled per sensor type (temperatures, voltages and fans.) + + +To change sensor N to a thermistor, 'echo 4 > tempN_type' where N is 1, 2, or 3. To change sensor N to a thermal diode, 'echo 3 > tempN_type'. Give 0 for unused sensor. Any other value is invalid. To configure this at startup, consult lm_sensors's /etc/sensors.conf. (4 = thermistor; 3 = thermal diode) + +# Miscellaneous Information + +## Fan speed control +The fan speed control features are limited to manual PWM mode. Automatic "Smart Guardian" mode control handling is only implemented for older chips [(see below.)](#automatic-fan-speed-control-old-interface) However if you want to go for "manual mode" just write 1 to pwmN_enable. + +If you are only able to control the fan speed with very small PWM values, try lowering the PWM base frequency (pwm1_freq). Depending on the fan, it may give you a somewhat greater control range. The same frequency is used to drive all fan outputs, which is why pwm2_freq and pwm3_freq are read-only. + +## Automatic fan speed control (old interface) +The driver supports the old interface to automatic fan speed control which is implemented by IT8705F chips up to revision F and IT8712F chips up to revision G. + +This interface implements 4 temperature vs. PWM output trip points. + +The PWM output of trip point 4 is always the maximum value (fan running at full speed) while the PWM output of the other 3 trip points can be freely chosen. The temperature of all 4 trip points can be freely chosen. Additionally, trip point 1 has an hysteresis temperature attached, to prevent fast switching between fan on and off. + +The chip automatically computes the PWM output value based on the input temperature, based on this simple rule: if the temperature value is between trip point N and trip point N+1 then the PWM output value is the one of trip point N. The automatic control mode is less flexible than the manual control mode, but it reacts faster, is more robust and doesn't use CPU cycles. + +Trip points must be set properly before switching to automatic fan speed control mode. The driver will perform basic integrity checks before actually switching to automatic control mode. + +## Temperature offset attributes +The driver supports `temp[1-3]_offset` sysfs attributes to adjust the reported +temperature for thermal diodes or diode-connected thermal transistors. +If a temperature sensor is configured for thermistors, the attribute values +are ignored. If the thermal sensor type is Intel PECI, the temperature offset must be programmed to the critical CPU temperature. + +## Preliminary support +Support for IT8607E is preliminary. Voltage readings, temperature readings, +fan control, and fan speed measurements may be wrong and/or missing. +Fan control and fan speed may be enabled and reported for non-existing +fans. Please report any problems and inconsistencies. + +## Reporting information for unsupported chips +If the chip in your system is not yet supported by the driver, please provide the following information. + +First, run sensors-detect. It will tell you something like + + Probing for Super-I/O at 0x2e/0x2f + ... + Trying family `ITE'... Yes + Found unknown chip with ID 0x8665 + (logical device 4 has address 0x290, could be sensors) + +With this information, run the following commands. + + sudo isadump -k 0x87,0x01,0x55,0x55 0x2e 0x2f 7 + sudo isadump 0x295 0x296 + +and report the results. + +The addresses in the first command are from "Probing for Super-I/O at +0x2e/0x2f". Use those addresses in the first command. + + sudo isadump -k 0x87,0x01,0x55,0x55 0x2e 0x2f 7 + +The addresses in the second command are from "has address 0x290". +Add 5 and 6 to this address for the next command. + + sudo isadump 0x295 0x296 + +Next, force-install the driver by providing one of the already supported chips +as forced ID. Useful IDs to test are 0x8622, 0x8628, 0x8728, and 0x8732, though +feel free to test more IDs. For each ID, instantiate the driver as follows +(this example is instantiating driver with ID 0x8622). + + sudo modprobe it87 force_id=0x8622 + +After entering this command, run the "sensors" command and provide the output. +Then unload the driver with + + sudo modprobe -r it87 + +Repeat with different chip IDs, and report each result. + +Please also report your board type as well as voltages and fan settings from the BIOS. If possible, connect fans to different fan headers and let us know if all fans are detected and reported. + +This information _might_ give us enough information to add experimental support for the chip in question. No guarantees, though - unless a datasheet is available, something is likely to be wrong. + +## A note on sensors-detect: +There is a persistent perception that changes in this driver would have impact +on the output of sensors-detect. This is not the case. sensors-detect is an +independent application. Changes in this driver do not affect sensors-detect, and changes in sensors-detect do not affect this driver. + +# Past and present maintainers + +* Christophe Gauthron +* Jean Delvare \ +* Guenter Roeck \ +* *Incomplete List!* \ No newline at end of file diff --git a/README b/README_old.txt similarity index 100% rename from README rename to README_old.txt diff --git a/alpine/AKMBUILD b/alpine/AKMBUILD new file mode 100644 index 0000000..41201c1 --- /dev/null +++ b/alpine/AKMBUILD @@ -0,0 +1,14 @@ +# Placeholder information will be used if not inserted above (e.g. by a build wrapper) +_source_modname="${_source_modname:-it87}" +modver="${modver:-0}" +# Placeholder information end + +modname="${_source_modname}-oot" +built_modules="${_source_modname}.ko" + +build() { + for i in compat.h ${_source_modname}.c Makefile; do + cp "${srcdir}/${i}" "${builddir}/" + done + make $MAKEFLAGS TARGET="$kernel_ver" DRIVER_VERSION="$modver" modules +} diff --git a/alpine/APKBUILD b/alpine/APKBUILD new file mode 100644 index 0000000..75f2934 --- /dev/null +++ b/alpine/APKBUILD @@ -0,0 +1,94 @@ +# Placeholder information will be used if not inserted above (e.g. by a build wrapper) +_source_modname="${_source_modname:-"it87"}" +_repo_name="${_repo_name:-"it87"}" +# WARNING: This placeholder will download a very old version, ensure the repo info and commit hash are up-to-date +_repo_owner="${_repo_owner:-"frankcrawford"}" +_repo_commit="${_repo_commit:-"77abcbe0c49d7d8dc4530dcf51cecb40ef39f49a"}" +_package_timestamp="${_package_timestamp:-"$(date '+%Y%m%d')"}" +# 'source=' (no _ prefix) is expanded later in the script due to the default's reliance on other other variables. Override with filename only (no URL) to use local source file, local source is alongside the APKBUILD, remote source is downloaded to "./src", we have a check to account for that. +# Placeholder information end + +pkgname="${_source_modname}-oot" +pkgver=0_git${_package_timestamp} +pkgrel=1 +pkgdesc="Userland package for the out-of-tree version of the \"${_source_modname}\" module forked by \"${_repo_owner}\"" +url="https://github.com/${_repo_owner}/${_repo_name}" +arch="noarch" +license="GPL-2.0-or-later" +subpackages=" + ${pkgname}-akms:akms:x86_64 + ${pkgname}-doc:doc:noarch + ${pkgname}-ignore_resource_conflict:ignore_resource_conflict:noarch" +source=${source:-"${url}/tarball/${_repo_commit}/${_repo_name}.tar.gz"} +options="!check" +export install _source_dirname _source0 + + +prepare() { + default_prepare + + # For some reason, akms doesn't remove the module after the package is uninstalled. + # So we do it via a post-deinstall script, this may become unnecessary in the future. + # This would error if the user uninstalled the module via "akms" prior to the package, hence "|| exit 0". + install -D -m 0755 <(printf '%s\n\n%s\n' '#!/bin/sh' "akms uninstall -k all '${pkgname}' || exit 0") "${startdir}/${pkgname}-akms.post-deinstall" + install="${pkgname}-akms.post-deinstall" + + # Find where our source tarball is located, and set it as the _source0 variable similar to RPM's SOURCE0. + for i in "${PWD}" "${srcdir}"; do + [ -f "${i}/${_repo_name}.tar.gz" ] && _source0="${i}/${_repo_name}.tar.gz" + done + + # Dynamically get the name of the directory inside the tarball (we expect it to be the only item in the tarball root). + _source_dirname="$(tar -tzf "${_source0}" | head -n 1 | head -c -2)" + [ -f "${srcdir}/${_source_dirname}/Makefile" ] || { echo "ERROR: Makefile not found in expected location"; exit 1; } + + # This could theoretically be a problem, so we check for it to get a usable error message. + [ "${builddir##*/}" != "${_source_dirname}" ] || { echo "ERROR: builddir (from abuild) and _source_dirname (from tarball) are overlapping."; exit 1; } + mkdir -p "${builddir}" # It apparently isn't automatically created. + + printf '%s\n' "override ${_source_modname} * akms" >"${builddir}/depmod_${pkgname}.conf" + printf '%s\n' "${_source_modname}" >"${builddir}/modload_${pkgname}.conf" + printf '%s\n' "options ${_source_modname} ignore_resource_conflict=true" >"${builddir}/modprobe_${pkgname}.conf" + + # We save the AKMBUILD externally so it is still available for the manual installation + # First we write the overrides, then append the original AKMBUILD. + printf '%s\n' \ + "_source_modname='${_source_modname}'" \ + "modver='${pkgver}'" \ + >"${builddir}/akmbuild_${pkgname}" + cat "${srcdir}/${_source_dirname}/alpine/AKMBUILD" >>"${builddir}/akmbuild_${pkgname}" +} + +package() { + depends="${pkgname}-akms" # Userland and akms packages depend on each other + + # Apparently Alpine only reads these files from /etc/, not the corresponding /usr/ locations + install -D -m 0644 "${builddir}/depmod_${pkgname}.conf" "${pkgdir}/etc/depmod.d/${pkgname}.conf" + install -D -m 0644 "${builddir}/modload_${pkgname}.conf" "${pkgdir}/etc/modules-load.d/${pkgname}.conf" + + # We're supposed to let abuild handle the -doc package, it automatically moves /usr/share files into it. + install -D -m 0644 "${srcdir}/${_source_dirname}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" + install -D -m 0644 "${srcdir}/${_source_dirname}/README.md" "${pkgdir}/usr/share/doc/${pkgname}/README" + install -D -m 0644 "${srcdir}/${_source_dirname}/ISSUES" "${pkgdir}/usr/share/doc/${pkgname}/ISSUES" + install -D -m 0644 "${srcdir}/${_source_dirname}/debian/changelog" "${pkgdir}/usr/share/doc/${pkgname}/changelog" + cp -r "${srcdir}/${_source_dirname}/Sensors configs" "${pkgdir}/usr/share/doc/${pkgname}/Sensors configs" + # 'Research' is commented out because it's about 100x larger than the rest of the project files. + # cp -r "${srcdir}/${_source_dirname}/Research" "${pkgdir}/usr/share/doc/${pkgname}/Research" +} + +akms() { + depends=" + akms + ${pkgname} + " # Depends on akms AND the userland package + pkgdesc="akms package for the out-of-tree version of the \"${_source_modname}\" module forked by \"${_repo_owner}\"" + install -D -m 0644 "${builddir}/akmbuild_${pkgname}" "${subpkgdir}/usr/src/${pkgname}/AKMBUILD" + for i in "Makefile" "compat.h" "${_source_modname}.c" "LICENSE"; do + install -D -m 0644 "${srcdir}/${_source_dirname}/${i}" "${subpkgdir}/usr/src/${pkgname}/${i}" + done +} + +ignore_resource_conflict() { + pkgdesc="Optional "modprobe.d" entry for the "${_source_modname}" module to ignore ACPI resource conflicts." + install -D -m 0644 "${builddir}/modprobe_${pkgname}.conf" "${subpkgdir}/etc/modprobe.d/${pkgname}.conf" +} diff --git a/packagetool.sh b/packagetool.sh new file mode 100755 index 0000000..4b7b25d --- /dev/null +++ b/packagetool.sh @@ -0,0 +1,590 @@ +#!/usr/bin/env bash +set -e +software_name='it87' # Hardcoded default (see "gather_repo_info()") +[ -f "./it87.c" ] || { printf '%s\n' "Error: Expected to find file './it87.c', this program should be run from inside the repository's root directory."; exit 1; } + +# ----------------- +# Utility functions +# ----------------- +print_usage() { + usage="$(cat </dev/null || { printf '%s\n' "Error: Container runtime 'docker' not found in PATH"; will_exit_with_err='true'; } + docker buildx version &>/dev/null || { printf '%s\n' "Error: 'docker buildx' plugin is not available"; will_exit_with_err='true'; } + ;; + *) + command -v "$container_runtime" &>/dev/null || { printf '%s\n' "Error: Container runtime '$container_runtime' not found in PATH"; will_exit_with_err='true'; } + ;; + esac + fi + + [ "$will_exit_with_err" == 'false' ] || { printf '%s\n' "Error: Exiting due to argument parsing error, see above for details"; exit 1; } +} + +gather_repo_info() { + # Variables are only set if they haven't been set already (in the environment or previously in the script). + [ "$working_tree_changed" ] || + working_tree_changed="$(git diff-index --quiet HEAD -- &>/dev/null; printf '%s' "$?")" # Whether the working tree has been modified + + if [ "$working_tree_changed" == '0' ]; then # If the working tree is clean, use the commit date. $working_tree_changed is also >0 if we're not a git repository. + [ "$current_commit" ] || + current_commit="$(git rev-parse HEAD 2>/dev/null || printf 'unknown')" # Commit hash of the current commit + [ "$working_tree_timestamp" ] || + working_tree_timestamp="$(git show -s --format=%ct "${current_commit}" 2>/dev/null || printf '%s' "$(date '+%s')")" + else # If working tree is dirty or invalid, use the current date + [ "$current_commit" ] || + current_commit='unknown' + [ "$working_tree_timestamp" ] || + working_tree_timestamp="$(date '+%s')" + fi + + [ "$origin_url" ] || + origin_url="$(git remote get-url origin 2>/dev/null || printf 'unknown')" # URL of the origin remote + # These parameter substitutions always expand to 'unknown' if $origin_url is 'unknown' + [ "$origin_name" ] || + origin_name="${origin_url##*/}" # Name of the origin remote + [ "$origin_owner" ] || + { origin_owner="${origin_url%/*}"; origin_owner="${origin_owner##*/}"; } # Owner of the origin remote + [ "$software_name" ] || + software_name="${origin_name}" # Name of the software (for built modules) +} + +print_repo_info() { + printf '%s\n' "-> Determined the following information about the current repository:" + printf '\t%s="%s"\n' \ + "software_name" "$software_name" \ + "current_commit" "$current_commit" \ + "working_tree_changed" "$working_tree_changed" \ + "working_tree_timestamp" "$working_tree_timestamp" \ + "origin_url" "$origin_url" \ + "origin_name" "$origin_name" \ + "origin_owner" "$origin_owner" +} + +container_build_and_run() { + container_name="${1}" + # $local_cache_dir, $container_runtime, $inspect_container, $container_security_privileged and $containerfile are expected to be, if applicable, set by the caller. + # /run_script.sh is expected to be present in the container, likely via a bind mount. + + build_opts=() + if [ "$local_cache_dir" ] && [ "$container_runtime" == 'docker-buildx' ]; then + if [ -f "${local_cache_dir}/index.json" ]; then # Only trying to load if the cache is not empty. + printf '%s\n' "-> Will try to load from local container build cache at '${local_cache_dir}'." + build_opts+=("--cache-from" "type=local,src=${local_cache_dir},compression=uncompressed") # GitHub actions cache always uses zstd compression, so we skip it here. + fi + if [ "$local_cache_ci_mode" != 'true' ] || [ ! -f "${local_cache_dir}/index.json" ]; then # If CI mode is NOT enabled, we always save to the cache, if CI mode is enabled, we only save if it's empty. + printf '%s\n' "-> Will try to save to local container build cache at '${local_cache_dir}'." + build_opts+=("--cache-to" "type=local,dest=${local_cache_dir},mode=max,compression=uncompressed") + fi + fi + + run_opts=(${container_runtime_opts[@]}) + [ "$inspect_container" == 'true' ] && run_opts+=("-it") + [ "$container_security_privileged" == 'true' ] && run_opts+=("--privileged") + + case "$container_runtime" in + # Note: We currently don't "COPY" any files during build, nonetheless the $temp_dir is specified since the command wants a directory. + podman) + printf '%s\n' "${containerfile}" | podman build ${build_opts[@]} --tag "${container_name}" --file - ${temp_dir} || + { printf '%s\n' "Error: Failed to build '${container_name}' image."; exit 1; } + podman run ${run_opts[@]} --rm "${container_name}" '/run_script.sh' || + { printf '%s\n' "Error: '${container_name}' exited with non-zero status '$?'. Aborting."; exit 1; } + ;; + docker) + printf '%s\n' "${containerfile}" | docker build ${build_opts[@]} --tag "${container_name}" --file - ${temp_dir} || + { printf '%s\n' "Error: Failed to build '${container_name}' image."; exit 1; } + docker run ${run_opts[@]} --rm "${container_name}" '/run_script.sh' || + { printf '%s\n' "Error: '${container_name}' exited with non-zero status '$?'. Aborting."; exit 1; } + ;; + docker-buildx) + printf '%s\n' "${containerfile}" | docker buildx build ${build_opts[@]} --load --tag "${container_name}" --file - ${temp_dir} || + { printf '%s\n' "Error: Failed to build '${container_name}' image."; exit 1; } + docker run ${run_opts[@]} --rm "${container_name}" '/run_script.sh' || + { printf '%s\n' "Error: '${container_name}' exited with non-zero status '$?'. Aborting."; exit 1; } + ;; + *) # container_runtime should be validated by the parser, so this should never happen. + printf '%s\n' "Error: Unknown container runtime '${container_runtime}'."; exit 1 + ;; + esac +} + +startup() { + printf '%s' "-> Deleting old .release/ folder and creating temporary directory..." + rm -rf "./.release/" || { printf '\n%s\n' "Error: Failed to delete previous release directory."; exit 1; } + temp_dir="$(mktemp -t --directory ${software_name}_tmp.XXXXXXXXXX)" || { printf '\n%s\n' "Error: Failed to create temporary directory."; exit 1; } + printf '%s\n' " OK." +} + +cleanup() { + last_exit_status="$?" + if [ "$print_temp_dir" == 'normal' ]; then + printf '%s\n' "-> Contents of temporary directory at '${temp_dir}' ('normal' verbosity):" + tree "${temp_dir}" 2>/dev/null || ls -R "${temp_dir}" # Fallback if "tree" is not installed. + elif [ "$print_temp_dir" == 'verbose' ]; then + printf '%s\n' "-> Contents of temporary directory at '${temp_dir}' ('verbose' verbosity):" + ls -laR "${temp_dir}" + fi + if [ "$keep_temp_dir" == 'true' ]; then + printf '%s\n' "-> Not removing '${temp_dir}' as per '--keep_temp_dir'." + else + printf '%s' "-> Deleting temporary directory at '${temp_dir}'..." + rm -rf "${temp_dir}" || { printf '\n%s\n' "Error: Failed to delete temporary directory."; exit 1; } + printf '%s\n' " OK." + fi + [ "$last_exit_status" == '0' ] && { printf '%s\n' "-> Program completed successfully"; exit 0; } + [ "$last_exit_status" != '0' ] && { printf '%s\n' "-> Program exited with non-zero status '$last_exit_status'"; exit "$last_exit_status"; } +} + +# ------------------- +# Packaging functions +# ------------------- +build_apk() { + # Prepare source and build files + mkdir -p "${temp_dir}/"{APKBUILD,packages} # Create the shared directories + build_overrides=( + "_source_modname=\"${software_name}\"" + "_repo_name=\"${origin_name}\"" + "_repo_owner=\"${origin_owner}\"" + "_repo_commit=\"${current_commit}\"" + "_package_timestamp=\"$(date -u -d "@${working_tree_timestamp}" '+%Y%m%d')\"" + "source=\"${origin_name}.tar.gz\"" + ) + printf '%s\n' "${build_overrides[@]}" >"${temp_dir}/APKBUILD/APKBUILD" # Write overrides + cat "./alpine/APKBUILD" >>"${temp_dir}/APKBUILD/APKBUILD" # Append the APKBUILD + + tar \ + --verbose \ + --exclude="${PWD##*/}/.git" \ + --create \ + --gzip \ + --file "${temp_dir}/APKBUILD/${origin_name}.tar.gz" \ + --directory '../' \ + "${PWD##*/}" # Create the source tarball, for compatibility with GitHub tarballs we put the repo in a subdirectory of the tarball + + # Prepare the container + containerfile="$(cat <<-'EOF' + FROM docker.io/library/alpine:latest + + # Install the build dependencies + RUN apk add abuild build-base + EOF + )" + containerfile_test="$(cat <<-'EOF' + # Install the test dependencies + RUN apk add linux-lts-dev akms + + # Remove /proc mount from akms-runas. This works around 'Can't mount proc on /newroot/proc: Operation not permitted' in GitHub Actions. + # Update: This removes the --privileged requirement for Podman, but Docker needs --privileged regardless. For now it's commented out and we will be using --privileged for any bwrap related issues. + # RUN sed -i '/--proc \/proc \\/d' /usr/libexec/akms/akms-runas + + # Save kernel dev name + RUN printf '%s\n' "$(ls /lib/modules/ | head -n 1)" >/kernel_dev_name.txt + EOF + )" + container_run_script=( + "(" + "cd /APKBUILD" + "&& abuild-keygen -a -n" # We can't not sign the package, so we generate a one time use key, the user has to install it with `--allow-untrusted` + "&& abuild -F checksum" + "&& abuild -F srcpkg" + "&& abuild -F" + ")" + "&& printf '%s\n' '-> Package building complete.'" + ) + if [ "$container_run_pkg_tests" == 'true' ]; then # Testing installing the package and akmod dynamic builds + container_run_script+=( + "&& apk add --allow-untrusted /root/packages/*/*.apk" + "&& akms --kernel \$(cat /kernel_dev_name.txt) build ${software_name}-oot" + "&& akms --kernel \$(cat /kernel_dev_name.txt) install ${software_name}-oot" + "&& modinfo /lib/modules/\$(cat /kernel_dev_name.txt)/kernel/extra/akms/${software_name}.ko*" # * in case compression is used + "&& printf '%s\n' '-> Checking if module is removed on package uninstall.'" + "&& apk del ${software_name}-oot*" + "&& { ! modinfo --filename /lib/modules/\$(cat /kernel_dev_name.txt)/kernel/extra/akms/${software_name}.ko* &>/dev/null || { printf '%s\n' '-> Error: Module was not removed on package uninstall.'; return 1; }; }" + "&& printf '%s\n' '-> Package installation and akms dynamic build tests successful.'" + ) + fi + if [ "$inspect_container" == 'true' ]; then + container_run_script+=( + "; printf '%s\n' '-> Dropping into container shell.'" + "; ash" + ) + fi + install -D -m 0755 <(printf '%s\n\n%s\n' '#!/bin/sh' "${container_run_script[*]}") "${temp_dir}/run_script.sh" # Write the run command + + # Build and run the container + container_runtime_opts=( + "--mount type=bind,source=${temp_dir}/APKBUILD,target=/APKBUILD" + "--mount type=bind,source=${temp_dir}/packages,target=/root/packages" + "--mount type=bind,source=${temp_dir}/run_script.sh,target=/run_script.sh" + ) + if [ "$container_run_pkg_tests" == 'true' ]; then + containerfile="$(printf '%s\n\n%s\n' "${containerfile}" "${containerfile_test}")" # Append test dependencies and setup + container_build_and_run "${software_name}-apk-build-and-test" + else + containerfile="$(printf '%s\n' "${containerfile}")" # Add newline for consistency + container_build_and_run "${software_name}-apk-build" + fi + + # Prepare to copy out files + apk_packages_folder="./.release/apk" + akms_manual_root_folder='./.release/akms' + mkdir -p "${apk_packages_folder}" "${akms_manual_root_folder}" + + # Copy out the apk packages + cp "${temp_dir}/packages/"*/*.apk "${apk_packages_folder}" + + # Extract akms files for manual install + if tar --version | grep -q 'busybox'; then + no_warning_option='' # busybox tar doesn't support (and doesn't need) --warning=no-unknown-keyword + else + no_warning_option=' --warning=no-unknown-keyword' # tar can act weird if we have a stray space, so we have it in the variable + fi + + mainpkg=$(ls "${apk_packages_folder}/"*.apk | head -n 1) # ls with a glob '*.apk' returns the full relative path. + mainpkgfiles=( + "etc/depmod.d/${software_name}-oot.conf" + "etc/modules-load.d/${software_name}-oot.conf" + ) + tar -xf "${mainpkg}" -C "${akms_manual_root_folder}/" "${mainpkgfiles[@]}"${no_warning_option} + akmspkg=$(ls "${apk_packages_folder}/"*akms*.apk | head -n 1) + akmspkgfiles=( + "usr/src/${software_name}-oot/" + ) + tar -xf "${akmspkg}" -C "${akms_manual_root_folder}/" "${akmspkgfiles[@]}"${no_warning_option} + ircpkg=$(ls "${apk_packages_folder}/"*ignore_resource_conflict*.apk | head -n 1) + ircpkgfiles=( + "etc/modprobe.d/${software_name}-oot.conf" + ) + tar -xf "${ircpkg}" -C "${akms_manual_root_folder}/" "${ircpkgfiles[@]}"${no_warning_option} +} + +build_rpm() { + # Prepare the source and build files + mkdir -p "${temp_dir}/rpmbuild/"{SOURCES,SPECS} # Create shared build directories in temp dir + spec_overrides=( + "%global source_modname ${software_name}" + "%global repo_name ${origin_name}" + "%global repo_owner ${origin_owner}" + "%global repo_commit ${current_commit}" + "%global package_timestamp $(date -u -d "@${working_tree_timestamp}" '+%Y%m%d')" + ) + for spec_file in "./redhat/"*.spec; do # Write overrides, then insert the original spec file + spec_file_target="${temp_dir}/rpmbuild/SPECS/${spec_file##*/}" + printf '%s\n' "${spec_overrides[@]}" >"${spec_file_target}" + cat "${spec_file}" >>"${spec_file_target}" + done + + tar \ + --verbose \ + --exclude="${PWD##*/}/.git" \ + --exclude="${PWD##*/}/Research" \ + --create \ + --gzip \ + --file="${temp_dir}/rpmbuild/SOURCES/${origin_name}.tar.gz" \ + --directory='../' \ + "${PWD##*/}" # The spec files expect the sources in a subdirectory of the archive (as with GitHub tarballs) + # Note: We exclude ./Research here since we can't just not install it through the spec file (kmodtool always includes the entire tarball). + # This isn't ideal, but anything else (modifying the source tarball itself during package building) seems like it would be sketchy. + + # Prepare the container + containerfile="$(cat <<-'EOF' + FROM registry.fedoraproject.org/fedora-minimal:latest + + # Install the build dependencies + RUN microdnf install -y rpmdevtools kmodtool + EOF + )" + containerfile_test="$(cat <<-'EOF' + # Install the test dependencies + # Note: Unlike with Alpine, we can't get away with only the -dev(el) package, we need the full kernel package. + # TODO: Unfortunately the kernel package has a ton of dependencies, TODO: somehow skip dependencies. + # DNF is needed by akmods to install the resulting package. + RUN microdnf install -y kernel kernel-devel akmods dnf + + # Save kernel dev name + RUN printf '%s\n' "$(ls /lib/modules/ | head -n 1)" >/kernel_dev_name.txt + EOF + )" + container_run_script=( + "rpmdev-setuptree" + "&& rpmbuild -ba /root/rpmbuild/SPECS/*.spec" + "&& printf '%s\n' '-> Package building complete.'" + ) + if [ "$container_run_pkg_tests" == 'true' ]; then # Testing installing the package and akms dynamic builds + container_run_script+=( + "&& rpm --install /root/rpmbuild/RPMS/*/*.rpm" + "&& akmods --kernels \$(cat /kernel_dev_name.txt) --akmod ${software_name}-oot" + "&& modinfo /lib/modules/\$(cat /kernel_dev_name.txt)/extra/${software_name}-oot/${software_name}.ko*" + "&& printf '%s\n' '-> Checking if module is removed on package uninstall.'" + "&& rpm --query --all '*${software_name}-oot*' | xargs rpm --erase" + "&& { ! modinfo --filename /lib/modules/\$(cat /kernel_dev_name.txt)/extra/${software_name}-oot/${software_name}.ko* &>/dev/null || { printf '%s\n' '-> Error: Module was not removed on package uninstall.'; return 1; }; }" + "&& printf '%s\n' '-> Package installation and akms dynamic build tests successful.'" + ) + fi + if [ "$inspect_container" == 'true' ]; then + container_run_script+=( + "; printf '%s\n' '-> Dropping into container shell.'" + "; bash" + ) + fi + install -D -m 0755 <(printf '%s\n\n%s\n' '#!/bin/sh' "${container_run_script[*]}") "${temp_dir}/run_script.sh" + + # Build and run the container + container_runtime_opts=( + "--mount type=bind,source=${temp_dir}/rpmbuild,target=/root/rpmbuild" + "--mount type=bind,source=${temp_dir}/run_script.sh,target=/run_script.sh" + ) + if [ "$container_run_pkg_tests" == 'true' ]; then + containerfile="$(printf '%s\n\n%s\n' "${containerfile}" "${containerfile_test}")" # Append test dependencies and setup + container_build_and_run "${software_name}-rpm-build-and-test" + else + containerfile="$(printf '%s\n' "${containerfile}")" # Add newline for consistency + container_build_and_run "${software_name}-rpm-build" + fi + + # Copy out the built packages + mkdir -p "./.release/"{SRPMS,RPMS} + cp "${temp_dir}/rpmbuild/SRPMS/"*.src.rpm "./.release/SRPMS/" + cp "${temp_dir}/rpmbuild/RPMS/"*/*.rpm "./.release/RPMS/" +} + +build_deb() { # TODO: Support this packaging method like apk and rpm + # Copy the source files to the temp directory + cp -r "../${PWD##*/}" "${temp_dir}/${software_name}" + + # Prepare the container + containerfile="$(cat <<-'EOF' + FROM docker.io/library/debian:stable-slim + + RUN apt-get update && apt-get install -y debhelper dkms + EOF + )" + containerfile_test="$(cat <<-'EOF' + # Building the package already needs dkms for some reason, which includes the kernel dev stuff, so this is kind of pointless. + # Save kernel dev name + RUN printf '%s\n' "$(ls /lib/modules/ | head -n 1)" >/kernel_dev_name.txt + EOF + )" + container_run_script=( + "(" + "cd /root/${software_name}" + "&& dpkg-buildpackage --no-sign" + ")" + "&& printf '%s\n' '-> Package building complete.'" + ) + if [ "$container_run_pkg_tests" == 'true' ]; then # Testing installing the package and dkms dynamic builds + container_run_script+=( + "&& dpkg --install /root/*.deb" + "&& modinfo /lib/modules/\$(cat /kernel_dev_name.txt)/updates/dkms/${software_name}.ko*" + "&& printf '%s\n' '-> Checking if module is removed on package uninstall.'" + "&& dpkg-query --show --showformat='\${Package}' '*${software_name}*' | xargs dpkg --remove" + "&& { ! modinfo --filename /lib/modules/\$(cat /kernel_dev_name.txt)/updates/dkms/${software_name}.ko* &>/dev/null || { printf '%s\n' '-> Error: Module was not removed on package uninstall.'; return 1; }; }" + "&& printf '%s\n' '-> Package installation and akms dynamic build tests successful.'" + ) + fi + if [ "$inspect_container" == 'true' ]; then + container_run_script+=( + "; printf '%s\n' '-> Dropping into container shell.'" + "; bash" + ) + fi + install -D -m 0755 <(printf '%s\n\n%s\n' '#!/bin/sh' "${container_run_script[*]}") "${temp_dir}/run_script.sh" + + # Build and run the container + container_runtime_opts=( + "--mount type=bind,source=${temp_dir}/,target=/root" + "--mount type=bind,source=${temp_dir}/run_script.sh,target=/run_script.sh" + ) + if [ "$container_run_pkg_tests" == 'true' ]; then + containerfile="$(printf '%s\n\n%s\n' "${containerfile}" "${containerfile_test}")" # Append test dependencies and setup + container_build_and_run "${software_name}-deb-build-and-test" + else + containerfile="$(printf '%s\n' "${containerfile}")" # Add newline for consistency + container_build_and_run "${software_name}-deb-build" + fi + + # Copy out the built packages + mkdir -p "./.release/" + cp "${temp_dir}/"*.deb "./.release/" +} + + +# ---- +# Main +# ---- +gather_repo_info +parse_arguments "$@" +trap cleanup EXIT + +startup +print_repo_info + +case "$package_system" in + apk) + build_apk + ;; + rpm) + build_rpm + ;; + deb) + build_deb + ;; + *) + printf '%s\n' "Error: Unknown package system '$package_system'" # This should never happen since the argument parser validates the input + exit 1 + ;; +esac diff --git a/packagetool_quickstart.md b/packagetool_quickstart.md new file mode 100644 index 0000000..bb2bb91 --- /dev/null +++ b/packagetool_quickstart.md @@ -0,0 +1,58 @@ +# `packagetool.sh` quick start guide + +`packagetool.sh` assists in the creation of a packaged version of the `it87` module for Alpine Linux (via AKMS), Fedora & co (including Silverblue) (via akmods), and Debian & co (via DKMS). +It uses a container to ensure that the build environment is reproducible and to avoid touching the host system. + +## Basic usage, for this example on Fedora Silverblue 38: +1. Docker (optionally with `buildx`) or Podman is required to use the program. + + The container runtime doesn't matter too much, usually the pre-installed or already in use one should be preferred. Podman comes pre-installed on Fedora Silverblue. + +2. Run `./packagetool.sh --container_runtime=podman --package_system=rpm --container_security_privileged` + + `--container_runtime=` and `--package_system=` are always required. + + `--container_security_privileged` is only required here because of Silverblue's SELinux restrictions on mounted directories. (More granular security options are "TODO".) + + For more information on the available options, run the program with `--help`. + + The program also includes tests for package installation and module building via the target distribution's dynamic module building mechanism. For this, run the program with `--run_build_tests`. Please note that this requires additional dependencies which increase the size of the container image, in Fedora's case by quite a lot. + +3. The resulting packages can be found in the `./.releases/` directory. + +The tool uses the following base images: +* `docker.io/library/alpine:latest` +* `registry.fedoraproject.org/fedora-minimal:latest` +* `docker.io/library/debian:stable-slim` + +The resulting images are named `it87-{package_system}-build` or `it87-{package_system}-build-and-test`, for example `it87-rpm-build`. + +It is recommended to delete the base images after some time to ensure that up-to-date packaging tools are used. The resulting images can also be deleted to save disk space. + +# GitHub Actions + +A wrapper for GitHub Actions is provided in `./.github/workflows/packagetool.yml`, the workflow resets its build cache with each week of the year. An option to not use the cache is provided when dispatching or calling the workflow. + +`./.github/workflows/package_and_release.yml` automatically builds and tests the packages, then creates a draft release with the packages as assets. It automatically replaces the latest draft release to avoid cluttering the releases page. If configured to be triggered by a push, it can be skipped by adding `[skip ci]` to the commit message (this is enforced by GitHub, not the workflow). + +# Package overview +## Packages: +| `package_system` | Package (`.release/*`) | Contents | Notes | +| ------------------ | ------- | -------- | ----- | +| `apk` | `apk/it87-oot-*.apk` | Userland files | Depends on AKMS package. | +| `apk` | `apk/it87-oot-akms-*.apk` | AKMS files | Depends on userland package. | +| `apk` | `apk/it87-oot-doc-*.apk` | Documentation files | | +| `apk` | `apk/it87-ignore_resource_conflict-*.apk` | `ignore_resource_conflict` option | | +| `apk` | `akms/*` | File system tree containing the files for manual installation | `/etc/modprobe.d/it87-oot.conf` is the `ignore_resource_conflict` option and should only be installed if needed | +| `deb` | `it87-dkms_*.deb` | DKMS files | The `.deb` process is currently much more basic than the others, `ignore_resource_conflict` has to be manually configured in `/etc/modprobe.d/` | +| `rpm` | `RPM/it87-oot-*.rpm` | Userland files | Depends on akmods package. | +| `rpm` | `RPM/akmod-it87-oot-*.rpm` | akmods files | Depends on userland package. | +| `rpm` | `RPM/kmod-it87-oot-*.rpm` | “Metapackage which tracks in the it87-oot kernel module for newest kernel” | I am not entirely sure what the point of this is since we’re building the module dynamically | +| `rpm` | `RPM/it87-oot-ignore_resource_conflict-*.rpm` | `ignore_resource_conflict` option | | +| `rpm` | `SRPM/*` | Source RPMs (for debugging and inspection) | | + +## General information: +- For Alpine Linux with either method, installing the `linux-{flavor}-dev` (usually `linux-lts-dev`) package is recommended, otherwise `akms` will temporarily download it at the time of building, requiring an internet connection. +- The `ignore_resource_conflict` packages should only be installed if the module fails to load otherwise. + - In the manual Alpine Linux installation, `/etc/modprobe.d/it87-oot.conf` corresponds to the aforementioned package. +- A reboot is recommended after installing the module or (un)installing the `ignore_resource_conflict` package. \ No newline at end of file diff --git a/redhat/it87-oot-ignore_resource_conflict.spec b/redhat/it87-oot-ignore_resource_conflict.spec new file mode 100644 index 0000000..bbd350e --- /dev/null +++ b/redhat/it87-oot-ignore_resource_conflict.spec @@ -0,0 +1,34 @@ +# Placeholder information will be used if not inserted above (e.g. by a build wrapper) +%{!?source_modname: %global source_modname it87} +%{!?package_timestamp:%global package_timestamp %{lua:print(os.date('!%Y%m%d'))}} +# Placeholder information end + + +Name: %{source_modname}-oot-ignore_resource_conflict +Version: %{!?version_override:0^%{package_timestamp}}%{?version_override:%{version_override}} +Release: 1%{?dist} +Summary: Optional "modprobe.d" entry for the "%{source_modname}" module to ignore ACPI resource conflicts. +License: n/a + +URL: https://github.com/%{repo_owner}/%{repo_name} + +Provides: %{name} = %{version} + +BuildArch: noarch + +%description +Package to ignore resource conflicts for the %{source_modname} kernel module. + +%prep +%setup -q -c -T + +printf '%s\n' "options %{source_modname} ignore_resource_conflict=true" >"modprobe_%{name}.conf" + +%install +install -D -m 0644 "modprobe_%{name}.conf" "%{buildroot}%{_prefix}/lib/modprobe.d/%{name}.conf" + +%files +%{_prefix}/lib/modprobe.d/%{name}.conf + +%changelog +# Nothing so far diff --git a/redhat/it87-oot-kmod.spec b/redhat/it87-oot-kmod.spec new file mode 100644 index 0000000..528a1df --- /dev/null +++ b/redhat/it87-oot-kmod.spec @@ -0,0 +1,59 @@ +# Placeholder information will be used if not inserted above (e.g. by a build wrapper) +%{!?source_modname: %global source_modname it87} +%{!?repo_name: %global repo_name it87} +# WARNING: This placeholder will download a very old version, ensure the repo info and commit hash are up-to-date +%{!?repo_owner: %global repo_owner frankcrawford} +%{!?repo_commit: %global repo_commit 77abcbe0c49d7d8dc4530dcf51cecb40ef39f49a} +%{!?package_timestamp:%global package_timestamp %{lua:print(os.date('!%Y%m%d'))}} +# Placeholder information end + +%define commit_short() %{lua:print(string.sub(rpm.expand('%repo_commit'),1,arg[1]))} +%global debug_package %{nil} + + +Name: %{source_modname}-oot-kmod +Version: %{!?version_override:0^%{package_timestamp}.git%{commit_short 7}}%{?version_override:%{version_override}} +Release: 1%{?dist} +Summary: kmodtool package for the out-of-tree version of the "%{source_modname}" module forked by "%{repo_owner}". +License: GPLv2+ + +URL: https://github.com/%{repo_owner}/%{repo_name} +Source0: %{url}/tarball/%{repo_commit}/%{repo_name}.tar.gz + +BuildRequires: kmodtool + +%description +Out-of-tree fork of the %{source_modname} kernel module with support for more chips. + +%{expand:%(kmodtool --target %{_target_cpu} --kmodname "%{name}" --akmod %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null)} + +%prep +%{?kmodtool_check} +%setup -q -c + +%global source_dirname %(tar -tzf %{SOURCE0} | head -n 1 | head -c -2) +if [ ! -f "%{source_dirname}/Makefile" ]; then + echo "ERROR: Makefile not found in source archive, we expect the archive to contain a single directory with the source code." + exit 1 +fi + +for kernel_version in %{?kernel_versions}; do + cp -a "%{source_dirname}" "_kmod_build_${kernel_version%%___*}" +done + +%build +for kernel_version in %{?kernel_versions}; do + (cd "_kmod_build_${kernel_version%%___*}/" && + make %{?_smp_mflags} TARGET="${kernel_version%%___*}" DRIVER_VERSION="%{version}" modules + # xz -f "%{source_modname}.ko" # No longer used, kmodtool compresses when appropriate, doing it here causes 'brp-kmodsign' to get indefinitely stuck. + ) || exit 1 +done + +%install +for kernel_version in %{?kernel_versions}; do + install -D -m 0755 "_kmod_build_${kernel_version%%___*}/%{source_modname}.ko" "%{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/%{source_modname}.ko" +done +%{?akmod_install} + +%changelog +# Nothing so far diff --git a/redhat/it87-oot.spec b/redhat/it87-oot.spec new file mode 100644 index 0000000..133024e --- /dev/null +++ b/redhat/it87-oot.spec @@ -0,0 +1,58 @@ +# Placeholder information will be used if not inserted above (e.g. by a build wrapper) +%{!?source_modname: %global source_modname it87} +%{!?repo_name: %global repo_name it87} +# WARNING: This placeholder will download a very old version, ensure the repo info and commit hash are up-to-date +%{!?repo_owner: %global repo_owner frankcrawford} +%{!?repo_commit: %global repo_commit 77abcbe0c49d7d8dc4530dcf51cecb40ef39f49a} +%{!?package_timestamp:%global package_timestamp %{lua:print(os.date('!%Y%m%d'))}} +# Placeholder information end + +%define commit_short() %{lua:print(string.sub(rpm.expand('%repo_commit'),1,arg[1]))} + + +Name: %{source_modname}-oot +Version: %{!?version_override:0^%{package_timestamp}.git%{commit_short 7}}%{?version_override:%{version_override}} +Release: 1%{?dist} +Summary: Userland package for the out-of-tree version of the "%{source_modname}" module forked by "%{repo_owner}". +License: GPLv2+ + +URL: https://github.com/%{repo_owner}/%{repo_name} +Source0: %{url}/tarball/%{repo_commit}/%{repo_name}.tar.gz + +Requires: %{name}-kmod >= %{version} +Provides: %{name}-kmod-common = %{version} + +BuildArch: noarch + +%description +Out-of-tree fork of the %{source_modname} kernel module with support for more chips. This is the userland package. + +%prep +%setup -q -c + +%global source_dirname %(tar -tzf %{SOURCE0} | head -n 1 | head -c -2) +if [ ! -f "%{source_dirname}/Makefile" ]; then + echo "ERROR: Makefile not found in source archive, we expect the archive to contain a single directory with the source code." + exit 1 +fi + +printf '%s\n' "override %{source_modname} * extra/%{name}" >"depmod_%{name}.conf" +printf '%s\n' "%{source_modname}" >"modload_%{name}.conf" + +%install +install -D -m 0644 "depmod_%{name}.conf" "%{buildroot}%{_prefix}/lib/depmod.d/%{name}.conf" +install -D -m 0644 "modload_%{name}.conf" "%{buildroot}%{_prefix}/lib/modules-load.d/%{name}.conf" +mkdir -p "%{buildroot}%{_docdir}/%{name}" +cp -r "%{source_dirname}/Sensors configs" "%{buildroot}%{_docdir}/%{name}/Sensors configs" + +%files +%doc "%{source_dirname}/README.md" "%{source_dirname}/ISSUES" "%{source_dirname}/debian/changelog" +# Unlike "doc", "docdir" doesn't automatically install the directory. +"%{_docdir}/%{name}/Sensors configs" +%docdir "%{_docdir}/%{name}/Sensors configs" +%license "%{source_dirname}/LICENSE" +"%{_prefix}/lib/depmod.d/%{name}.conf" +"%{_prefix}/lib/modules-load.d/%{name}.conf" + +%changelog +# Nothing so far