├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── documentation_issue.md │ └── feature_request.md ├── hadolint.yml ├── stale.yml └── workflows │ ├── build-images.yml │ └── validate-readme.yml ├── .gitignore ├── CODEOWNERS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── alpine ├── Dockerfile ├── entrypoint └── update ├── build ├── contrib └── cont-init.d │ ├── 10-show-directories │ ├── 20-add-allowed-ssh-keys │ ├── 20-add-console-loggers │ ├── 20-open-ssh-server │ ├── 20-set-host-key │ ├── 30-jetty-increase-webclients │ ├── 40-openhabcloud │ ├── 50-setpcap-on-java │ └── 60-socat-serial-network ├── debian ├── Dockerfile ├── entrypoint └── update ├── helper-functions └── openhab.png /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "🐛 Bug report" 3 | about: Something isn't working correctly with an openHAB Docker image. This is the wrong place for reporting bugs in add-ons, UIs or the core. 4 | labels: bug 5 | 6 | --- 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Summary 17 | 18 | 19 | ## Expected Behavior 20 | 21 | 22 | ## Current Behavior 23 | 24 | 25 | 26 | 27 | 28 | ## Possible Solution 29 | 30 | 31 | ## Steps to Reproduce 32 | 33 | 1. 34 | 2. 35 | 36 | ## Context 37 | 38 | 39 | 40 | ## Your Environment 41 | 42 | 43 | ### Image 44 | 45 | * openHAB version: (e.g., openHAB and add-on versions) 46 | * Image tag used: (e.g. 3.0.0, latest-debian, snapshot) 47 | 48 | ### Docker Host 49 | 50 | * Operating System: (e.g. Raspbian GNU/Linux 10 (buster), Ubuntu 20.04.1 LTS, Windows 10) 51 | * Docker Version: (e.g. 20.04.1, 20.10.2) 52 | * Kernel Version: (e.g. 5.4.0-62-generic, 5.4.83-v7+) 53 | * Architecture: (e.g. x86_64, armv7l) 54 | 55 | ### Configuration 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: 🤔 openHAB Docker Support/Usage Question 4 | url: https://community.openhab.org/tags/c/setup-configuration-and-use/docker 5 | about: Ask anything about how to use the openHAB Docker images here 6 | - name: 📖 openHAB Documentation 7 | url: https://www.openhab.org/docs/ 8 | about: Official openHAB documentation 9 | - name: 🐋 Docker Documentation 10 | url: https://docs.docker.com/ 11 | about: Official Docker documentation 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation_issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "📖 Documentation issue" 3 | about: Some information within the Docker image documentation is wrong or missing 4 | labels: documentation 5 | 6 | --- 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "✨ Feature request" 3 | about: You think that the openHAB Docker images should gain another feature 4 | labels: enhancement 5 | 6 | --- 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Summary 17 | 18 | 19 | ## Expected Behavior 20 | 21 | 22 | ## Current Behavior 23 | 24 | 25 | 26 | 27 | 28 | ## Possible Solution 29 | 30 | 31 | ## Context 32 | 33 | 34 | 35 | ## Your Environment 36 | 37 | 38 | ### Image 39 | * openHAB version: (e.g., openHAB and add-on versions) 40 | * Image tag used: (e.g. latest-debian, snapshot, 3.0.0) 41 | 42 | ### Docker Host 43 | 44 | * Operating System: (e.g. Raspbian GNU/Linux 10 (buster), Ubuntu 20.04.1 LTS, Windows 10) 45 | * Docker Version: (e.g. 20.04.1, 20.10.2) 46 | * Kernel Version: (e.g. 5.4.0-62-generic, 5.4.83-v7+) 47 | * Architecture: (e.g. x86_64, armv7l) 48 | 49 | ### Configuration 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /.github/hadolint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | trustedRegistries: 3 | - docker.io 4 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale (two month) 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed (another six month) 4 | daysUntilClose: 180 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | - "PR pending" 10 | # Only issues with all of these labels are checked if stale. 11 | onlyLabels: 12 | - "awaiting feedback" 13 | # Label to use when marking an issue as stale 14 | staleLabel: stale 15 | # Comment to post when marking an issue as stale. Set to `false` to disable 16 | markComment: > 17 | This issue has been automatically marked as stale because it has not had 18 | recent activity. It will be closed if no further activity occurs. Thank you 19 | for your contributions. 20 | # Comment to post when closing a stale issue. Set to `false` to disable 21 | closeComment: false 22 | # Limit to only `issues`` 23 | only: issues 24 | -------------------------------------------------------------------------------- /.github/workflows/build-images.yml: -------------------------------------------------------------------------------- 1 | name: Build images 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | pull_request: 8 | branches: 9 | - 'main' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-24.04 15 | strategy: 16 | matrix: 17 | tag: ["latest", "snapshot"] 18 | distribution: ["alpine", "debian"] 19 | name: ${{ matrix.tag }}-${{ matrix.distribution }} 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v4 23 | 24 | - name: Lint Dockerfile 25 | uses: hadolint/hadolint-action@v3.1.0 26 | with: 27 | dockerfile: ${{ matrix.distribution }}/Dockerfile 28 | config: ".github/hadolint.yml" 29 | 30 | - name: Set up Docker Buildx 31 | uses: docker/setup-buildx-action@v3 32 | 33 | - name: Build images 34 | run: ./build ${{ matrix.tag }} ${{ matrix.distribution }} 35 | -------------------------------------------------------------------------------- /.github/workflows/validate-readme.yml: -------------------------------------------------------------------------------- 1 | name: Validate README.md 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | pull_request: 8 | branches: 9 | - 'main' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-24.04 15 | name: validate 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | 20 | - name: Validate README.md 21 | run: bash -c 'source helper-functions && validate_readme_constraints' 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .history 3 | .idea 4 | .project 5 | .settings 6 | .vscode 7 | 8 | *.bak 9 | *.log 10 | *.swp 11 | *.tmp 12 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This file helps GitHub doing automatic review requests for new PRs. 2 | # It should always list the active Docker maintainers. 3 | 4 | # Assign all PRs to the Docker maintainers: 5 | * @openhab/docker-maintainers 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contribution guidelines 2 | 3 | ### Pull requests are always welcome 4 | 5 | We are always thrilled to receive pull requests, and do our best to 6 | process them as fast as possible. Not sure if that typo is worth a pull 7 | request? Do it! We will appreciate it. 8 | 9 | If your pull request is not accepted on the first try, don't be 10 | discouraged! If there's a problem with the implementation, hopefully you 11 | received feedback on what to improve. 12 | 13 | We're trying very hard to keep openHAB lean and focused. We don't want it 14 | to do everything for everybody. This means that we might decide against 15 | incorporating a new feature. However, there might be a way to implement 16 | that feature *on top of* openHAB. 17 | 18 | ### Discuss your design on the mailing list 19 | 20 | We recommend discussing your plans [in the discussion forum](https://community.openhab.org/) 21 | before starting to code - especially for more ambitious contributions. 22 | This gives other contributors a chance to point you in the right 23 | direction, give feedback on your design, and maybe point out if someone 24 | else is working on the same thing. 25 | 26 | ### Create issues... 27 | 28 | Any significant improvement should be documented as [a GitHub 29 | issue](https://github.com/openhab/openhab-docker/issues?labels=enhancement&page=1&state=open) before anybody 30 | starts working on it. 31 | 32 | ### ...but check for existing issues first! 33 | 34 | Please take a moment to check that an issue doesn't already exist 35 | documenting your bug report or improvement proposal. If it does, it 36 | never hurts to add a quick "+1" or "I have this problem too". This will 37 | help prioritize the most common problems and requests. 38 | 39 | ### Conventions 40 | 41 | Fork the repo and make changes on your fork in a feature branch. 42 | 43 | Update the documentation when creating or modifying features. Test 44 | your documentation changes for clarity, concision, and correctness, as 45 | well as a clean documentation build. 46 | 47 | Write clean code. Universally formatted code promotes ease of writing, reading, 48 | and maintenance. 49 | 50 | Pull requests descriptions should be as clear as possible and include a 51 | reference to all the issues that they address. 52 | 53 | Pull requests must not contain commits from other users or branches. 54 | 55 | Commit messages must start with a capitalized and short summary (max. 50 56 | chars) written in the imperative, followed by an optional, more detailed 57 | explanatory text which is separated from the summary by an empty line. 58 | 59 | Code review comments may be added to your pull request. Discuss, then make the 60 | suggested modifications and push additional commits to your feature branch. Be 61 | sure to post a comment after pushing. The new commits will show up in the pull 62 | request automatically, but the reviewers will not be notified unless you 63 | comment. 64 | 65 | Before the pull request is merged, make sure that you squash your commits into 66 | logical units of work using `git rebase -i` and `git push -f`. After every 67 | commit the test suite should be passing. Include documentation changes in the 68 | same commit so that a revert would remove all traces of the feature or fix. 69 | 70 | Commits that fix or close an issue should include a reference like `Closes #XXX` 71 | or `Fixes #XXX`, which will automatically close the issue when merged. 72 | 73 | ### Merge approval 74 | 75 | openHAB maintainers use LGTM (Looks Good To Me) in comments on the code review 76 | to indicate acceptance. 77 | 78 | ### Sign your work 79 | 80 | The sign-off is a simple line at the end of the explanation for the 81 | patch, which certifies that you wrote it or otherwise have the right to 82 | pass it on as an open-source patch. The rules are pretty simple: if you 83 | can certify the below (from 84 | [developercertificate.org](http://developercertificate.org/)): 85 | 86 | ``` 87 | Developer Certificate of Origin 88 | Version 1.1 89 | 90 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 91 | 660 York Street, Suite 102, 92 | San Francisco, CA 94110 USA 93 | 94 | Everyone is permitted to copy and distribute verbatim copies of this 95 | license document, but changing it is not allowed. 96 | 97 | 98 | Developer's Certificate of Origin 1.1 99 | 100 | By making a contribution to this project, I certify that: 101 | 102 | (a) The contribution was created in whole or in part by me and I 103 | have the right to submit it under the open source license 104 | indicated in the file; or 105 | 106 | (b) The contribution is based upon previous work that, to the best 107 | of my knowledge, is covered under an appropriate open source 108 | license and I have the right under that license to submit that 109 | work with modifications, whether created in whole or in part 110 | by me, under the same open source license (unless I am 111 | permitted to submit under a different license), as indicated 112 | in the file; or 113 | 114 | (c) The contribution was provided directly to me by some other 115 | person who certified (a), (b) or (c) and I have not modified 116 | it. 117 | 118 | (d) I understand and agree that this project and the contribution 119 | are public and that a record of the contribution (including all 120 | personal information I submit with it, including my sign-off) is 121 | maintained indefinitely and may be redistributed consistent with 122 | this project or the open source license(s) involved. 123 | ``` 124 | 125 | then you just add a line to every git commit message: 126 | 127 | Signed-off-by: Joe Smith (github: github_handle) 128 | 129 | using your real name (sorry, no pseudonyms or anonymous contributions.) 130 | 131 | #### Small patch exception 132 | 133 | There are several exceptions to the signing requirement. Currently these are: 134 | 135 | * Your patch fixes spelling or grammar errors. 136 | * Your patch is a single line change to documentation. 137 | 138 | ## Community Guidelines 139 | 140 | We want to keep the openHAB community awesome, growing and collaborative. We 141 | need your help to keep it that way. To help with this we've come up with some 142 | general guidelines for the community as a whole: 143 | 144 | * Be nice: Be courteous, respectful and polite to fellow community members: no 145 | regional, racial, gender, or other abuse will be tolerated. We like nice people 146 | way better than mean ones! 147 | 148 | * Encourage diversity and participation: Make everyone in our community 149 | feel welcome, regardless of their background and the extent of their 150 | contributions, and do everything possible to encourage participation in 151 | our community. 152 | 153 | * Keep it legal: Basically, don't get us in trouble. Share only content that 154 | you own, do not share private or sensitive information, and don't break the 155 | law. 156 | 157 | * Stay on topic: Make sure that you are posting to the correct channel 158 | and avoid off-topic discussions. Remember when you update an issue or 159 | respond to an email you are potentially sending to a large number of 160 | people. Please consider this before you update. Also remember that 161 | nobody likes spam. 162 | 163 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 2.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 4 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION 5 | OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial content 12 | Distributed under this Agreement, and 13 | 14 | b) in the case of each subsequent Contributor: 15 | i) changes to the Program, and 16 | ii) additions to the Program; 17 | where such changes and/or additions to the Program originate from 18 | and are Distributed by that particular Contributor. A Contribution 19 | "originates" from a Contributor if it was added to the Program by 20 | such Contributor itself or anyone acting on such Contributor's behalf. 21 | Contributions do not include changes or additions to the Program that 22 | are not Modified Works. 23 | 24 | "Contributor" means any person or entity that Distributes the Program. 25 | 26 | "Licensed Patents" mean patent claims licensable by a Contributor which 27 | are necessarily infringed by the use or sale of its Contribution alone 28 | or when combined with the Program. 29 | 30 | "Program" means the Contributions Distributed in accordance with this 31 | Agreement. 32 | 33 | "Recipient" means anyone who receives the Program under this Agreement 34 | or any Secondary License (as applicable), including Contributors. 35 | 36 | "Derivative Works" shall mean any work, whether in Source Code or other 37 | form, that is based on (or derived from) the Program and for which the 38 | editorial revisions, annotations, elaborations, or other modifications 39 | represent, as a whole, an original work of authorship. 40 | 41 | "Modified Works" shall mean any work in Source Code or other form that 42 | results from an addition to, deletion from, or modification of the 43 | contents of the Program, including, for purposes of clarity any new file 44 | in Source Code form that contains any contents of the Program. Modified 45 | Works shall not include works that contain only declarations, 46 | interfaces, types, classes, structures, or files of the Program solely 47 | in each case in order to link to, bind by name, or subclass the Program 48 | or Modified Works thereof. 49 | 50 | "Distribute" means the acts of a) distributing or b) making available 51 | in any manner that enables the transfer of a copy. 52 | 53 | "Source Code" means the form of a Program preferred for making 54 | modifications, including but not limited to software source code, 55 | documentation source, and configuration files. 56 | 57 | "Secondary License" means either the GNU General Public License, 58 | Version 2.0, or any later versions of that license, including any 59 | exceptions or additional permissions as identified by the initial 60 | Contributor. 61 | 62 | 2. GRANT OF RIGHTS 63 | 64 | a) Subject to the terms of this Agreement, each Contributor hereby 65 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 66 | license to reproduce, prepare Derivative Works of, publicly display, 67 | publicly perform, Distribute and sublicense the Contribution of such 68 | Contributor, if any, and such Derivative Works. 69 | 70 | b) Subject to the terms of this Agreement, each Contributor hereby 71 | grants Recipient a non-exclusive, worldwide, royalty-free patent 72 | license under Licensed Patents to make, use, sell, offer to sell, 73 | import and otherwise transfer the Contribution of such Contributor, 74 | if any, in Source Code or other form. This patent license shall 75 | apply to the combination of the Contribution and the Program if, at 76 | the time the Contribution is added by the Contributor, such addition 77 | of the Contribution causes such combination to be covered by the 78 | Licensed Patents. The patent license shall not apply to any other 79 | combinations which include the Contribution. No hardware per se is 80 | licensed hereunder. 81 | 82 | c) Recipient understands that although each Contributor grants the 83 | licenses to its Contributions set forth herein, no assurances are 84 | provided by any Contributor that the Program does not infringe the 85 | patent or other intellectual property rights of any other entity. 86 | Each Contributor disclaims any liability to Recipient for claims 87 | brought by any other entity based on infringement of intellectual 88 | property rights or otherwise. As a condition to exercising the 89 | rights and licenses granted hereunder, each Recipient hereby 90 | assumes sole responsibility to secure any other intellectual 91 | property rights needed, if any. For example, if a third party 92 | patent license is required to allow Recipient to Distribute the 93 | Program, it is Recipient's responsibility to acquire that license 94 | before distributing the Program. 95 | 96 | d) Each Contributor represents that to its knowledge it has 97 | sufficient copyright rights in its Contribution, if any, to grant 98 | the copyright license set forth in this Agreement. 99 | 100 | e) Notwithstanding the terms of any Secondary License, no 101 | Contributor makes additional grants to any Recipient (other than 102 | those set forth in this Agreement) as a result of such Recipient's 103 | receipt of the Program under the terms of a Secondary License 104 | (if permitted under the terms of Section 3). 105 | 106 | 3. REQUIREMENTS 107 | 108 | 3.1 If a Contributor Distributes the Program in any form, then: 109 | 110 | a) the Program must also be made available as Source Code, in 111 | accordance with section 3.2, and the Contributor must accompany 112 | the Program with a statement that the Source Code for the Program 113 | is available under this Agreement, and informs Recipients how to 114 | obtain it in a reasonable manner on or through a medium customarily 115 | used for software exchange; and 116 | 117 | b) the Contributor may Distribute the Program under a license 118 | different than this Agreement, provided that such license: 119 | i) effectively disclaims on behalf of all other Contributors all 120 | warranties and conditions, express and implied, including 121 | warranties or conditions of title and non-infringement, and 122 | implied warranties or conditions of merchantability and fitness 123 | for a particular purpose; 124 | 125 | ii) effectively excludes on behalf of all other Contributors all 126 | liability for damages, including direct, indirect, special, 127 | incidental and consequential damages, such as lost profits; 128 | 129 | iii) does not attempt to limit or alter the recipients' rights 130 | in the Source Code under section 3.2; and 131 | 132 | iv) requires any subsequent distribution of the Program by any 133 | party to be under a license that satisfies the requirements 134 | of this section 3. 135 | 136 | 3.2 When the Program is Distributed as Source Code: 137 | 138 | a) it must be made available under this Agreement, or if the 139 | Program (i) is combined with other material in a separate file or 140 | files made available under a Secondary License, and (ii) the initial 141 | Contributor attached to the Source Code the notice described in 142 | Exhibit A of this Agreement, then the Program may be made available 143 | under the terms of such Secondary Licenses, and 144 | 145 | b) a copy of this Agreement must be included with each copy of 146 | the Program. 147 | 148 | 3.3 Contributors may not remove or alter any copyright, patent, 149 | trademark, attribution notices, disclaimers of warranty, or limitations 150 | of liability ("notices") contained within the Program from any copy of 151 | the Program which they Distribute, provided that Contributors may add 152 | their own appropriate notices. 153 | 154 | 4. COMMERCIAL DISTRIBUTION 155 | 156 | Commercial distributors of software may accept certain responsibilities 157 | with respect to end users, business partners and the like. While this 158 | license is intended to facilitate the commercial use of the Program, 159 | the Contributor who includes the Program in a commercial product 160 | offering should do so in a manner which does not create potential 161 | liability for other Contributors. Therefore, if a Contributor includes 162 | the Program in a commercial product offering, such Contributor 163 | ("Commercial Contributor") hereby agrees to defend and indemnify every 164 | other Contributor ("Indemnified Contributor") against any losses, 165 | damages and costs (collectively "Losses") arising from claims, lawsuits 166 | and other legal actions brought by a third party against the Indemnified 167 | Contributor to the extent caused by the acts or omissions of such 168 | Commercial Contributor in connection with its distribution of the Program 169 | in a commercial product offering. The obligations in this section do not 170 | apply to any claims or Losses relating to any actual or alleged 171 | intellectual property infringement. In order to qualify, an Indemnified 172 | Contributor must: a) promptly notify the Commercial Contributor in 173 | writing of such claim, and b) allow the Commercial Contributor to control, 174 | and cooperate with the Commercial Contributor in, the defense and any 175 | related settlement negotiations. The Indemnified Contributor may 176 | participate in any such claim at its own expense. 177 | 178 | For example, a Contributor might include the Program in a commercial 179 | product offering, Product X. That Contributor is then a Commercial 180 | Contributor. If that Commercial Contributor then makes performance 181 | claims, or offers warranties related to Product X, those performance 182 | claims and warranties are such Commercial Contributor's responsibility 183 | alone. Under this section, the Commercial Contributor would have to 184 | defend claims against the other Contributors related to those performance 185 | claims and warranties, and if a court requires any other Contributor to 186 | pay any damages as a result, the Commercial Contributor must pay 187 | those damages. 188 | 189 | 5. NO WARRANTY 190 | 191 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 192 | PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" 193 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 194 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF 195 | TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 196 | PURPOSE. Each Recipient is solely responsible for determining the 197 | appropriateness of using and distributing the Program and assumes all 198 | risks associated with its exercise of rights under this Agreement, 199 | including but not limited to the risks and costs of program errors, 200 | compliance with applicable laws, damage to or loss of data, programs 201 | or equipment, and unavailability or interruption of operations. 202 | 203 | 6. DISCLAIMER OF LIABILITY 204 | 205 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 206 | PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS 207 | SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 208 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST 209 | PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 210 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 211 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 212 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE 213 | POSSIBILITY OF SUCH DAMAGES. 214 | 215 | 7. GENERAL 216 | 217 | If any provision of this Agreement is invalid or unenforceable under 218 | applicable law, it shall not affect the validity or enforceability of 219 | the remainder of the terms of this Agreement, and without further 220 | action by the parties hereto, such provision shall be reformed to the 221 | minimum extent necessary to make such provision valid and enforceable. 222 | 223 | If Recipient institutes patent litigation against any entity 224 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 225 | Program itself (excluding combinations of the Program with other software 226 | or hardware) infringes such Recipient's patent(s), then such Recipient's 227 | rights granted under Section 2(b) shall terminate as of the date such 228 | litigation is filed. 229 | 230 | All Recipient's rights under this Agreement shall terminate if it 231 | fails to comply with any of the material terms or conditions of this 232 | Agreement and does not cure such failure in a reasonable period of 233 | time after becoming aware of such noncompliance. If all Recipient's 234 | rights under this Agreement terminate, Recipient agrees to cease use 235 | and distribution of the Program as soon as reasonably practicable. 236 | However, Recipient's obligations under this Agreement and any licenses 237 | granted by Recipient relating to the Program shall continue and survive. 238 | 239 | Everyone is permitted to copy and distribute copies of this Agreement, 240 | but in order to avoid inconsistency the Agreement is copyrighted and 241 | may only be modified in the following manner. The Agreement Steward 242 | reserves the right to publish new versions (including revisions) of 243 | this Agreement from time to time. No one other than the Agreement 244 | Steward has the right to modify this Agreement. The Eclipse Foundation 245 | is the initial Agreement Steward. The Eclipse Foundation may assign the 246 | responsibility to serve as the Agreement Steward to a suitable separate 247 | entity. Each new version of the Agreement will be given a distinguishing 248 | version number. The Program (including Contributions) may always be 249 | Distributed subject to the version of the Agreement under which it was 250 | received. In addition, after a new version of the Agreement is published, 251 | Contributor may elect to Distribute the Program (including its 252 | Contributions) under the new version. 253 | 254 | Except as expressly stated in Sections 2(a) and 2(b) above, Recipient 255 | receives no rights or licenses to the intellectual property of any 256 | Contributor under this Agreement, whether expressly, by implication, 257 | estoppel or otherwise. All rights in the Program not expressly granted 258 | under this Agreement are reserved. Nothing in this Agreement is intended 259 | to be enforceable by any entity that is not a Contributor or Recipient. 260 | No third-party beneficiary rights are created under this Agreement. 261 | 262 | Exhibit A - Form of Secondary Licenses Notice 263 | 264 | "This Source Code may also be made available under the following 265 | Secondary Licenses when the conditions for such availability set forth 266 | in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), 267 | version(s), and exceptions or additional permissions here}." 268 | 269 | Simply including a copy of this Agreement, including this Exhibit A 270 | is not sufficient to license the Source Code under Secondary Licenses. 271 | 272 | If it is not possible or desirable to put the notice in a particular 273 | file, then You may include the notice in a location (such as a LICENSE 274 | file in a relevant directory) where a recipient would be likely to 275 | look for such a notice. 276 | 277 | You may add additional accurate notices of copyright ownership. 278 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openHAB Docker Containers 2 | 3 | ![openHAB logo](https://github.com/openhab/openhab-docker/raw/main/openhab.png) 4 | 5 | [![Build Status](https://ci.openhab.org/job/openHAB-Docker/badge/icon)](https://ci.openhab.org/job/openHAB-Docker/) 6 | [![EPL-2.0](https://img.shields.io/badge/license-EPL%202-green.svg)](https://opensource.org/licenses/EPL-2.0) 7 | [![Docker Version](https://img.shields.io/badge/version-4.3.5-blue)](https://hub.docker.com/repository/docker/openhab/openhab/tags?name=4.3.5) 8 | [![Docker Stars](https://img.shields.io/docker/stars/openhab/openhab.svg?cacheSeconds=2592000)](https://hub.docker.com/r/openhab/openhab/) 9 | [![Docker Pulls](https://img.shields.io/docker/pulls/openhab/openhab.svg?cacheSeconds=2592000)](https://hub.docker.com/r/openhab/openhab/) 10 | [![GitHub Issues](https://img.shields.io/github/issues/openhab/openhab-docker.svg)](https://github.com/openhab/openhab-docker/issues) 11 | [![GitHub Stars](https://img.shields.io/github/stars/openhab/openhab-docker.svg)](https://github.com/openhab/openhab-docker/stargazers) 12 | [![GitHub Forks](https://img.shields.io/github/forks/openhab/openhab-docker.svg)](https://github.com/openhab/openhab-docker/network) 13 | [![CodeFactor](https://www.codefactor.io/repository/github/openhab/openhab-docker/badge)](https://www.codefactor.io/repository/github/openhab/openhab-docker) 14 | [![Gitter Chat](https://badges.gitter.im/openhab/openhab-docker.svg)](https://gitter.im/openhab/openhab-docker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 15 | 16 | # Table of Contents 17 | 18 | * [openHAB Docker Containers](#openhab-docker-containers) 19 | * [Introduction](#introduction) 20 | * [Image variants](#image-variants) 21 | * [Usage](#usage) 22 | * [Starting with Docker named volumes (for beginners)](#starting-with-docker-named-volumes-for-beginners) 23 | * [Running from command line](#running-from-command-line) 24 | * [Running from compose-file.yml](#running-from-compose-fileyml) 25 | * [Running openHAB with libpcap support](#running-openhab-with-libpcap-support) 26 | * [Running on Windows and macOS](#running-on-windows-and-macos) 27 | * [Starting with Docker mounting a host directory (for advanced user)](#starting-with-docker-mounting-a-host-directory-for-advanced-user) 28 | * [Automating Docker setup using ansible (for advanced user)](#automating-docker-setup-using-ansible-for-advanced-user) 29 | * [Accessing the console](#accessing-the-console) 30 | * [Startup modes](#startup-modes) 31 | * [Environment variables](#environment-variables) 32 | * [User and group identifiers](#user-and-group-identifiers) 33 | * [Java cryptographic strength policy](#java-cryptographic-strength-policy) 34 | * [Parameters](#parameters) 35 | * [Passing devices with symlinks](#passing-devices-with-symlinks) 36 | * [Executing shell scripts before openHAB is started](#executing-shell-scripts-before-openhab-is-started) 37 | * [Upgrading](#upgrading) 38 | * [Common problems](#common-problems) 39 | * [Building the images](#building-the-images) 40 | * [Contributing](#contributing) 41 | 42 | ## Introduction 43 | 44 | Repository for building Docker containers for [openHAB](https://openhab.org) (Home Automation Server). 45 | Comments, suggestions and contributions are welcome! 46 | 47 | ## Image variants 48 | 49 | The openHAB Docker images are available in the [openhab/openhab](https://hub.docker.com/r/openhab/openhab/) repository on Docker Hub. 50 | 51 | * For specific versions use: 52 | - `openhab/openhab:` 53 | - `openhab/openhab:-` 54 | 55 | * For the latest stable release use: 56 | - `openhab/openhab` 57 | - `openhab/openhab:latest` 58 | - `openhab/openhab:latest-` 59 | 60 | * For the latest release that has a milestone or stable maturity use: 61 | - `openhab/openhab:milestone` 62 | - `openhab/openhab:milestone-` 63 | 64 | * For the latest snapshot release use: 65 | - `openhab/openhab:snapshot` 66 | - `openhab/openhab:snapshot-` 67 | 68 | **Versions:** 69 | 70 | * **Stable:** Thoroughly tested semi-annual official releases of openHAB. Use the stable version for your production environment if you do not need the latest enhancements and prefer a robust system. 71 | * `4.3.5` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/4.3.5)) 72 | * `4.2.3` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/4.2.3)) 73 | * **Milestone:** Intermediary releases of the next openHAB version which are released about once a month. They include recently added features and bugfixes and are a good compromise between the current stable version and the bleeding-edge and potentially unstable snapshot version. 74 | * `5.0.0.M2` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/5.0.0.M2)) 75 | * `5.0.0.M1` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/5.0.0.M1)) 76 | * **Snapshot:** Usually 1 or 2 days old and include the latest code. Use these for testing out very recent changes using the latest code. Be aware that some snapshots might be unstable so use these in production at your own risk! 77 | * `5.0.0-snapshot` 78 | 79 | **Distributions:** 80 | 81 | * `debian` for Debian 12 "bookworm" (default when not specified in tag) ([Dockerfile](https://github.com/openhab/openhab-docker/blob/main/debian/Dockerfile)) 82 | * `alpine` for Alpine 3.21 ([Dockerfile](https://github.com/openhab/openhab-docker/blob/main/alpine/Dockerfile)) 83 | 84 | The Alpine images are substantially smaller than the Debian images but may be less compatible because OpenJDK is used (see [Prerequisites](https://www.openhab.org/docs/installation/#prerequisites) for known disadvantages). 85 | Older container images may use older versions of the Debian and Alpine base images. 86 | 87 | If you are unsure about what your needs are, you probably want to use `openhab/openhab:4.3.5`. 88 | 89 | **Platforms:** 90 | 91 | The following Docker platforms are supported (automatically determined): 92 | 93 | * `linux/amd64` 94 | * `linux/arm64` 95 | * `linux/arm/v7` (Debian openHAB 4 (or older), Alpine openHAB 2 (or older)) 96 | 97 | ## Usage 98 | 99 | **Important:** To be able to use UPnP for discovery the container needs to be started with `--net=host`. 100 | 101 | **Important:** In the container openHAB runs with user "openhab" (id 9001) by default. See user configuration section below! 102 | 103 | The following will run openHAB in demo mode on the host machine: 104 | 105 | `docker run --name openhab --net=host openhab/openhab:4.3.5` 106 | 107 | _**NOTE:** Although this is the simplest method to getting openHAB up and running, but it is not the preferred method. 108 | To properly run the container, please specify a **host volume** for the directories._ 109 | 110 | ### Starting with Docker named volumes (for beginners) 111 | 112 | The following configuration uses Docker named data volumes. 113 | These volumes will survive, if you delete or upgrade your container. 114 | It is a good starting point for beginners. 115 | The volumes are created in the Docker volume directory. 116 | You can use `docker inspect openhab` to locate the directories (e.g. /var/lib/docker/volumes) on your host system. 117 | For more information visit [Manage data in containers](https://docs.docker.com/engine/tutorials/dockervolumes/). 118 | 119 | #### Running from command line 120 | 121 | ```shell 122 | docker run \ 123 | --name openhab \ 124 | --net=host \ 125 | -v /etc/localtime:/etc/localtime:ro \ 126 | -v /etc/timezone:/etc/timezone:ro \ 127 | -v openhab_addons:/openhab/addons \ 128 | -v openhab_conf:/openhab/conf \ 129 | -v openhab_userdata:/openhab/userdata \ 130 | -e "CRYPTO_POLICY=unlimited" \ 131 | -e "EXTRA_JAVA_OPTS=-Duser.timezone=Europe/Berlin" \ 132 | -d \ 133 | --restart=always \ 134 | openhab/openhab:4.3.5 135 | ``` 136 | 137 | #### Running from compose-file.yml 138 | 139 | Create the following `docker-compose.yml` for use of local directories and start the container with `docker compose up -d` 140 | 141 | ```yaml 142 | services: 143 | openhab: 144 | image: "openhab/openhab:4.3.5" 145 | restart: always 146 | network_mode: host 147 | volumes: 148 | - "/etc/localtime:/etc/localtime:ro" 149 | - "/etc/timezone:/etc/timezone:ro" 150 | - "./openhab_addons:/openhab/addons" 151 | - "./openhab_conf:/openhab/conf" 152 | - "./openhab_userdata:/openhab/userdata" 153 | environment: 154 | CRYPTO_POLICY: "unlimited" 155 | EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin" 156 | OPENHAB_HTTP_PORT: "8080" 157 | OPENHAB_HTTPS_PORT: "8443" 158 | ``` 159 | 160 | Create the following `docker-compose.yml` for use of Docker volumes and start the container with `docker compose up -d` 161 | 162 | ```yml 163 | services: 164 | openhab: 165 | image: "openhab/openhab:4.3.5" 166 | restart: always 167 | network_mode: host 168 | volumes: 169 | - "/etc/localtime:/etc/localtime:ro" 170 | - "/etc/timezone:/etc/timezone:ro" 171 | - "openhab_addons:/openhab/addons" 172 | - "openhab_conf:/openhab/conf" 173 | - "openhab_userdata:/openhab/userdata" 174 | environment: 175 | CRYPTO_POLICY: "unlimited" 176 | EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin" 177 | OPENHAB_HTTP_PORT: "8080" 178 | OPENHAB_HTTPS_PORT: "8443" 179 | 180 | volumes: 181 | openhab_addons: 182 | driver: local 183 | openhab_conf: 184 | driver: local 185 | openhab_userdata: 186 | driver: local 187 | ``` 188 | 189 | ### Running openHAB with libpcap support 190 | 191 | You can run all openHAB images with libpcap support by configuring additional capabilities. 192 | This allows for using the *Amazon Dash Button Binding* in the Docker container. 193 | Create the following `docker-compose.yml` and start the container with `docker compose up -d` 194 | 195 | ```yaml 196 | services: 197 | openhab: 198 | container_name: openhab 199 | image: "openhab/openhab:4.3.5" 200 | restart: always 201 | network_mode: host 202 | cap_add: 203 | - NET_ADMIN 204 | - NET_RAW 205 | volumes: 206 | - "/etc/localtime:/etc/localtime:ro" 207 | - "/etc/timezone:/etc/timezone:ro" 208 | - "./openhab_addons:/openhab/addons" 209 | - "./openhab_conf:/openhab/conf" 210 | - "./openhab_userdata:/openhab/userdata" 211 | ``` 212 | 213 | ### Running on Windows and macOS 214 | 215 | The `host` networking driver only works on Linux hosts, and is not supported by Docker on Windows and macOS. 216 | On Windows and macOS ports should be exposed by adding port options to commands (`-p 8080`) or by adding a ports section to `docker-compose.yml`. 217 | 218 | ```yaml 219 | services: 220 | openhab: 221 | image: "openhab/openhab:4.3.5" 222 | restart: always 223 | ports: 224 | - "8080:8080" 225 | - "8443:8443" 226 | volumes: 227 | - "./openhab_addons:/openhab/addons" 228 | - "./openhab_conf:/openhab/conf" 229 | - "./openhab_userdata:/openhab/userdata" 230 | environment: 231 | CRYPTO_POLICY: "unlimited" 232 | EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin" 233 | OPENHAB_HTTP_PORT: "8080" 234 | OPENHAB_HTTPS_PORT: "8443" 235 | ``` 236 | 237 | ### Starting with Docker mounting a host directory (for advanced user) 238 | 239 | You can mount a local host directory to store your configuration files. 240 | If you followed the beginners guide, you do not need to read this section. 241 | The following `run` command will create the folders and copy the initial configuration files for you. 242 | 243 | ```shell 244 | docker run \ 245 | --name openhab \ 246 | --net=host \ 247 | -v /etc/localtime:/etc/localtime:ro \ 248 | -v /etc/timezone:/etc/timezone:ro \ 249 | -v /opt/openhab/addons:/openhab/addons \ 250 | -v /opt/openhab/conf:/openhab/conf \ 251 | -v /opt/openhab/userdata:/openhab/userdata \ 252 | -e "CRYPTO_POLICY=unlimited" \ 253 | -e "EXTRA_JAVA_OPTS=-Duser.timezone=Europe/Berlin" \ 254 | openhab/openhab:4.3.5 255 | ``` 256 | 257 | ### Automating Docker setup using Ansible (for advanced user) 258 | 259 | Here is an example playbook in case you control your environment with Ansible. 260 | You can test it by running `ansible-playbook -i mycontainerhost, -t openhab run-containers.yml`. 261 | The `:Z` at the end of volume lines is for SELinux systems. 262 | If run elsewhere, replace it with ro. 263 | 264 | ```yaml 265 | - name: ensure containers are running 266 | hosts: all 267 | tasks: 268 | 269 | - name: ensure openhab is up 270 | tags: openhab 271 | docker_container: 272 | name: openhab 273 | image: openhab/openhab:4.3.5 274 | state: started 275 | detach: yes 276 | ports: 277 | - 8080:8080 278 | - 8101:8101 279 | - 5007:5007 280 | volumes: 281 | - "/etc/localtime:/etc/localtime:ro" 282 | - "/etc/timezone:/etc/timezone:ro" 283 | - "/opt/openhab/addons:/openhab/addons:Z" 284 | - "/opt/openhab/conf:/openhab/conf:Z" 285 | - "/opt/openhab/userdata:/openhab/userdata:Z" 286 | keep_volumes: yes 287 | hostname: openhab.localnet 288 | memory: 512m 289 | pull: true 290 | restart_policy: unless-stopped 291 | env: 292 | CRYPTO_POLICY="unlimited" 293 | EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Berlin" 294 | ``` 295 | 296 | ### Accessing the console 297 | 298 | You can connect to a console of an already running openHAB container with the following command: 299 | 300 | `docker exec -it openhab /openhab/runtime/bin/client` 301 | 302 | The default password for the login is: `habopen` 303 | 304 | ### Startup modes 305 | 306 | #### Server mode 307 | 308 | The container starts openHAB in server mode when no TTY is provided, example: 309 | 310 | `docker run --detach --name openhab openhab/openhab:4.3.5` 311 | 312 | When the container runs in server mode you can also add a console logger so it prints logging to stdout so you can check the logging of a container named "openhab" with: 313 | 314 | `docker logs openhab` 315 | 316 | To use a console logger with openHAB 3 (or newer), edit `userdata/etc/log4j2.xml` and add the following appender to the "Root logger" and "openhab.event" logger configurations: `` 317 | 318 | To use a console logger with openHAB 2, edit `userdata/etc/org.ops4j.pax.logging.cfg` and then: 319 | 320 | * Update the appenderRefs line to: `log4j2.rootLogger.appenderRefs = out, osgi, console` 321 | * Add the following line: `log4j2.rootLogger.appenderRef.console.ref = STDOUT` 322 | 323 | #### Regular mode 324 | 325 | When a TTY is provided openHAB is started with an interactive console, e.g.: 326 | 327 | `docker run -it openhab/openhab:4.3.5` 328 | 329 | #### Debug mode 330 | 331 | The debug mode is started with the command: 332 | 333 | `docker run -it openhab/openhab:4.3.5 ./start_debug.sh` 334 | 335 | ## Environment variables 336 | 337 | * `CRYPTO_POLICY`=limited 338 | * `EXTRA_JAVA_OPTS`="" 339 | * `EXTRA_SHELL_OPTS`="" 340 | * `LC_ALL`=en_US.UTF-8 341 | * `LANG`=en_US.UTF-8 342 | * `LANGUAGE`=en_US.UTF-8 343 | * `OPENHAB_HTTP_PORT`=8080 344 | * `OPENHAB_HTTPS_PORT`=8443 345 | * `USER_ID`=9001 346 | * `GROUP_ID`=9001 347 | 348 | ### User and group identifiers 349 | 350 | The group ID will default to the same value as the user ID. 351 | By default the openHAB user in the container is running with: 352 | 353 | * `uid=9001(openhab) gid=9001(openhab) groups=9001(openhab)` 354 | 355 | Make sure that either 356 | 357 | * You create the same user with the same uid and gid on your Docker host system 358 | 359 | ```shell 360 | groupadd -g 9001 openhab 361 | useradd -u 9001 -g openhab -r -s /sbin/nologin openhab 362 | usermod -a -G openhab myownuser 363 | ``` 364 | 365 | * Or run the Docker container with your own user AND pass the uid and gid to openHAB with environment variables 366 | 367 | ```shell 368 | docker run \ 369 | (...) 370 | -e USER_ID= \ 371 | -e GROUP_ID= \ 372 | (...) 373 | ``` 374 | 375 | You can obtain your user and group ID by executing the `id --user` and `id --group` commands. 376 | 377 | ### Java cryptographic strength policy 378 | 379 | Due to local laws and export restrictions the containers use Java with a limited cryptographic strength policy. 380 | Some openHAB functionality may depend on unlimited strength which can be enabled by configuring the environment variable `CRYPTO_POLICY`=unlimited 381 | 382 | Before enabling this make sure this is allowed by local laws and you agree with the applicable license and terms (see [OpenJDK (Cryptographic Cautions)](https://openjdk.java.net/groups/security)). 383 | 384 | The following functionality depends on the unlimited cryptographic strength policy: 385 | 386 | * air-Q Binding 387 | * KM200 Binding 388 | * Linky Binding 389 | * Loxone Binding 390 | * MQTT Binding 391 | * openHAB Marketplace 392 | 393 | ## Parameters 394 | 395 | * `-it` - starts openHAB with an interactive console (since openHAB 2.0.0) 396 | * `-p 8080` - the HTTP port of the web interface 397 | * `-p 8443` - the HTTPS port of the web interface 398 | * `-p 8101` - the SSH port of the [Console](https://www.openhab.org/docs/administration/console.html) (since openHAB 2.0.0) 399 | * `-p 5007` - the LSP port for [validating rules](https://github.com/openhab/openhab-vscode#validating-the-rules) (since openHAB 2.2.0) 400 | * `-v /openhab/addons` - custom openHAB addons 401 | * `-v /openhab/conf` - openHAB configs 402 | * `-v /openhab/userdata` - openHAB userdata directory 403 | * `--device=/dev/ttyUSB0` - attach your devices like RFXCOM or Z-Wave Sticks to the container 404 | 405 | ### Passing devices with symlinks 406 | 407 | On Linux, if you pass a device with a symlink or any non standard name (e.g. /dev/ttyZWave), some addons require the device name to follow the Linux serial port naming rules (e.g. "ttyACM0", "ttyUSB0" or "ttyUSB-9999") or will otherwise fail to discover the device. 408 | 409 | This can be achieved by mapping the devices to a compliant name like this: 410 | 411 | ```shell 412 | docker run \ 413 | (...) 414 | --device=/dev/ttyZWave:/dev/ttyACM0 415 | --device=/dev/ttyZigbee:/dev/ttyACM1 416 | (...) 417 | ``` 418 | 419 | More information about serial ports and symlinks can be found [here](https://www.openhab.org/docs/administration/serial.html). 420 | 421 | ## Executing shell scripts before openHAB is started 422 | 423 | It is sometimes useful to run shell scripts after the "userdata" directory is created, but before Karaf itself is launched. 424 | One such case is creating SSH host keys, and allowing access to the system from the outside via SSH. 425 | Exemplary scripts can be found in the [contrib/cont-init.d](https://github.com/openhab/openhab-docker/tree/main/contrib/cont-init.d) directory 426 | 427 | To use this, create a directory called 428 | 429 | ```shell 430 | /etc/cont-init.d 431 | ``` 432 | 433 | and add a volume mount to your startup: 434 | 435 | ```shell 436 | ... 437 | -v /etc/cont-init.d:/etc/cont-init.d \ 438 | ... 439 | ``` 440 | 441 | and put your scripts into that directory. 442 | This can be done by either using a volume mount (see the examples above) or creating your own images which inherit from the official ones. 443 | 444 | ## Upgrading 445 | 446 | Upgrading openHAB requires changes to the user mapped in userdata folder. 447 | The container will perform these steps automatically when it detects that the `userdata/etc/version.properties` is different from the version in `dist/userdata/etc/version.properties` in the Docker image. 448 | 449 | The steps performed are: 450 | * Create a `userdata/backup` folder if one does not exist. 451 | * Create a full backup of userdata as a dated tar file saved to `userdata/backup`. The `userdata/backup` folder is excluded from this backup. 452 | * Show update notes and warnings. 453 | * Execute update pre/post commands. 454 | * Copy userdata system files from `dist/userdata/etc` to `userdata/etc`. 455 | * Update KAR files in `addons`. 456 | * Delete the contents of `userdata/cache` and `userdata/tmp`. 457 | 458 | The steps performed are the same as those performed by running the upgrade script that comes with OH, except the backup is performed differently and the latest openHAB runtime is not downloaded. 459 | All messages shown during the update are also logged to `userdata/logs/update.log`. 460 | 461 | ## Common problems 462 | 463 | ### Error: KARAF_ETC is not valid 464 | 465 | This error message indicates that the data in the volumes is not properly initialized. 466 | The error is usually the result of a permissions issue or already putting files into volumes without the volumes having been initialized by the container first. 467 | When mounting directories into the container, check that these directories exist, are completely empty and are owned by the same `USER_ID` and `GROUP_ID` as configured in the container ENV variables. 468 | 469 | ### Missing some preinstalled package 470 | 471 | Docker containers are kept as small as possible intentionally to decrease download times and the number of potential vulnerabilities for everyone. 472 | If you want additional packages installed, create your own container based on this container. 473 | Another option is to install the package by [executing a shell script before openHAB is started](#executing-shell-scripts-before-openhab-is-started). 474 | 475 | ### No logging after "Launching the openHAB runtime..." 476 | 477 | By default this will always be the last logged message. 478 | A console logger can be [configured](#server-mode) for more detailed logging. 479 | 480 | ### OpenJDK Client VM warning: No monotonic clock was available 481 | 482 | This error message may occur when running a recent openHAB container image on a Docker host with an outdated version of libseccomp2. 483 | The issue can be fixed by upgrading libseccomp2 on your Docker host to a more recent version. 484 | For more details see this [community thread](https://community.openhab.org/t/128865). 485 | 486 | ### OpenMediaVault 487 | 488 | The default filesystem mount flags of OpenMediaVault contain the `noexec` flag which interferes with the serial library used by openHAB. 489 | To be able to use serial devices with openHAB, make sure the `userdata` volume mounted by the container is not backed by a filesystem having the `noexec` flag. 490 | See the [OMV documentation](https://openmediavault.readthedocs.io/en/6.x/various/fs_env_vars.html) on how to remove the `noexec` flag from an existing filesystem. 491 | 492 | ### Portainer 493 | 494 | The default values of ENV variables are always stored by Portainer (see [portainer/portainer#2952](https://github.com/portainer/portainer/issues/2952)). 495 | This causes issues such as endless restart loops when upgrading the container with Portainer. 496 | To resolve this issue when upgrading openHAB, first remove all default (non-overridden) ENV variables before starting the new container. 497 | 498 | ### SELinux 499 | 500 | When using the container on a Linux distribution with SELinux enabled (CentOS/Fedora/RHEL), add the `:z` or `:Z` option to volumes to give the container write permissions. 501 | For more information on this see the [Docker documentation](https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label). 502 | 503 | ## Building the images 504 | 505 | Checkout the GitHub repository, change to a directory containing a Dockerfile (e.g. `/debian`) and then run these commands to build and run a Docker image for your current platform: 506 | 507 | ```shell 508 | $ docker build --build-arg JAVA_VERSION=17 --build-arg OPENHAB_VERSION=4.3.5 --tag openhab/openhab . 509 | $ docker run openhab/openhab 510 | ``` 511 | 512 | To be able to build the same image for other platforms (e.g. arm/v7, arm64 on amd64) Docker CE with BuildKit support can be used. 513 | 514 | First configure QEMU binary formats and a builder using: 515 | 516 | ```shell 517 | $ docker run --privileged --rm tonistiigi/binfmt:qemu-v8.1.5 --install all 518 | $ docker buildx create --name builder --use 519 | ``` 520 | 521 | Change to a directory containing a Dockerfile (e.g. `/debian`) and then use the following command to build an ARMv7 image: 522 | 523 | ```shell 524 | $ docker buildx build --build-arg JAVA_VERSION=17 --build-arg OPENHAB_VERSION=4.3.5 --platform linux/arm/v7 --tag openhab/openhab --load . 525 | ``` 526 | 527 | The `build` script in the root of the repository helps to simplify building the openHAB images with BuildKit. 528 | It can be used to build the images of multiple openHAB versions and correctly tag and push them to a Docker registry. 529 | Execute `./build -h` for usage instructions and examples. 530 | 531 | ## Contributing 532 | 533 | [Contribution guidelines](https://github.com/openhab/openhab-docker/blob/main/CONTRIBUTING.md) 534 | -------------------------------------------------------------------------------- /alpine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | ARG BUILD_DATE 4 | ARG VCS_REF 5 | ARG JAVA_VERSION 6 | ARG OPENHAB_VERSION 7 | 8 | ENV \ 9 | CRYPTO_POLICY="limited" \ 10 | EXTRA_JAVA_OPTS="" \ 11 | EXTRA_SHELL_OPTS="" \ 12 | GROUP_ID="9001" \ 13 | KARAF_EXEC="exec" \ 14 | LC_ALL="en_US.UTF-8" \ 15 | LANG="en_US.UTF-8" \ 16 | LANGUAGE="en_US.UTF-8" \ 17 | OPENHAB_BACKUPS="/openhab/userdata/backup" \ 18 | OPENHAB_CONF="/openhab/conf" \ 19 | OPENHAB_HOME="/openhab" \ 20 | OPENHAB_HTTP_PORT="8080" \ 21 | OPENHAB_HTTPS_PORT="8443" \ 22 | OPENHAB_LOGDIR="/openhab/userdata/logs" \ 23 | OPENHAB_USERDATA="/openhab/userdata" \ 24 | USER_ID="9001" 25 | 26 | # Basic build-time metadata as defined at https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys 27 | LABEL org.opencontainers.image.created=$BUILD_DATE \ 28 | org.opencontainers.image.licenses="EPL-2.0" \ 29 | org.opencontainers.image.title="openHAB" \ 30 | org.opencontainers.image.vendor="openHAB Foundation e.V." \ 31 | org.opencontainers.image.version=$OPENHAB_VERSION \ 32 | org.opencontainers.image.description="An open source, technology agnostic home automation platform" \ 33 | org.opencontainers.image.url="https://www.openhab.org/" \ 34 | org.opencontainers.image.documentation="https://www.openhab.org/docs/installation/docker.html" \ 35 | org.opencontainers.image.revision=$VCS_REF \ 36 | org.opencontainers.image.source="https://github.com/openhab/openhab-docker.git" \ 37 | org.opencontainers.image.authors="openHAB " 38 | 39 | # https://github.com/hadolint/hadolint/wiki/DL4006 40 | SHELL ["/bin/ash", "-eo", "pipefail", "-c"] 41 | 42 | # Install basepackages. Versions are "pinned" by using a pinned base image. 43 | # hadolint ignore=DL3018 44 | RUN apk update --no-cache && \ 45 | apk upgrade --no-cache && \ 46 | apk add --no-cache \ 47 | arping \ 48 | bash \ 49 | ca-certificates \ 50 | curl \ 51 | eudev \ 52 | fontconfig \ 53 | gcompat \ 54 | libcap \ 55 | nss \ 56 | shadow \ 57 | su-exec \ 58 | tini \ 59 | ttf-dejavu \ 60 | openjdk${JAVA_VERSION} \ 61 | unzip \ 62 | wget \ 63 | zip && \ 64 | # Install NodeJS only for openHAB >= 5 65 | if [ "$(echo $OPENHAB_VERSION | sed -E 's/^([0-9]+).*/\1/')" -ge 5 ]; then apk add --no-cache nodejs; fi && \ 66 | chmod u+s /usr/sbin/arping && \ 67 | rm -rf /var/cache/apk/* 68 | 69 | # Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography 70 | RUN JAVA_HOME=$(find /usr/lib/jvm -mindepth 1 -maxdepth 1 -type d) && \ 71 | sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security" 72 | 73 | # Install openHAB 74 | # Set permissions for openHAB. Export TERM variable. See issue #30 for details! 75 | # Single quotes are used on purpose, so $TERM is expanded when running the container. 76 | # hadolint ignore=SC2016 77 | RUN version="$(echo $OPENHAB_VERSION | sed 's/snapshot/SNAPSHOT/g')" && \ 78 | if [ $(echo $version | grep -E '^.+\.(M|RC).+$') ]; then url="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab/${version}/openhab-${version}.zip"; \ 79 | elif [ $(echo $version | grep -E '^5\..+-SNAPSHOT$') ]; then url="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip"; \ 80 | else url="https://openhab.jfrog.io/openhab/libs-release/org/openhab/distro/openhab/${version}/openhab-${version}.zip"; fi && \ 81 | wget -nv -O /tmp/openhab.zip "$url" && \ 82 | unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ 83 | rm /tmp/openhab.zip && \ 84 | mkdir -p "${OPENHAB_LOGDIR}" && \ 85 | touch "${OPENHAB_LOGDIR}/openhab.log" && \ 86 | mkdir -p "${OPENHAB_HOME}/dist" && \ 87 | cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ 88 | echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc 89 | COPY update ${OPENHAB_HOME}/runtime/bin/update 90 | RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update 91 | 92 | # Expose volume with configuration and userdata dir 93 | VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons 94 | 95 | # Expose HTTP, HTTPS, Console and LSP ports 96 | EXPOSE 8080 8443 8101 5007 97 | 98 | # Set healthcheck 99 | HEALTHCHECK --interval=5m --timeout=5s --retries=3 CMD curl -f http://localhost:${OPENHAB_HTTP_PORT}/ || exit 1 100 | 101 | # Set working directory and entrypoint 102 | WORKDIR ${OPENHAB_HOME} 103 | COPY entrypoint /entrypoint 104 | RUN chmod +x /entrypoint 105 | ENTRYPOINT ["/entrypoint"] 106 | 107 | # Execute command 108 | CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] 109 | -------------------------------------------------------------------------------- /alpine/entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | interactive=$(if test -t 0; then echo true; else echo false; fi) 4 | set -eux -o pipefail ${EXTRA_SHELL_OPTS-} 5 | IFS=$'\n\t' 6 | 7 | export JAVA_HOME=$(find /usr/lib/jvm -mindepth 1 -maxdepth 1 -type d) 8 | 9 | # Configure Java unlimited strength cryptography 10 | if [ "${CRYPTO_POLICY}" = "unlimited" ]; then 11 | echo "Configuring Java unlimited strength cryptography policy..." 12 | sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${JAVA_HOME}/conf/security/java.security" 13 | fi 14 | 15 | # Set capabilities when available for add-ons using Pcap4J 16 | if capsh --print | grep -E 'Current:.+,cap_net_admin,cap_net_raw,.+' >/dev/null; then 17 | setcap cap_net_raw,cap_net_admin=eip "${JAVA_HOME}/bin/java" 18 | cat >> "/etc/ld-musl-$(arch).path" <<-EOI 19 | /lib 20 | /usr/lib 21 | ${JAVA_HOME}/lib 22 | ${JAVA_HOME}/lib/jli 23 | ${JAVA_HOME}/lib/security 24 | ${JAVA_HOME}/lib/server 25 | EOI 26 | fi 27 | 28 | # Delete stale nrjavaserial lock files and Karaf instance.properties to avoid PID conflicts on restarts 29 | rm -f /var/lock/LCK..* 30 | rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" 31 | 32 | # Add openhab user and add user to groups for different host distros 33 | # Alpine: audio=18, dialout=20, uucp=14 34 | # CentOS/RedHat: audio=63, dialout=18, uucp=14 35 | # Debian/Ubuntu: audio=29, dialout=20, uucp=10 36 | # Linux from Scratch: audio=11, dialout=10, uucp=32 37 | # openSUSE (old): audio=17, dialout=16, uucp=14 38 | # openSUSE (new): audio=492, dialout=490 39 | # Raspberry Pi OS: audio=29, dialout=20, uucp=10, gpio=997 40 | NEW_USER_ID=${USER_ID:-9001} 41 | NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} 42 | echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" 43 | if ! id -u openhab >/dev/null 2>&1; then 44 | if [ -z "$(getent group $NEW_GROUP_ID)" ]; then 45 | echo "Create group openhab with id ${NEW_GROUP_ID}" 46 | groupadd -g $NEW_GROUP_ID openhab 47 | else 48 | group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) 49 | echo "Rename group $group_name to openhab" 50 | groupmod --new-name openhab $group_name 51 | fi 52 | echo "Create user openhab with id ${NEW_USER_ID}" 53 | adduser -u $NEW_USER_ID -D -g '' -h ${OPENHAB_HOME} -G openhab openhab 54 | groupadd -g 29 audio2 55 | groupadd -g 32 uucp2 56 | groupadd -g 63 audio3 57 | groupadd -g 490 dialout2 58 | groupadd -g 492 audio4 59 | groupadd -g 997 gpio 60 | adduser openhab audio 61 | adduser openhab audio2 62 | adduser openhab audio3 63 | adduser openhab audio4 64 | adduser openhab dialout 65 | adduser openhab dialout2 66 | adduser openhab gpio 67 | adduser openhab uucp 68 | adduser openhab uucp2 69 | 70 | chown root:uucp /var/lock 71 | chmod g+w /var/lock 72 | fi 73 | 74 | initialize_volume() { 75 | volume="$1" 76 | source="$2" 77 | 78 | if [ -z "$(ls -A "$volume")" ]; then 79 | echo "Initializing empty volume ${volume} ..." 80 | cp -av "${source}/." "${volume}/" 81 | fi 82 | } 83 | 84 | # Initialize empty volumes and update userdata 85 | initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" 86 | initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" 87 | 88 | # Update userdata if versions do not match 89 | if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then 90 | echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" 91 | 92 | # Make a backup of userdata 93 | backup_file=userdata-$(date +"%FT%H-%M-%S").tar 94 | if [ ! -d "${OPENHAB_BACKUPS}" ]; then 95 | mkdir "${OPENHAB_BACKUPS}" 96 | fi 97 | tar -c -f "${OPENHAB_BACKUPS}/${backup_file}" --exclude "backup/*" "${OPENHAB_USERDATA}" 98 | echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" 99 | 100 | exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" 101 | fi 102 | 103 | # Set openhab folder permission 104 | chown -R openhab:openhab "${OPENHAB_HOME}" 105 | sync 106 | 107 | # Run s6-style init continuation scripts if dir exists and s6 is not installed 108 | if [ -d /etc/cont-init.d ] && [ $(ls /bin/s6-* 2>/dev/null | wc -l) == 0 ]; then 109 | for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort); do 110 | . "${script}" 111 | done 112 | fi 113 | 114 | # sync again after continuation scripts have been run 115 | sync 116 | 117 | # Use server mode with the default command when there is no pseudo-TTY 118 | if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "su-exec openhab tini -s ./start.sh" ]; then 119 | command=($@ server) 120 | exec "${command[@]}" 121 | else 122 | exec "$@" 123 | fi 124 | -------------------------------------------------------------------------------- /alpine/update: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | setup() { 4 | # Ask to run as root to prevent us from running sudo in this script. 5 | if [ "$(id -u)" -ne 0 ]; then 6 | echo "Please run this script as root! (e.g. use sudo)" >&2 7 | exit 1 8 | fi 9 | 10 | current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" 11 | oh_version="$(awk '/openhab-distro/{print $3}' "/openhab/dist/userdata/etc/version.properties")" 12 | milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" 13 | 14 | # Download snapshots from Jenkins and download milestones and releases using openHAB redirect. 15 | if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then 16 | addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" 17 | elif [ "${oh_version}" = "$current_version" ]; then 18 | echo "You are already on openHAB $current_version" >&2 19 | exit 1 20 | elif [ -n "$milestone_version" ]; then 21 | addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" 22 | else 23 | addons_download_location="https://openhab.jfrog.io/openhab/libs-release/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" 24 | fi 25 | } 26 | 27 | run_command() { 28 | string="$1" 29 | string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" 30 | string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" 31 | string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" 32 | 33 | command="$(echo "$string" | awk -F';' '{print $1}')" 34 | param1="$(echo "$string" | awk -F';' '{print $2}')" 35 | param2="$(echo "$string" | awk -F';' '{print $3}')" 36 | param3="$(echo "$string" | awk -F';' '{print $4}')" 37 | 38 | case $command in 39 | 'DEFAULT') 40 | if [ -f "$param1" ]; then 41 | echo " Adding '.bak' to $param1" 42 | mv "$param1" "$param1.bak" 43 | fi 44 | echo " Using default file $param1" 45 | cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" 46 | ;; 47 | 'DELETE') 48 | # We should be strict and specific here, i.e only delete one file. 49 | if [ -f "$param1" ]; then 50 | echo " Deleting File: $param1" 51 | rm -f "$param1" 52 | fi 53 | ;; 54 | 'DELETEDIR') 55 | # We should be strict and specific here, i.e only delete one directory. 56 | if [ -d "$param1" ]; then 57 | echo " Deleting Directory: $param1" 58 | rm -rf "$param1" 59 | fi 60 | ;; 61 | 'MOVE') 62 | # Avoid error if file or directory does not exist 63 | if [ -e "$param1" ]; then 64 | echo " Moving: From $param1 to $param2" 65 | file_dir=$(dirname "$param2") 66 | # Create directory with same ownership as file 67 | if [ ! -d file_dir ]; then 68 | mkdir -p "$file_dir" 69 | prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') 70 | chown -R "$prev_user_group" "$file_dir" 71 | fi 72 | mv "$param1" "$param2" 73 | fi 74 | ;; 75 | 'REPLACE') 76 | # Avoid error if file does not exist 77 | if [ -f "$param3" ]; then 78 | echo " Replacing: String $param1 to $param2 in file $param3" 79 | sed -i "s:$param1:$param2:g" "$param3" 80 | fi 81 | ;; 82 | 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; 83 | 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; 84 | esac 85 | } 86 | 87 | get_version_number() { 88 | first_part="$(echo "$1" | awk -F'.' '{print $1}')" 89 | second_part="$(echo "$1" | awk -F'.' '{print $2}')" 90 | third_part="$(echo "$1" | awk -F'.' '{print $3}')" 91 | third_part="${third_part%%-*}" 92 | echo $((first_part*10000+second_part*100+third_part)) 93 | } 94 | 95 | scan_versioning_list() { 96 | section="$1" 97 | version_message="$2" 98 | in_section=false 99 | in_new_version=false 100 | 101 | # Read the file line by line. 102 | while IFS= read -r line 103 | do 104 | case $line in 105 | '') 106 | continue 107 | ;; 108 | # Flag to run the relevant [[section]] only. 109 | "[[$section]]") 110 | in_section=true 111 | ;; 112 | # Stop reading the file if another [[section]] starts. 113 | "[["*"]]") 114 | if $in_section; then 115 | break 116 | fi 117 | ;; 118 | # Detect the [version] and execute the line if relevant. 119 | '['*'.'*'.'*']') 120 | if $in_section; then 121 | line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" 122 | line_version_number=$(get_version_number "$line_version") 123 | if [ "$current_version_number" -lt "$line_version_number" ]; then 124 | in_new_version=true 125 | echo "" 126 | echo "$version_message $line_version:" 127 | else 128 | in_new_version=false 129 | fi 130 | fi 131 | ;; 132 | *) 133 | if $in_section && $in_new_version; then 134 | run_command "$line" 135 | fi 136 | ;; 137 | esac 138 | done < "${OPENHAB_HOME}/runtime/bin/update.lst" 139 | } 140 | 141 | echo "" 142 | echo "################################################" 143 | echo " openHAB Docker update script " 144 | echo "################################################" 145 | echo "" 146 | 147 | # Run the initialisation functions defined above 148 | setup 149 | 150 | current_version_number=$(get_version_number "$current_version") 151 | case $current_version in 152 | *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; 153 | esac 154 | 155 | # Notify the user of important changes first 156 | echo "The script will attempt to update openHAB to version ${oh_version}" 157 | printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' 158 | scan_versioning_list "MSG" "Important notes for version" 159 | echo "" 160 | 161 | # Perform version specific pre-update commands 162 | scan_versioning_list "PRE" "Performing pre-update tasks for version" 163 | 164 | echo "Replacing userdata system files with newer versions..." 165 | while IFS= read -r file_name 166 | do 167 | full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" 168 | if [ -f "$full_path" ]; then 169 | cp "$full_path" "${OPENHAB_USERDATA}/etc/" 170 | fi 171 | done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" 172 | 173 | # Clearing the cache, marketplace and tmp folders is necessary for upgrade. 174 | echo "Clearing cache..." 175 | rm -rf "${OPENHAB_USERDATA:?}/cache" 176 | if [ $(get_version_number "${oh_version}") -ge $(get_version_number "4.2.0") ]; then 177 | rm -rf "${OPENHAB_USERDATA:?}/marketplace" 178 | fi 179 | rm -rf "${OPENHAB_USERDATA:?}/tmp" 180 | 181 | # Perform version specific post-update commands 182 | scan_versioning_list "POST" "Performing post-update tasks for version" 183 | 184 | # If there's an existing addons file, we need to replace it with the correct version. 185 | addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" 186 | if [ -f "$addons_file" ]; then 187 | echo "Found an openHAB addons file, replacing with new version..." 188 | rm -f "${addons_file:?}" 189 | curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { 190 | echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 191 | } 192 | fi 193 | echo "" 194 | 195 | # Start the upgrade tool 196 | if [ -f "${OPENHAB_HOME}/runtime/bin/upgradetool.jar" ]; then 197 | echo "Starting JSON database update..." 198 | java -jar "${OPENHAB_HOME}/runtime/bin/upgradetool.jar" || { 199 | echo "Update tool failed, please check the openHAB website (www.openhab.org) for manual update instructions." >&2 200 | exit 1 201 | } 202 | echo "JSON database updated successfully." 203 | echo "" 204 | fi 205 | 206 | echo "" 207 | echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" 208 | echo "" 209 | -------------------------------------------------------------------------------- /build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eo pipefail 3 | 4 | source helper-functions 5 | 6 | filter_options() { 7 | local options="$1" 8 | local valid_options="$2" 9 | local fallback="$3" 10 | 11 | local filtered=() 12 | for valid_option in $valid_options; do 13 | for option in $options; do 14 | if [ "$option" == "$valid_option" ]; then 15 | filtered+=("$option") 16 | fi 17 | done 18 | done 19 | 20 | local result="$(IFS=' '; echo "${filtered[*]}")" 21 | if [ "$result" == "" ]; then 22 | echo "$fallback" 23 | else 24 | echo "$result" 25 | fi 26 | } 27 | 28 | resolve_version_tags() { 29 | local latest_version=$(last_stable_version) 30 | local milestone_version="$(last_milestone_version)" 31 | if [ "$milestone_version" == "" ]; then 32 | milestone_version="$(last_stable_version)" 33 | fi 34 | local snapshot_version=$(last_snapshot_version) 35 | 36 | local results=() 37 | for s in $@; do 38 | local result="$s" 39 | if [ "$result" == "latest" ]; then 40 | result="$latest_version" 41 | elif [ "$result" == "milestone" ]; then 42 | result="$milestone_version" 43 | elif [ "$result" == "snapshot" ]; then 44 | result="$snapshot_version" 45 | fi 46 | results+=("$result") 47 | done 48 | 49 | echo "$(IFS=' '; echo "${results[*]}")" 50 | } 51 | 52 | print_help() { 53 | local snapshot_5x=$(grep -E '^5\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS | tail -n 1) 54 | local milestone_4x=$(grep -E '^4\.[0-9]+\.[0-9]+.(M[0-9]+)$' <<< $VERSIONS | tail -n 1) 55 | local stable_42x=$(grep -E '^4\.2\.[0-9]+$' <<< $VERSIONS | tail -n 1) 56 | local stable_43x=$(grep -E '^4\.3\.[0-9]+$' <<< $VERSIONS | tail -n 1) 57 | 58 | cat <<-EOI 59 | Usage: ./build [OPTIONS] 60 | 61 | Builds openHAB Docker images using BuildKit. 62 | 63 | When no options are provided the latest snapshot images are build for all Docker platforms. 64 | To build other versions or only the images of a specific base image add these to the options. 65 | To push the images to the Docker registry ($(docker_repo)) add --push 66 | Log in to the Docker Registry with "docker login" before building and pushing the images. 67 | 68 | Examples: 69 | 70 | Build the Debian and Alpine $snapshot_5x images: 71 | ./build 72 | 73 | Build the Debian $snapshot_5x images: 74 | ./build debian 75 | 76 | Build the Alpine $milestone_4x images: 77 | ./build $milestone_4x alpine 78 | 79 | Build the $stable_43x and $stable_42x Debian/Alpine images and push them to $(docker_repo): 80 | ./build $stable_43x $stable_42x --push 81 | 82 | Build the latest/snapshot Debian images by resolving the versions ("milestone" can also be resolved): 83 | ./build latest snapshot debian 84 | 85 | EOI 86 | } 87 | 88 | main() { 89 | local versions=$(filter_options "$(resolve_version_tags "${*/-SNAPSHOT/-snapshot}")" "$VERSIONS" "$(last_snapshot_version)") 90 | local bases=$(filter_options "$*" "$(bases)" "$(bases)") 91 | local push=$(filter_options "$*" "--push" "") 92 | 93 | for version in $versions; do 94 | for base in $bases; do 95 | build $version $base $push 96 | done 97 | done 98 | } 99 | 100 | if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then 101 | print_help 102 | else 103 | main "$@" 104 | fi 105 | -------------------------------------------------------------------------------- /contrib/cont-init.d/10-show-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | ls -l "${OPENHAB_HOME}" 4 | ls -l "${OPENHAB_USERDATA}" 5 | -------------------------------------------------------------------------------- /contrib/cont-init.d/20-add-allowed-ssh-keys: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | cat > "${OPENHAB_USERDATA}/etc/keys.properties" < "${OPENHAB_USERDATA}/etc/host.key" < "${OPENHAB_USERDATA}/uuid" 7 | fi 8 | 9 | if [ ! -z ${OHC_SECRET} ] 10 | then 11 | mkdir -p "${OPENHAB_USERDATA}/openhabcloud" 12 | echo ${OHC_SECRET} > "${OPENHAB_USERDATA}/openhabcloud/secret" 13 | fi 14 | -------------------------------------------------------------------------------- /contrib/cont-init.d/50-setpcap-on-java: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | setcap 'cap_net_bind_service=+ep' "${JAVA_HOME}/bin/java" 4 | -------------------------------------------------------------------------------- /contrib/cont-init.d/60-socat-serial-network: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # https://community.openhab.org/t/cant-use-forwarded-socat-serial-port-in-lgtvserial-binding-ioexception/97965 3 | # https://community.openhab.org/t/forwarding-of-serial-and-usb-ports-over-the-network-to-openhab/46597 4 | apt-get update 5 | apt-get install socat -y -q 6 | 7 | # use while loop to restart socat on connection end 8 | while /bin/true; do 9 | socat -d -d -s -lf /openhab/userdata/logs/socat.log pty,link=/dev/ttyNET0,raw,user=openhab,group=openhab,mode=777 tcp:192.168.188.17:20108,forever,intervall=10 10 | sleep 1 11 | done &> /dev/null & 12 | -------------------------------------------------------------------------------- /debian/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:12-slim 2 | 3 | ARG BUILD_DATE 4 | ARG VCS_REF 5 | ARG JAVA_VERSION 6 | ARG OPENHAB_VERSION 7 | 8 | ENV \ 9 | CRYPTO_POLICY="limited" \ 10 | EXTRA_JAVA_OPTS="" \ 11 | EXTRA_SHELL_OPTS="" \ 12 | GROUP_ID="9001" \ 13 | KARAF_EXEC="exec" \ 14 | LC_ALL="en_US.UTF-8" \ 15 | LANG="en_US.UTF-8" \ 16 | LANGUAGE="en_US.UTF-8" \ 17 | OPENHAB_BACKUPS="/openhab/userdata/backup" \ 18 | OPENHAB_CONF="/openhab/conf" \ 19 | OPENHAB_HOME="/openhab" \ 20 | OPENHAB_HTTP_PORT="8080" \ 21 | OPENHAB_HTTPS_PORT="8443" \ 22 | OPENHAB_LOGDIR="/openhab/userdata/logs" \ 23 | OPENHAB_USERDATA="/openhab/userdata" \ 24 | USER_ID="9001" 25 | 26 | # Basic build-time metadata as defined at https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys 27 | LABEL org.opencontainers.image.created=$BUILD_DATE \ 28 | org.opencontainers.image.licenses="EPL-2.0" \ 29 | org.opencontainers.image.title="openHAB" \ 30 | org.opencontainers.image.vendor="openHAB Foundation e.V." \ 31 | org.opencontainers.image.version=$OPENHAB_VERSION \ 32 | org.opencontainers.image.description="An open source, technology agnostic home automation platform" \ 33 | org.opencontainers.image.url="https://www.openhab.org/" \ 34 | org.opencontainers.image.documentation="https://www.openhab.org/docs/installation/docker.html" \ 35 | org.opencontainers.image.revision=$VCS_REF \ 36 | org.opencontainers.image.source="https://github.com/openhab/openhab-docker.git" \ 37 | org.opencontainers.image.authors="openHAB " 38 | 39 | # https://github.com/hadolint/hadolint/wiki/DL4006 40 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] 41 | 42 | # Install basepackages. Versions are "pinned" by using a pinned base image. 43 | # hadolint ignore=DL3008 44 | RUN apt-get update && \ 45 | apt-get upgrade --yes && \ 46 | openjdk_package="openjdk-${JAVA_VERSION}-jre-headless" && \ 47 | apt-get install --no-install-recommends -y --dry-run "$openjdk_package" >/dev/null || openjdk_package="temurin-${JAVA_VERSION}-jre" && \ 48 | if [ $(echo "$openjdk_package" | grep -E '^temurin-.+$') ]; then \ 49 | DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y wget ca-certificates && \ 50 | wget -nv -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /usr/share/keyrings/adoptium.asc && \ 51 | echo "deb [signed-by=/usr/share/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list && \ 52 | apt-get update; \ 53 | fi && \ 54 | DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ 55 | arping \ 56 | ca-certificates \ 57 | curl \ 58 | fontconfig \ 59 | gosu \ 60 | iputils-ping \ 61 | libcap2-bin \ 62 | locales \ 63 | locales-all \ 64 | netbase \ 65 | "$openjdk_package" \ 66 | procps \ 67 | tini \ 68 | unzip \ 69 | wget \ 70 | zip && \ 71 | # Install NodeJS only for openHAB >= 5 72 | if [ "$(echo $OPENHAB_VERSION | sed -E 's/^([0-9]+).*/\1/')" -ge 5 ]; then DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y nodejs; fi && \ 73 | c_rehash && \ 74 | chmod u+s /usr/sbin/arping && \ 75 | ln -s -f /bin/true /usr/bin/chfn && \ 76 | apt-get clean && \ 77 | rm -rf /var/lib/apt/lists/* 78 | 79 | # Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography 80 | RUN JAVA_HOME=$(find /usr/lib/jvm -mindepth 1 -maxdepth 1 -type d) && \ 81 | sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security" 82 | 83 | # Install openHAB 84 | # Set permissions for openHAB. Export TERM variable. See issue #30 for details! 85 | # Single quotes are used on purpose, so $TERM is expanded when running the container. 86 | # hadolint ignore=SC2016 87 | RUN version="$(echo $OPENHAB_VERSION | sed 's/snapshot/SNAPSHOT/g')" && \ 88 | if [ $(echo $version | grep -E '^.+\.(M|RC).+$') ]; then url="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab/${version}/openhab-${version}.zip"; \ 89 | elif [ $(echo $version | grep -E '^5\..+-SNAPSHOT$') ]; then url="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip"; \ 90 | else url="https://openhab.jfrog.io/openhab/libs-release/org/openhab/distro/openhab/${version}/openhab-${version}.zip"; fi && \ 91 | wget -nv -O /tmp/openhab.zip "$url" && \ 92 | unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ 93 | rm /tmp/openhab.zip && \ 94 | mkdir -p "${OPENHAB_LOGDIR}" && \ 95 | touch "${OPENHAB_LOGDIR}/openhab.log" && \ 96 | mkdir -p "${OPENHAB_HOME}/dist" && \ 97 | cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ 98 | echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc 99 | COPY update ${OPENHAB_HOME}/runtime/bin/update 100 | RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update 101 | 102 | # Expose volume with configuration and userdata dir 103 | VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons 104 | 105 | # Expose HTTP, HTTPS, Console and LSP ports 106 | EXPOSE 8080 8443 8101 5007 107 | 108 | # Set healthcheck 109 | HEALTHCHECK --interval=5m --timeout=5s --retries=3 CMD curl -f http://localhost:${OPENHAB_HTTP_PORT}/ || exit 1 110 | 111 | # Set working directory and entrypoint 112 | WORKDIR ${OPENHAB_HOME} 113 | COPY entrypoint /entrypoint 114 | RUN chmod +x /entrypoint 115 | ENTRYPOINT ["/entrypoint"] 116 | 117 | # Execute command 118 | CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] 119 | -------------------------------------------------------------------------------- /debian/entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | interactive=$(if test -t 0; then echo true; else echo false; fi) 4 | set -eux -o pipefail ${EXTRA_SHELL_OPTS-} 5 | IFS=$'\n\t' 6 | 7 | export JAVA_HOME=$(find /usr/lib/jvm -mindepth 1 -maxdepth 1 -type d) 8 | 9 | # Configure Java unlimited strength cryptography 10 | if [ "${CRYPTO_POLICY}" = "unlimited" ]; then 11 | echo "Configuring Java unlimited strength cryptography policy..." 12 | sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${JAVA_HOME}/conf/security/java.security" 13 | fi 14 | 15 | # Set capabilities when available for add-ons using Pcap4J 16 | if capsh --print | grep -E 'Current:.+,cap_net_admin,cap_net_raw,.+' >/dev/null; then 17 | setcap cap_net_raw,cap_net_admin=eip "${JAVA_HOME}/bin/java" 18 | fi 19 | 20 | # Delete stale nrjavaserial lock files and Karaf instance.properties to avoid PID conflicts on restarts 21 | rm -f /var/lock/LCK..* 22 | rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" 23 | 24 | # Add openhab user and add user to groups for different host distros 25 | # Alpine: audio=18, dialout=20, uucp=14 26 | # CentOS/RedHat: audio=63, dialout=18, uucp=14 27 | # Debian/Ubuntu: audio=29, dialout=20, uucp=10 28 | # Linux from Scratch: audio=11, dialout=10, uucp=32 29 | # openSUSE (old): audio=17, dialout=16, uucp=14 30 | # openSUSE (new): audio=492, dialout=490 31 | # Raspberry Pi OS: audio=29, dialout=20, uucp=10, gpio=997 32 | NEW_USER_ID=${USER_ID:-9001} 33 | NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} 34 | echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" 35 | if ! id -u openhab >/dev/null 2>&1; then 36 | if [ -z "$(getent group $NEW_GROUP_ID)" ]; then 37 | echo "Create group openhab with id ${NEW_GROUP_ID}" 38 | groupadd -g $NEW_GROUP_ID openhab 39 | else 40 | group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) 41 | echo "Rename group $group_name to openhab" 42 | groupmod --new-name openhab $group_name 43 | fi 44 | echo "Create user openhab with id ${NEW_USER_ID}" 45 | adduser -u $NEW_USER_ID --disabled-password --gecos '' --home "${OPENHAB_HOME}" --gid $NEW_GROUP_ID openhab 46 | groupadd -g 11 audio2 47 | groupadd -g 14 uucp2 48 | groupadd -g 16 dialout2 49 | groupadd -g 17 audio3 50 | groupadd -g 18 dialout3 51 | groupadd -g 32 uucp3 52 | groupadd -g 63 audio4 53 | groupadd -g 490 dialout4 54 | groupadd -g 492 audio5 55 | groupadd -g 997 gpio 56 | adduser openhab audio 57 | adduser openhab audio2 58 | adduser openhab audio3 59 | adduser openhab audio4 60 | adduser openhab audio5 61 | adduser openhab dialout 62 | adduser openhab dialout2 63 | adduser openhab dialout3 64 | adduser openhab dialout4 65 | adduser openhab gpio 66 | adduser openhab uucp 67 | adduser openhab uucp2 68 | adduser openhab uucp3 69 | fi 70 | 71 | initialize_volume() { 72 | volume="$1" 73 | source="$2" 74 | 75 | if [ -z "$(ls -A "$volume")" ]; then 76 | echo "Initializing empty volume ${volume} ..." 77 | cp -av "${source}/." "${volume}/" 78 | fi 79 | } 80 | 81 | # Initialize empty volumes and update userdata 82 | initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" 83 | initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" 84 | 85 | # Update userdata if versions do not match 86 | if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then 87 | echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" 88 | 89 | # Make a backup of userdata 90 | backup_file=userdata-$(date +"%FT%H-%M-%S").tar 91 | if [ ! -d "${OPENHAB_BACKUPS}" ]; then 92 | mkdir "${OPENHAB_BACKUPS}" 93 | fi 94 | tar --exclude="${OPENHAB_BACKUPS}" -c -f "${OPENHAB_BACKUPS}/${backup_file}" "${OPENHAB_USERDATA}" 95 | echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" 96 | 97 | exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" 98 | fi 99 | 100 | # Set openhab folder permission 101 | chown -R openhab:openhab "${OPENHAB_HOME}" 102 | sync 103 | 104 | # Run s6-style init continuation scripts if dir exists and s6 is not installed 105 | if [ -d /etc/cont-init.d ] && [ $(ls /usr/bin/s6-* 2>/dev/null | wc -l) == 0 ]; then 106 | for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort); do 107 | . "${script}" 108 | done 109 | fi 110 | 111 | # sync again after continuation scripts have been run 112 | sync 113 | 114 | # Use server mode with the default command when there is no pseudo-TTY 115 | if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "gosu openhab tini -s ./start.sh" ]; then 116 | command=($@ server) 117 | exec "${command[@]}" 118 | else 119 | exec "$@" 120 | fi 121 | -------------------------------------------------------------------------------- /debian/update: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | setup() { 4 | # Ask to run as root to prevent us from running sudo in this script. 5 | if [ "$(id -u)" -ne 0 ]; then 6 | echo "Please run this script as root! (e.g. use sudo)" >&2 7 | exit 1 8 | fi 9 | 10 | current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" 11 | oh_version="$(awk '/openhab-distro/{print $3}' "/openhab/dist/userdata/etc/version.properties")" 12 | milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" 13 | 14 | # Download snapshots from Jenkins and download milestones and releases using openHAB redirect. 15 | if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then 16 | addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" 17 | elif [ "${oh_version}" = "$current_version" ]; then 18 | echo "You are already on openHAB $current_version" >&2 19 | exit 1 20 | elif [ -n "$milestone_version" ]; then 21 | addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" 22 | else 23 | addons_download_location="https://openhab.jfrog.io/openhab/libs-release/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" 24 | fi 25 | } 26 | 27 | run_command() { 28 | string="$1" 29 | string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" 30 | string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" 31 | string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" 32 | 33 | command="$(echo "$string" | awk -F';' '{print $1}')" 34 | param1="$(echo "$string" | awk -F';' '{print $2}')" 35 | param2="$(echo "$string" | awk -F';' '{print $3}')" 36 | param3="$(echo "$string" | awk -F';' '{print $4}')" 37 | 38 | case $command in 39 | 'DEFAULT') 40 | if [ -f "$param1" ]; then 41 | echo " Adding '.bak' to $param1" 42 | mv "$param1" "$param1.bak" 43 | fi 44 | echo " Using default file $param1" 45 | cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" 46 | ;; 47 | 'DELETE') 48 | # We should be strict and specific here, i.e only delete one file. 49 | if [ -f "$param1" ]; then 50 | echo " Deleting File: $param1" 51 | rm -f "$param1" 52 | fi 53 | ;; 54 | 'DELETEDIR') 55 | # We should be strict and specific here, i.e only delete one directory. 56 | if [ -d "$param1" ]; then 57 | echo " Deleting Directory: $param1" 58 | rm -rf "$param1" 59 | fi 60 | ;; 61 | 'MOVE') 62 | # Avoid error if file or directory does not exist 63 | if [ -e "$param1" ]; then 64 | echo " Moving: From $param1 to $param2" 65 | file_dir=$(dirname "$param2") 66 | # Create directory with same ownership as file 67 | if [ ! -d file_dir ]; then 68 | mkdir -p "$file_dir" 69 | prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') 70 | chown -R "$prev_user_group" "$file_dir" 71 | fi 72 | mv "$param1" "$param2" 73 | fi 74 | ;; 75 | 'REPLACE') 76 | # Avoid error if file does not exist 77 | if [ -f "$param3" ]; then 78 | echo " Replacing: String $param1 to $param2 in file $param3" 79 | sed -i "s:$param1:$param2:g" "$param3" 80 | fi 81 | ;; 82 | 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; 83 | 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; 84 | esac 85 | } 86 | 87 | get_version_number() { 88 | first_part="$(echo "$1" | awk -F'.' '{print $1}')" 89 | second_part="$(echo "$1" | awk -F'.' '{print $2}')" 90 | third_part="$(echo "$1" | awk -F'.' '{print $3}')" 91 | third_part="${third_part%%-*}" 92 | echo $((first_part*10000+second_part*100+third_part)) 93 | } 94 | 95 | scan_versioning_list() { 96 | section="$1" 97 | version_message="$2" 98 | in_section=false 99 | in_new_version=false 100 | 101 | # Read the file line by line. 102 | while IFS= read -r line 103 | do 104 | case $line in 105 | '') 106 | continue 107 | ;; 108 | # Flag to run the relevant [[section]] only. 109 | "[[$section]]") 110 | in_section=true 111 | ;; 112 | # Stop reading the file if another [[section]] starts. 113 | "[["*"]]") 114 | if $in_section; then 115 | break 116 | fi 117 | ;; 118 | # Detect the [version] and execute the line if relevant. 119 | '['*'.'*'.'*']') 120 | if $in_section; then 121 | line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" 122 | line_version_number=$(get_version_number "$line_version") 123 | if [ "$current_version_number" -lt "$line_version_number" ]; then 124 | in_new_version=true 125 | echo "" 126 | echo "$version_message $line_version:" 127 | else 128 | in_new_version=false 129 | fi 130 | fi 131 | ;; 132 | *) 133 | if $in_section && $in_new_version; then 134 | run_command "$line" 135 | fi 136 | ;; 137 | esac 138 | done < "${OPENHAB_HOME}/runtime/bin/update.lst" 139 | } 140 | 141 | echo "" 142 | echo "################################################" 143 | echo " openHAB Docker update script " 144 | echo "################################################" 145 | echo "" 146 | 147 | # Run the initialisation functions defined above 148 | setup 149 | 150 | current_version_number=$(get_version_number "$current_version") 151 | case $current_version in 152 | *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; 153 | esac 154 | 155 | # Notify the user of important changes first 156 | echo "The script will attempt to update openHAB to version ${oh_version}" 157 | printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' 158 | scan_versioning_list "MSG" "Important notes for version" 159 | echo "" 160 | 161 | # Perform version specific pre-update commands 162 | scan_versioning_list "PRE" "Performing pre-update tasks for version" 163 | 164 | echo "Replacing userdata system files with newer versions..." 165 | while IFS= read -r file_name 166 | do 167 | full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" 168 | if [ -f "$full_path" ]; then 169 | cp "$full_path" "${OPENHAB_USERDATA}/etc/" 170 | fi 171 | done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" 172 | 173 | # Clearing the cache, marketplace and tmp folders is necessary for upgrade. 174 | echo "Clearing cache..." 175 | rm -rf "${OPENHAB_USERDATA:?}/cache" 176 | if [ $(get_version_number "${oh_version}") -ge $(get_version_number "4.2.0") ]; then 177 | rm -rf "${OPENHAB_USERDATA:?}/marketplace" 178 | fi 179 | rm -rf "${OPENHAB_USERDATA:?}/tmp" 180 | 181 | # Perform version specific post-update commands 182 | scan_versioning_list "POST" "Performing post-update tasks for version" 183 | 184 | # If there's an existing addons file, we need to replace it with the correct version. 185 | addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" 186 | if [ -f "$addons_file" ]; then 187 | echo "Found an openHAB addons file, replacing with new version..." 188 | rm -f "${addons_file:?}" 189 | curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { 190 | echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 191 | } 192 | fi 193 | echo "" 194 | 195 | # Start the upgrade tool 196 | if [ -f "${OPENHAB_HOME}/runtime/bin/upgradetool.jar" ]; then 197 | echo "Starting JSON database update..." 198 | java -jar "${OPENHAB_HOME}/runtime/bin/upgradetool.jar" || { 199 | echo "Update tool failed, please check the openHAB website (www.openhab.org) for manual update instructions." >&2 200 | exit 1 201 | } 202 | echo "JSON database updated successfully." 203 | echo "" 204 | fi 205 | 206 | echo "" 207 | echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" 208 | echo "" 209 | -------------------------------------------------------------------------------- /helper-functions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eo pipefail 3 | 4 | BUILDER="" 5 | DISTRO_REPO="${DISTRO_REPO:=openhab/openhab-distro}" 6 | VERSIONS="" 7 | 8 | get_released_versions_from_tags() { 9 | git ls-remote --refs --tags "https://github.com/${DISTRO_REPO}.git" | grep -E '.+/tags/[0-9]+\.[0-9]+\.[0-9]+(\.(M|RC)[0-9]+)?$' | sed -E 's#.+/tags/(.+)#\1#g' || echo "" 10 | } 11 | 12 | get_snapshot_versions_from_poms() { 13 | local branch_names="$(git ls-remote --refs --heads "https://github.com/${DISTRO_REPO}.git" | grep -E '.+/heads/(main)$' | sed -E 's#.+/heads/(.+)#\1#g')" 14 | for branch_name in $branch_names; do 15 | curl -sS "https://raw.githubusercontent.com/${DISTRO_REPO}/${branch_name}/pom.xml" | grep -E '^ ' | grep 'SNAPSHOT' | sed -E 's#.+(.+)-SNAPSHOT#\1-snapshot#g' || echo "" 16 | done 17 | } 18 | 19 | get_versions() { 20 | (get_released_versions_from_tags && get_snapshot_versions_from_poms) | sort --unique --version-sort 21 | } 22 | 23 | VERSIONS=$(get_versions) 24 | 25 | # Supported base images 26 | bases() { 27 | echo "debian alpine" 28 | } 29 | 30 | docker_repo() { 31 | echo "${DOCKER_REPO:=openhab/openhab}" 32 | } 33 | 34 | # Supported Docker platforms 35 | platforms() { 36 | local version="$1" 37 | local base="$2" 38 | 39 | if [[ "$version" =~ ^4.*$ ]] && [ "$base" == "debian" ]; then 40 | echo "linux/amd64,linux/arm64,linux/arm/v7" 41 | else 42 | # There are no linux/arm/v7 images for openHAB 5 (or newer) because this platform is no longer supported. 43 | # There are no linux/arm/v7 Alpine images for openHAB 3 (or newer) because the required openjdk package is unavailable for this platform. 44 | echo "linux/amd64,linux/arm64" 45 | fi 46 | } 47 | 48 | tags() { 49 | local version="$1" 50 | local base="$2" 51 | 52 | local tags=() 53 | 54 | if [ "$base" == "debian" ]; then 55 | tags+=("$(docker_repo):$version") 56 | fi 57 | 58 | tags+=("$(docker_repo):$version-$base") 59 | 60 | if [ "$version" == "$(last_stable_version)" ]; then 61 | if [ "$base" == "debian" ]; then 62 | tags+=("$(docker_repo):latest") 63 | fi 64 | tags+=("$(docker_repo):latest-$base") 65 | fi 66 | 67 | milestone_maturity_version="$(last_milestone_version)" 68 | if [ "$milestone_maturity_version" == "" ]; then 69 | milestone_maturity_version="$(last_stable_version)" 70 | fi 71 | 72 | if [ "$version" == "$milestone_maturity_version" ]; then 73 | if [ "$base" == "debian" ]; then 74 | tags+=("$(docker_repo):milestone") 75 | fi 76 | tags+=("$(docker_repo):milestone-$base") 77 | fi 78 | 79 | if [ "$version" == "$(last_snapshot_version)" ]; then 80 | if [ "$base" == "debian" ]; then 81 | tags+=("$(docker_repo):snapshot") 82 | fi 83 | tags+=("$(docker_repo):snapshot-$base") 84 | fi 85 | 86 | echo $(IFS=' '; echo "${tags[*]}") 87 | } 88 | 89 | last_stable_version() { 90 | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' <<< $VERSIONS | tail -n 1 91 | } 92 | 93 | stable_versions() { 94 | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' <<< $VERSIONS 95 | } 96 | 97 | last_stable_minor_versions() { 98 | local minor_versions=$(grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' <<< $VERSIONS | sed -E 's/^([0-9]+\.[0-9]+).+/\1/' | sort --unique --version-sort) 99 | for minor_version in $minor_versions; do 100 | stable_versions | grep -E "^$minor_version" | tail -n 1 101 | done 102 | } 103 | 104 | snapshot_versions() { 105 | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS || echo "" 106 | } 107 | 108 | last_snapshot_version() { 109 | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS | tail -n 1 || echo "" 110 | } 111 | 112 | next_stable_version() { 113 | sed 's/-snapshot//' <<< $(last_snapshot_version) 114 | } 115 | 116 | milestone_versions() { 117 | grep -E "$(next_stable_version)\.(M|RC)[0-9]+$" <<< $VERSIONS | tail -n 3 || echo "" 118 | } 119 | 120 | last_milestone_version() { 121 | grep -E "$(next_stable_version)\.(M|RC)[0-9]+$" <<< $VERSIONS | tail -n 1 || echo "" 122 | } 123 | 124 | generate_readme_versions() { 125 | local text="$1" 126 | local versions="$(echo "$2" | sort --reverse --version-sort | head -n 2)" 127 | 128 | if [ "$versions" != "" ]; then 129 | echo "* $text" 130 | for version in $versions; do 131 | case $version in 132 | *-snapshot) echo " * \`$version\`";; 133 | *) echo " * \`$version\` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/$version))";; 134 | esac 135 | done 136 | fi 137 | } 138 | 139 | update_readme() { 140 | local file=README.md 141 | 142 | if [ "$(last_stable_version)" == "" ]; then 143 | echo "Cannot update $file because the last stable version is unknown!" 144 | exit 1 145 | fi 146 | 147 | local generate="false" 148 | while IFS= read -r line 149 | do 150 | if [[ $line =~ ^\*\ \*\*Stable:\*\*.+$ ]]; then 151 | generate="true" 152 | else 153 | if [ "$generate" == "true" ]; then 154 | if [ "$line" == "" ]; then 155 | generate="false" 156 | 157 | generate_readme_versions \ 158 | '**Stable:** Thoroughly tested semi-annual official releases of openHAB. Use the stable version for your production environment if you do not need the latest enhancements and prefer a robust system.' \ 159 | "$(last_stable_minor_versions)" 160 | generate_readme_versions \ 161 | '**Milestone:** Intermediary releases of the next openHAB version which are released about once a month. They include recently added features and bugfixes and are a good compromise between the current stable version and the bleeding-edge and potentially unstable snapshot version.' \ 162 | "$(milestone_versions)" 163 | generate_readme_versions \ 164 | '**Snapshot:** Usually 1 or 2 days old and include the latest code. Use these for testing out very recent changes using the latest code. Be aware that some snapshots might be unstable so use these in production at your own risk!' \ 165 | "$(snapshot_versions)" 166 | echo 167 | fi 168 | else 169 | echo "$line" 170 | fi 171 | fi 172 | done < $file > $file.new && mv $file.new $file 173 | 174 | sed -i "s#version-[0-9]*\.[0-9]*\.[0-9]*-blue#version-$(last_stable_version)-blue#g" $file 175 | sed -i "s#openhab/tags?name=[0-9]*\.[0-9]*\.[0-9]*#openhab/tags?name=$(last_stable_version)#g" $file 176 | sed -i "s#openhab/openhab:[0-9]*\.[0-9]*\.[0-9]*#openhab/openhab:$(last_stable_version)#g" $file 177 | sed -i "s#OPENHAB_VERSION=[0-9]*\.[0-9]*\.[0-9]*#OPENHAB_VERSION=$(last_stable_version)#g" $file 178 | } 179 | 180 | validate_readme_constraints() { 181 | local count=$(wc -m &2 184 | exit 1 185 | else 186 | echo "README.md contains $count characters which is below the 25000 character limit of Docker Hub" 187 | fi 188 | } 189 | 190 | update_dockerhub_readme() { 191 | if [ "$(docker info 2>&1 | grep 'pushrm: Push Readme to container registry' | wc -l)" -eq "0" ]; then 192 | # The pushrm plugin is available from https://github.com/christian-korneck/docker-pushrm 193 | echo "Failed to update README for $(docker_repo) on Docker Hub (pushrm Docker CLI plugin not installed)" >&2 194 | exit 1 195 | fi 196 | 197 | if docker pushrm $(docker_repo); then 198 | echo "Successfully updated README for $(docker_repo) on Docker Hub" 199 | else 200 | echo "Failed to update README for $(docker_repo) on Docker Hub" >&2 201 | exit 1 202 | fi 203 | } 204 | 205 | prepare_builder() { 206 | if [ "$BUILDER" == "" ]; then 207 | docker run --privileged --rm tonistiigi/binfmt:qemu-v8.1.5 --install all &> /dev/null 208 | (docker buildx inspect builder &> /dev/null && echo -e "\nReusing existing builder") || \ 209 | (docker buildx create --name builder --use &> /dev/null && echo -e "\nCreated builder") 210 | BUILDER="builder" 211 | fi 212 | } 213 | 214 | build() { 215 | prepare_builder 216 | 217 | local openhab_version="${1/SNAPSHOT/snapshot}" 218 | local dist="$2" 219 | local push="$3" 220 | 221 | local java_version="" 222 | case $openhab_version in 223 | 4.*) java_version="17";; 224 | *) java_version="21";; 225 | esac 226 | 227 | local build_arg_options="--build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") --build-arg VCS_REF=$(git rev-parse HEAD) --build-arg JAVA_VERSION=$java_version --build-arg OPENHAB_VERSION=$openhab_version" 228 | local tags=$(tags $openhab_version $dist) 229 | local tag_options=${tags//$(docker_repo)/--tag $(docker_repo)} 230 | local output_options="--output type=image,oci-mediatypes=false,push=$([ "$push" == "--push" ] && echo true || echo false)" 231 | local build_options="$build_arg_options --platform $(platforms $openhab_version $dist) $tag_options $output_options --progress plain --provenance=false" 232 | local dockerfile_path="./$dist" 233 | local build_command="docker buildx build $build_options $dockerfile_path" 234 | 235 | echo 236 | echo "Building openHAB $openhab_version $dist Docker image" 237 | echo 238 | set -x 239 | 240 | $build_command 241 | 242 | { set +x; } 2> /dev/null 243 | echo 244 | } 245 | -------------------------------------------------------------------------------- /openhab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openhab/openhab-docker/1c2ab5e8a53783e089ac6b606122ae984b94d09a/openhab.png --------------------------------------------------------------------------------