From 69b2534052c19a39a0c46e08d40028e8bea2ff1c Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 1 Jan 2021 16:00:25 +0100 Subject: [PATCH] Rework build scripts (#336) * Make Dockerfiles more generic so they can be reused for all openHAB versions * Determine version information automatically based on openhab-distro tags/branches * Merge helper scripts into helper-functions * Add "build" script to simplify building multiple versions or a specific distro using BuildKit * Add GitHub Actions workflows for PR builds Fixes #318 Signed-off-by: Wouter Born --- .github/workflows/build-images.yml | 30 ++ .github/workflows/validate-readme.yml | 19 + 2.4.0/debian/Dockerfile | 126 ------- 2.5.11/alpine/Dockerfile | 110 ------ 2.5.11/alpine/entrypoint.sh | 99 ----- 2.5.11/alpine/update.sh | 207 ----------- 2.5.11/debian/Dockerfile | 126 ------- 2.5.11/debian/entrypoint.sh | 108 ------ 2.5.11/debian/update.sh | 207 ----------- 2.5.12-snapshot/alpine/Dockerfile | 110 ------ 2.5.12-snapshot/alpine/entrypoint.sh | 99 ----- 2.5.12-snapshot/alpine/update.sh | 207 ----------- 2.5.12-snapshot/debian/entrypoint.sh | 108 ------ 2.5.12-snapshot/debian/update.sh | 207 ----------- 3.0.0/alpine/Dockerfile | 110 ------ 3.0.0/alpine/entrypoint.sh | 99 ----- 3.0.0/alpine/update.sh | 207 ----------- 3.0.0/debian/Dockerfile | 126 ------- 3.0.0/debian/entrypoint.sh | 108 ------ 3.0.0/debian/update.sh | 207 ----------- 3.1.0-snapshot/alpine/Dockerfile | 110 ------ 3.1.0-snapshot/alpine/entrypoint.sh | 99 ----- 3.1.0-snapshot/alpine/update.sh | 207 ----------- 3.1.0-snapshot/debian/Dockerfile | 126 ------- 3.1.0-snapshot/debian/entrypoint.sh | 108 ------ 3.1.0-snapshot/debian/update.sh | 207 ----------- README.md | 111 +++--- {2.4.0/alpine => alpine}/Dockerfile | 41 +- .../alpine/entrypoint.sh => alpine/entrypoint | 0 2.4.0/alpine/update.sh => alpine/update | 0 build | 105 ++++++ {2.5.12-snapshot/debian => debian}/Dockerfile | 41 +- .../debian/entrypoint.sh => debian/entrypoint | 0 2.4.0/debian/update.sh => debian/update | 0 entrypoint-alpine.sh | 99 ----- entrypoint-debian.sh | 108 ------ helper-functions | 241 ++++++++++++ openhab-update.sh | 207 ----------- images/openhab.png => openhab.png | Bin sync-docker-hub-readme.sh | 23 -- update-docker-files.sh | 351 ------------------ update-functions.sh | 115 ------ update-readme.sh | 56 --- update.sh | 5 - versions | 41 -- 45 files changed, 485 insertions(+), 4536 deletions(-) create mode 100644 .github/workflows/build-images.yml create mode 100644 .github/workflows/validate-readme.yml delete mode 100644 2.4.0/debian/Dockerfile delete mode 100644 2.5.11/alpine/Dockerfile delete mode 100755 2.5.11/alpine/entrypoint.sh delete mode 100755 2.5.11/alpine/update.sh delete mode 100644 2.5.11/debian/Dockerfile delete mode 100755 2.5.11/debian/entrypoint.sh delete mode 100755 2.5.11/debian/update.sh delete mode 100644 2.5.12-snapshot/alpine/Dockerfile delete mode 100755 2.5.12-snapshot/alpine/entrypoint.sh delete mode 100755 2.5.12-snapshot/alpine/update.sh delete mode 100755 2.5.12-snapshot/debian/entrypoint.sh delete mode 100755 2.5.12-snapshot/debian/update.sh delete mode 100644 3.0.0/alpine/Dockerfile delete mode 100755 3.0.0/alpine/entrypoint.sh delete mode 100755 3.0.0/alpine/update.sh delete mode 100644 3.0.0/debian/Dockerfile delete mode 100755 3.0.0/debian/entrypoint.sh delete mode 100755 3.0.0/debian/update.sh delete mode 100644 3.1.0-snapshot/alpine/Dockerfile delete mode 100755 3.1.0-snapshot/alpine/entrypoint.sh delete mode 100755 3.1.0-snapshot/alpine/update.sh delete mode 100644 3.1.0-snapshot/debian/Dockerfile delete mode 100755 3.1.0-snapshot/debian/entrypoint.sh delete mode 100755 3.1.0-snapshot/debian/update.sh rename {2.4.0/alpine => alpine}/Dockerfile (74%) rename 2.4.0/alpine/entrypoint.sh => alpine/entrypoint (100%) rename 2.4.0/alpine/update.sh => alpine/update (100%) create mode 100755 build rename {2.5.12-snapshot/debian => debian}/Dockerfile (80%) rename 2.4.0/debian/entrypoint.sh => debian/entrypoint (100%) rename 2.4.0/debian/update.sh => debian/update (100%) delete mode 100755 entrypoint-alpine.sh delete mode 100755 entrypoint-debian.sh create mode 100644 helper-functions delete mode 100755 openhab-update.sh rename images/openhab.png => openhab.png (100%) delete mode 100755 sync-docker-hub-readme.sh delete mode 100755 update-docker-files.sh delete mode 100755 update-functions.sh delete mode 100755 update-readme.sh delete mode 100755 update.sh delete mode 100644 versions diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml new file mode 100644 index 0000000..8a39e8f --- /dev/null +++ b/.github/workflows/build-images.yml @@ -0,0 +1,30 @@ +name: Build images + +on: + push: + branches: [ $default-branch ] + pull_request: + branches: [ $default-branch ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-20.04 + strategy: + matrix: + tag: ["latest", "snapshot"] + distribution: ["alpine", "debian"] + name: ${{ matrix.tag }}-${{ matrix.distribution }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up QEMU + run: docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build images + run: ./build ${{ matrix.tag }} ${{ matrix.distribution }} diff --git a/.github/workflows/validate-readme.yml b/.github/workflows/validate-readme.yml new file mode 100644 index 0000000..117eaa3 --- /dev/null +++ b/.github/workflows/validate-readme.yml @@ -0,0 +1,19 @@ +name: Validate README.md + +on: + push: + branches: [ $default-branch ] + pull_request: + branches: [ $default-branch ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-20.04 + name: validate + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Validate README.md + run: bash -c 'source helper-functions && validate_readme_constraints' diff --git a/2.4.0/debian/Dockerfile b/2.4.0/debian/Dockerfile deleted file mode 100644 index 894b8e9..0000000 --- a/2.4.0/debian/Dockerfile +++ /dev/null @@ -1,126 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM debian:10.7-slim - -# Set version variables -ENV \ - JAVA_VERSION="8" \ - OPENHAB_VERSION="2.4.0" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ - arping \ - ca-certificates \ - curl \ - fontconfig \ - gosu \ - libcap2-bin \ - locales \ - locales-all \ - netbase \ - procps \ - tini \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - ln -s -f /bin/true /usr/bin/chfn && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Install java -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -RUN mkdir -p "${JAVA_HOME}" && \ - zulu8_amd64_url='https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz' && \ - zulu8_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch32hf.tar.gz' && \ - zulu8_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz' && \ - zulu11_amd64_url='https://cdn.azul.com/zulu/bin/zulu11.43.21-ca-jdk11.0.9-linux_x64.tar.gz' && \ - zulu11_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch32hf.tar.gz' && \ - zulu11_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch64.tar.gz' && \ - url_var="zulu${JAVA_VERSION}_$(dpkg --print-architecture)_url" && \ - eval "java_url=\$$url_var" && \ - wget -nv -O /tmp/java.tar.gz "${java_url}" && \ - tar --exclude='demo' --exclude='sample' --exclude='src.zip' -xf /tmp/java.tar.gz --strip-components=1 -C "${JAVA_HOME}" && \ - if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^#crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi && \ - rm /tmp/java.tar.gz && \ - update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 50 && \ - update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 50 - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F2.4.0%2Fopenhab-2.4.0.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] diff --git a/2.5.11/alpine/Dockerfile b/2.5.11/alpine/Dockerfile deleted file mode 100644 index 7db22fb..0000000 --- a/2.5.11/alpine/Dockerfile +++ /dev/null @@ -1,110 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM alpine:3.12.2 - -# Set version variables -ENV \ - JAVA_VERSION="8" \ - OPENHAB_VERSION="2.5.11" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apk update --no-cache && \ - apk add --no-cache \ - arping \ - bash \ - ca-certificates \ - curl \ - fontconfig \ - libcap \ - nss \ - shadow \ - su-exec \ - tini \ - ttf-dejavu \ - openjdk${JAVA_VERSION} \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - rm -rf /var/cache/apk/* - -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -RUN if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F2.5.11%2Fopenhab-2.5.11.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] diff --git a/2.5.11/alpine/entrypoint.sh b/2.5.11/alpine/entrypoint.sh deleted file mode 100755 index 0a4411b..0000000 --- a/2.5.11/alpine/entrypoint.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring OpenJDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "${JAVA_VERSION}" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 14 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID -D -g '' -h ${OPENHAB_HOME} -G openhab openhab - adduser openhab dialout - adduser openhab uucp -fi - - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar -c -f "${OPENHAB_BACKUPS}/${backup_file}" --exclude "backup/*" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "su-exec openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/2.5.11/alpine/update.sh b/2.5.11/alpine/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/2.5.11/alpine/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/2.5.11/debian/Dockerfile b/2.5.11/debian/Dockerfile deleted file mode 100644 index 9df2039..0000000 --- a/2.5.11/debian/Dockerfile +++ /dev/null @@ -1,126 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM debian:10.7-slim - -# Set version variables -ENV \ - JAVA_VERSION="8" \ - OPENHAB_VERSION="2.5.11" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ - arping \ - ca-certificates \ - curl \ - fontconfig \ - gosu \ - libcap2-bin \ - locales \ - locales-all \ - netbase \ - procps \ - tini \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - ln -s -f /bin/true /usr/bin/chfn && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Install java -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -RUN mkdir -p "${JAVA_HOME}" && \ - zulu8_amd64_url='https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz' && \ - zulu8_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch32hf.tar.gz' && \ - zulu8_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz' && \ - zulu11_amd64_url='https://cdn.azul.com/zulu/bin/zulu11.43.21-ca-jdk11.0.9-linux_x64.tar.gz' && \ - zulu11_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch32hf.tar.gz' && \ - zulu11_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch64.tar.gz' && \ - url_var="zulu${JAVA_VERSION}_$(dpkg --print-architecture)_url" && \ - eval "java_url=\$$url_var" && \ - wget -nv -O /tmp/java.tar.gz "${java_url}" && \ - tar --exclude='demo' --exclude='sample' --exclude='src.zip' -xf /tmp/java.tar.gz --strip-components=1 -C "${JAVA_HOME}" && \ - if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^#crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi && \ - rm /tmp/java.tar.gz && \ - update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 50 && \ - update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 50 - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F2.5.11%2Fopenhab-2.5.11.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] diff --git a/2.5.11/debian/entrypoint.sh b/2.5.11/debian/entrypoint.sh deleted file mode 100755 index 1a263c0..0000000 --- a/2.5.11/debian/entrypoint.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring Zulu JDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "$JAVA_VERSION" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 10 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID --disabled-password --gecos '' --home "${OPENHAB_HOME}" --gid $NEW_GROUP_ID openhab - groupadd -g 14 uucp2 - groupadd -g 16 dialout2 - groupadd -g 18 dialout3 - groupadd -g 32 uucp3 - groupadd -g 997 gpio - adduser openhab dialout - adduser openhab uucp - adduser openhab uucp2 - adduser openhab dialout2 - adduser openhab dialout3 - adduser openhab uucp3 - adduser openhab gpio -fi - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar --exclude="${OPENHAB_BACKUPS}" -c -f "${OPENHAB_BACKUPS}/${backup_file}" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "gosu openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/2.5.11/debian/update.sh b/2.5.11/debian/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/2.5.11/debian/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/2.5.12-snapshot/alpine/Dockerfile b/2.5.12-snapshot/alpine/Dockerfile deleted file mode 100644 index aa929ef..0000000 --- a/2.5.12-snapshot/alpine/Dockerfile +++ /dev/null @@ -1,110 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM alpine:3.12.2 - -# Set version variables -ENV \ - JAVA_VERSION="8" \ - OPENHAB_VERSION="2.5.12-snapshot" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apk update --no-cache && \ - apk add --no-cache \ - arping \ - bash \ - ca-certificates \ - curl \ - fontconfig \ - libcap \ - nss \ - shadow \ - su-exec \ - tini \ - ttf-dejavu \ - openjdk${JAVA_VERSION} \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - rm -rf /var/cache/apk/* - -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -RUN if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-2.5.12-SNAPSHOT.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] diff --git a/2.5.12-snapshot/alpine/entrypoint.sh b/2.5.12-snapshot/alpine/entrypoint.sh deleted file mode 100755 index 0a4411b..0000000 --- a/2.5.12-snapshot/alpine/entrypoint.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring OpenJDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "${JAVA_VERSION}" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 14 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID -D -g '' -h ${OPENHAB_HOME} -G openhab openhab - adduser openhab dialout - adduser openhab uucp -fi - - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar -c -f "${OPENHAB_BACKUPS}/${backup_file}" --exclude "backup/*" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "su-exec openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/2.5.12-snapshot/alpine/update.sh b/2.5.12-snapshot/alpine/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/2.5.12-snapshot/alpine/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/2.5.12-snapshot/debian/entrypoint.sh b/2.5.12-snapshot/debian/entrypoint.sh deleted file mode 100755 index 1a263c0..0000000 --- a/2.5.12-snapshot/debian/entrypoint.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring Zulu JDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "$JAVA_VERSION" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 10 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID --disabled-password --gecos '' --home "${OPENHAB_HOME}" --gid $NEW_GROUP_ID openhab - groupadd -g 14 uucp2 - groupadd -g 16 dialout2 - groupadd -g 18 dialout3 - groupadd -g 32 uucp3 - groupadd -g 997 gpio - adduser openhab dialout - adduser openhab uucp - adduser openhab uucp2 - adduser openhab dialout2 - adduser openhab dialout3 - adduser openhab uucp3 - adduser openhab gpio -fi - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar --exclude="${OPENHAB_BACKUPS}" -c -f "${OPENHAB_BACKUPS}/${backup_file}" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "gosu openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/2.5.12-snapshot/debian/update.sh b/2.5.12-snapshot/debian/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/2.5.12-snapshot/debian/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/3.0.0/alpine/Dockerfile b/3.0.0/alpine/Dockerfile deleted file mode 100644 index 0738131..0000000 --- a/3.0.0/alpine/Dockerfile +++ /dev/null @@ -1,110 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM alpine:3.12.2 - -# Set version variables -ENV \ - JAVA_VERSION="11" \ - OPENHAB_VERSION="3.0.0" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apk update --no-cache && \ - apk add --no-cache \ - arping \ - bash \ - ca-certificates \ - curl \ - fontconfig \ - libcap \ - nss \ - shadow \ - su-exec \ - tini \ - ttf-dejavu \ - openjdk${JAVA_VERSION} \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - rm -rf /var/cache/apk/* - -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -RUN if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F3.0.0%2Fopenhab-3.0.0.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] diff --git a/3.0.0/alpine/entrypoint.sh b/3.0.0/alpine/entrypoint.sh deleted file mode 100755 index 0a4411b..0000000 --- a/3.0.0/alpine/entrypoint.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring OpenJDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "${JAVA_VERSION}" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 14 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID -D -g '' -h ${OPENHAB_HOME} -G openhab openhab - adduser openhab dialout - adduser openhab uucp -fi - - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar -c -f "${OPENHAB_BACKUPS}/${backup_file}" --exclude "backup/*" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "su-exec openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/3.0.0/alpine/update.sh b/3.0.0/alpine/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/3.0.0/alpine/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/3.0.0/debian/Dockerfile b/3.0.0/debian/Dockerfile deleted file mode 100644 index eaa298f..0000000 --- a/3.0.0/debian/Dockerfile +++ /dev/null @@ -1,126 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM debian:10.7-slim - -# Set version variables -ENV \ - JAVA_VERSION="11" \ - OPENHAB_VERSION="3.0.0" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ - arping \ - ca-certificates \ - curl \ - fontconfig \ - gosu \ - libcap2-bin \ - locales \ - locales-all \ - netbase \ - procps \ - tini \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - ln -s -f /bin/true /usr/bin/chfn && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Install java -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -RUN mkdir -p "${JAVA_HOME}" && \ - zulu8_amd64_url='https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz' && \ - zulu8_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch32hf.tar.gz' && \ - zulu8_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz' && \ - zulu11_amd64_url='https://cdn.azul.com/zulu/bin/zulu11.43.21-ca-jdk11.0.9-linux_x64.tar.gz' && \ - zulu11_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch32hf.tar.gz' && \ - zulu11_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch64.tar.gz' && \ - url_var="zulu${JAVA_VERSION}_$(dpkg --print-architecture)_url" && \ - eval "java_url=\$$url_var" && \ - wget -nv -O /tmp/java.tar.gz "${java_url}" && \ - tar --exclude='demo' --exclude='sample' --exclude='src.zip' -xf /tmp/java.tar.gz --strip-components=1 -C "${JAVA_HOME}" && \ - if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^#crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi && \ - rm /tmp/java.tar.gz && \ - update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 50 && \ - update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 50 - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F3.0.0%2Fopenhab-3.0.0.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] diff --git a/3.0.0/debian/entrypoint.sh b/3.0.0/debian/entrypoint.sh deleted file mode 100755 index 1a263c0..0000000 --- a/3.0.0/debian/entrypoint.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring Zulu JDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "$JAVA_VERSION" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 10 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID --disabled-password --gecos '' --home "${OPENHAB_HOME}" --gid $NEW_GROUP_ID openhab - groupadd -g 14 uucp2 - groupadd -g 16 dialout2 - groupadd -g 18 dialout3 - groupadd -g 32 uucp3 - groupadd -g 997 gpio - adduser openhab dialout - adduser openhab uucp - adduser openhab uucp2 - adduser openhab dialout2 - adduser openhab dialout3 - adduser openhab uucp3 - adduser openhab gpio -fi - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar --exclude="${OPENHAB_BACKUPS}" -c -f "${OPENHAB_BACKUPS}/${backup_file}" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "gosu openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/3.0.0/debian/update.sh b/3.0.0/debian/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/3.0.0/debian/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/3.1.0-snapshot/alpine/Dockerfile b/3.1.0-snapshot/alpine/Dockerfile deleted file mode 100644 index e7ba754..0000000 --- a/3.1.0-snapshot/alpine/Dockerfile +++ /dev/null @@ -1,110 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM alpine:3.12.2 - -# Set version variables -ENV \ - JAVA_VERSION="11" \ - OPENHAB_VERSION="3.1.0-snapshot" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apk update --no-cache && \ - apk add --no-cache \ - arping \ - bash \ - ca-certificates \ - curl \ - fontconfig \ - libcap \ - nss \ - shadow \ - su-exec \ - tini \ - ttf-dejavu \ - openjdk${JAVA_VERSION} \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - rm -rf /var/cache/apk/* - -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -RUN if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-3.1.0-SNAPSHOT.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] diff --git a/3.1.0-snapshot/alpine/entrypoint.sh b/3.1.0-snapshot/alpine/entrypoint.sh deleted file mode 100755 index 0a4411b..0000000 --- a/3.1.0-snapshot/alpine/entrypoint.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring OpenJDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "${JAVA_VERSION}" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 14 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID -D -g '' -h ${OPENHAB_HOME} -G openhab openhab - adduser openhab dialout - adduser openhab uucp -fi - - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar -c -f "${OPENHAB_BACKUPS}/${backup_file}" --exclude "backup/*" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "su-exec openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/3.1.0-snapshot/alpine/update.sh b/3.1.0-snapshot/alpine/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/3.1.0-snapshot/alpine/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/3.1.0-snapshot/debian/Dockerfile b/3.1.0-snapshot/debian/Dockerfile deleted file mode 100644 index 00fb9dd..0000000 --- a/3.1.0-snapshot/debian/Dockerfile +++ /dev/null @@ -1,126 +0,0 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# -FROM debian:10.7-slim - -# Set version variables -ENV \ - JAVA_VERSION="11" \ - OPENHAB_VERSION="3.1.0-snapshot" - -# Set other variables -ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - -# Basic build-time metadata as defined at http://label-schema.org -LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -# Install basepackages -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ - arping \ - ca-certificates \ - curl \ - fontconfig \ - gosu \ - libcap2-bin \ - locales \ - locales-all \ - netbase \ - procps \ - tini \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - ln -s -f /bin/true /usr/bin/chfn && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Install java -ENV JAVA_HOME='/usr/lib/jvm/default-jvm' -# Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography -RUN mkdir -p "${JAVA_HOME}" && \ - zulu8_amd64_url='https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz' && \ - zulu8_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch32hf.tar.gz' && \ - zulu8_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz' && \ - zulu11_amd64_url='https://cdn.azul.com/zulu/bin/zulu11.43.21-ca-jdk11.0.9-linux_x64.tar.gz' && \ - zulu11_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch32hf.tar.gz' && \ - zulu11_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch64.tar.gz' && \ - url_var="zulu${JAVA_VERSION}_$(dpkg --print-architecture)_url" && \ - eval "java_url=\$$url_var" && \ - wget -nv -O /tmp/java.tar.gz "${java_url}" && \ - tar --exclude='demo' --exclude='sample' --exclude='src.zip' -xf /tmp/java.tar.gz --strip-components=1 -C "${JAVA_HOME}" && \ - if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^#crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi && \ - rm /tmp/java.tar.gz && \ - update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 50 && \ - update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 50 - -# Install openHAB -# Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-3.1.0-SNAPSHOT.zip" && \ - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update -RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -# Expose volume with configuration and userdata dir -VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -# Expose HTTP, HTTPS, Console and LSP ports -EXPOSE 8080 8443 8101 5007 - -# Set working directory and entrypoint -WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -# Execute command -CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] diff --git a/3.1.0-snapshot/debian/entrypoint.sh b/3.1.0-snapshot/debian/entrypoint.sh deleted file mode 100755 index 1a263c0..0000000 --- a/3.1.0-snapshot/debian/entrypoint.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring Zulu JDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "$JAVA_VERSION" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 10 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID --disabled-password --gecos '' --home "${OPENHAB_HOME}" --gid $NEW_GROUP_ID openhab - groupadd -g 14 uucp2 - groupadd -g 16 dialout2 - groupadd -g 18 dialout3 - groupadd -g 32 uucp3 - groupadd -g 997 gpio - adduser openhab dialout - adduser openhab uucp - adduser openhab uucp2 - adduser openhab dialout2 - adduser openhab dialout3 - adduser openhab uucp3 - adduser openhab gpio -fi - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar --exclude="${OPENHAB_BACKUPS}" -c -f "${OPENHAB_BACKUPS}/${backup_file}" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "gosu openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/3.1.0-snapshot/debian/update.sh b/3.1.0-snapshot/debian/update.sh deleted file mode 100755 index 55789ab..0000000 --- a/3.1.0-snapshot/debian/update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/README.md b/README.md index dd32a81..d90f445 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # openHAB Docker Containers -![openHAB logo](https://github.com/openhab/openhab-docker/raw/master/images/openhab.png) +![openHAB logo](https://github.com/openhab/openhab-docker/raw/master/openhab.png) [![Build Status](https://ci.openhab.org/job/openHAB-Docker/badge/icon)](https://ci.openhab.org/job/openHAB-Docker/) [![EPL-2.0](https://img.shields.io/badge/license-EPL%202-green.svg)](https://opensource.org/licenses/EPL-2.0) @@ -35,12 +35,11 @@ * [Java cryptographic strength policy](#java-cryptographic-strength-policy) * [Parameters](#parameters) * [Passing devices with symlinks](#passing-devices-with-symlinks) - * [Upgrading](#upgrading) - * [Building the images](#building-the-images) * [Executing shell scripts before openHAB is started](#executing-shell-scripts-before-openhab-is-started) + * [Upgrading](#upgrading) * [Common problems](#common-problems) + * [Building the images](#building-the-images) * [Contributing](#contributing) - * [License](#license) ## Introduction @@ -72,16 +71,14 @@ Comments, suggestions and contributions are welcome! **Versions:** -* `2.4.0` Stable openHAB 2.4.0 version ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/2.4.0/debian/Dockerfile)) -* `2.5.0` - `2.5.11` Stable openHAB 2.5.x version ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/2.5.11/debian/Dockerfile)) -* `3.0.0` Stable openHAB 3.0.0 version ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/3.0.0/debian/Dockerfile)) -* `2.5.12-snapshot` Experimental openHAB 2.5.12 SNAPSHOT version ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/2.5.12-snapshot/debian/Dockerfile)) -* `3.1.0-snapshot` Experimental openHAB 3.1.0 SNAPSHOT version ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/3.1.0-snapshot/debian/Dockerfile)) +* **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. + * `3.0.0` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/3.0.0)) + * `2.5.11` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/2.5.11)) **Distributions:** -* `debian` for Debian 10 "buster" (default when not specified in tag) -* `alpine` for Alpine 3.12 +* `debian` for Debian 10 "buster" (default when not specified in tag) ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/debian/Dockerfile)) +* `alpine` for Alpine 3.12 ([Dockerfile](https://github.com/openhab/openhab-docker/blob/master/alpine/Dockerfile)) 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). @@ -429,50 +426,6 @@ docker run \ More information about serial ports and symlinks can be found [here](https://www.openhab.org/docs/administration/serial.html). -## Upgrading - -Upgrading OH requires changes to the user mapped in userdata folder. -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. - -The steps performed are: -* Create a `userdata/backup` folder if one does not exist. -* Create a full backup of userdata as a dated tar file saved to `userdata/backup`. The `userdata/backup` folder is excluded from this backup. -* Show update notes and warnings. -* Execute update pre/post commands. -* Copy userdata system files from `dist/userdata/etc` to `userdata/etc`. -* Update KAR files in `addons`. -* Delete the contents of `userdata/cache` and `userdata/tmp`. - -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. -All messages shown during the update are also logged to `userdata/logs/update.log`. - -## Building the images - -Checkout the GitHub repository, change to a directory containing a Dockerfile (e.g. `3.0.0/debian`) and then run these commands to build and run a Docker image for your current platform: - -```shell -$ docker build --tag openhab/openhab . -$ docker run openhab/openhab -``` - -To be able to build the same image for other platforms (e.g. arm/v7, arm64 on amd64) Docker CE 19.03 with BuildKit support can be used. - -First enable BuildKit support, configure QEMU binary formats and a builder using: - -```shell -$ echo '{"experimental":true}' | sudo tee /etc/docker/daemon.json -$ export DOCKER_CLI_EXPERIMENTAL=enabled -$ docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64 -$ sudo systemctl restart docker -$ docker buildx create --name builder --use -``` - -Change to a directory containing a Dockerfile (e.g. `3.0.0/debian`) and then use the following command to build a armhf image: - -``` -$ docker buildx build --platform linux/arm/v7 --tag openhab/openhab --load . -``` - ## Executing shell scripts before openHAB is started It is sometimes useful to run shell scripts after the "userdata" directory is created, but before Karaf itself is launched. @@ -496,6 +449,23 @@ and add a volume mount to your startup: and put your scripts into that directory. 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. +## Upgrading + +Upgrading OH requires changes to the user mapped in userdata folder. +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. + +The steps performed are: +* Create a `userdata/backup` folder if one does not exist. +* Create a full backup of userdata as a dated tar file saved to `userdata/backup`. The `userdata/backup` folder is excluded from this backup. +* Show update notes and warnings. +* Execute update pre/post commands. +* Copy userdata system files from `dist/userdata/etc` to `userdata/etc`. +* Update KAR files in `addons`. +* Delete the contents of `userdata/cache` and `userdata/tmp`. + +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. +All messages shown during the update are also logged to `userdata/logs/update.log`. + ## Common problems ### Error: KARAF_ETC is not valid @@ -532,6 +502,37 @@ To resolve this issue when upgrading openHAB, first remove all default (non-over 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. For more information on this see the [Docker documentation](https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label). +## Building the images + +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: + +```shell +$ docker build --build-arg JAVA_VERSION=11 --build-arg OPENHAB_VERSION=3.0.0 --tag openhab/openhab . +$ docker run openhab/openhab +``` + +To be able to build the same image for other platforms (e.g. arm/v7, arm64 on amd64) Docker CE 19.03 with BuildKit support can be used. + +First enable BuildKit support, configure QEMU binary formats and a builder using: + +```shell +$ echo '{"experimental":true}' | sudo tee /etc/docker/daemon.json +$ export DOCKER_CLI_EXPERIMENTAL=enabled +$ docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64 +$ sudo systemctl restart docker +$ docker buildx create --name builder --use +``` + +Change to a directory containing a Dockerfile (e.g. `/debian`) and then use the following command to build an ARMv7 image: + +``` +$ docker buildx build --build-arg JAVA_VERSION=11 --build-arg OPENHAB_VERSION=3.0.0 --platform linux/arm/v7 --tag openhab/openhab --load . +``` + +The `build` script in the root of the repository helps to simplify building the openHAB images with BuildKit. +It can be used to build the images of multiple openHAB versions and correctly tag and push them to a Docker registry. +Execute `./build -h` for usage instructions and examples. + ## Contributing [Contribution guidelines](https://github.com/openhab/openhab-docker/blob/master/CONTRIBUTING.md) diff --git a/2.4.0/alpine/Dockerfile b/alpine/Dockerfile similarity index 74% rename from 2.4.0/alpine/Dockerfile rename to alpine/Dockerfile index f39f699..8f8283c 100644 --- a/2.4.0/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -1,23 +1,15 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# FROM alpine:3.12.2 -# Set version variables -ENV \ - JAVA_VERSION="8" \ - OPENHAB_VERSION="2.4.0" +ARG BUILD_DATE +ARG VCS_REF +ARG JAVA_VERSION +ARG OPENHAB_VERSION -# Set other variables ENV \ CRYPTO_POLICY="limited" \ EXTRA_JAVA_OPTS="" \ GROUP_ID="9001" \ + JAVA_VERSION="$JAVA_VERSION" \ KARAF_EXEC="exec" \ LC_ALL="en_US.UTF-8" \ LANG="en_US.UTF-8" \ @@ -29,20 +21,16 @@ ENV \ OPENHAB_HTTPS_PORT="8443" \ OPENHAB_LOGDIR="/openhab/userdata/logs" \ OPENHAB_USERDATA="/openhab/userdata" \ + OPENHAB_VERSION="$OPENHAB_VERSION" \ USER_ID="9001" -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - # Basic build-time metadata as defined at http://label-schema.org LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.docker.dockerfile="/Dockerfile" \ org.label-schema.license="EPL-2.0" \ org.label-schema.name="openHAB" \ org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ + org.label-schema.version=$OPENHAB_VERSION \ org.label-schema.description="An open source, technology agnostic home automation platform" \ org.label-schema.url="https://www.openhab.com/" \ org.label-schema.vcs-ref=$VCS_REF \ @@ -81,7 +69,12 @@ RUN if [ "${JAVA_VERSION}" = "8" ]; then \ # Install openHAB # Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F2.4.0%2Fopenhab-2.4.0.zip" && \ +RUN version="$(echo $OPENHAB_VERSION | sed 's/snapshot/SNAPSHOT/g')" && \ + 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"; \ + elif [ $(echo $version | grep -E '^2\..+-SNAPSHOT$') ]; then url="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip"; \ + elif [ $(echo $version | grep -E '^3\..+-SNAPSHOT$') ]; then url="https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip"; \ + else url="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F${version}%2Fopenhab-${version}.zip"; fi && \ + wget -nv -O /tmp/openhab.zip "$url" && \ unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ rm /tmp/openhab.zip && \ if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ @@ -91,7 +84,7 @@ RUN wget -nv -O /tmp/openhab.zip "https://bintray.com/openhab/mvn/download_file? mkdir -p "${OPENHAB_HOME}/dist" && \ cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update +COPY update ${OPENHAB_HOME}/runtime/bin/update RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update # Expose volume with configuration and userdata dir @@ -102,9 +95,9 @@ EXPOSE 8080 8443 8101 5007 # Set working directory and entrypoint WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +COPY entrypoint /entrypoint +RUN chmod +x /entrypoint +ENTRYPOINT ["/entrypoint"] # Execute command CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] diff --git a/2.4.0/alpine/entrypoint.sh b/alpine/entrypoint similarity index 100% rename from 2.4.0/alpine/entrypoint.sh rename to alpine/entrypoint diff --git a/2.4.0/alpine/update.sh b/alpine/update similarity index 100% rename from 2.4.0/alpine/update.sh rename to alpine/update diff --git a/build b/build new file mode 100755 index 0000000..c5387c6 --- /dev/null +++ b/build @@ -0,0 +1,105 @@ +#!/bin/bash +set -eo pipefail + +source helper-functions + +filter_options() { + local options="$1" + local valid_options="$2" + local fallback="$3" + + local filtered=() + for valid_option in $valid_options; do + for option in $options; do + if [ "$option" == "$valid_option" ]; then + filtered+=("$option") + fi + done + done + + local result="$(IFS=' '; echo "${filtered[*]}")" + if [ "$result" == "" ]; then + echo "$fallback" + else + echo "$result" + fi +} + +resolve_version_tags() { + local latest_version=$(last_stable_version) + local milestone_version="$(last_milestone_version)" + if [ "$milestone_version" == "" ]; then + milestone_version="$(last_stable_version)" + fi + local snapshot_version=$(last_snapshot_version) + + local results=() + for s in $@; do + local result="$s" + if [ "$result" == "latest" ]; then + result="$latest_version" + elif [ "$result" == "milestone" ]; then + result="$milestone_version" + elif [ "$result" == "snapshot" ]; then + result="$snapshot_version" + fi + results+=("$result") + done + + echo "$(IFS=' '; echo "${results[*]}")" +} + +print_help() { + local snapshot_2x=$(grep -E '^2\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS | tail -n 1) + local stable_2x=$(grep -E '^2\.[0-9]+\.[0-9]+$' <<< $VERSIONS | tail -n 1) + + local snapshot_3x=$(grep -E '^3\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS | tail -n 1) + local stable_3x=$(grep -E '^3\.[0-9]+\.[0-9]+$' <<< $VERSIONS | tail -n 1) + + cat <<-EOI +Usage: ./build [OPTIONS] + +Builds openHAB Docker images using BuildKit. + +When no options are provided the latest snapshot images are build for all Docker platforms. +To build other versions or only the images of a specific base image add these to the options. +To push the images to the Docker registry ($(docker_repo)) add --push +Log in to the Docker Registry with "docker login" before building and pushing the images. + +Examples: + +Build the Debian and Alpine $snapshot_3x images: + ./build + +Build the Debian $snapshot_3x images: + ./build debian + +Build the Alpine $snapshot_2x images: + ./build $snapshot_2x alpine + +Build the $stable_2x and $stable_3x Debian/Alpine images and push them to $(docker_repo): + ./build $stable_2x $stable_3x --push + +Build the latest/snapshot Debian images by resolving the versions ("milestone" can also be resolved): + ./build latest snapshot debian + +EOI +} + +main() { + local versions=$(filter_options "$(resolve_version_tags "${*/-SNAPSHOT/-snapshot}")" "$VERSIONS" "$(last_snapshot_version)") + local bases=$(filter_options "$*" "$(bases)" "$(bases)") + local push=$(filter_options "$*" "--push" "") + + for version in $versions; do + for base in $bases; do + build $version $base $push + done + done +} + +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + print_help +else + main "$@" +fi diff --git a/2.5.12-snapshot/debian/Dockerfile b/debian/Dockerfile similarity index 80% rename from 2.5.12-snapshot/debian/Dockerfile rename to debian/Dockerfile index 33a90e3..c0642af 100644 --- a/2.5.12-snapshot/debian/Dockerfile +++ b/debian/Dockerfile @@ -1,23 +1,15 @@ -# openhab image -# -# ------------------------------------------------------------------------------ -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" -# -# PLEASE DO NOT EDIT IT DIRECTLY. -# ------------------------------------------------------------------------------ -# FROM debian:10.7-slim -# Set version variables -ENV \ - JAVA_VERSION="8" \ - OPENHAB_VERSION="2.5.12-snapshot" +ARG BUILD_DATE +ARG VCS_REF +ARG JAVA_VERSION +ARG OPENHAB_VERSION -# Set other variables ENV \ CRYPTO_POLICY="limited" \ EXTRA_JAVA_OPTS="" \ GROUP_ID="9001" \ + JAVA_VERSION="$JAVA_VERSION" \ KARAF_EXEC="exec" \ LC_ALL="en_US.UTF-8" \ LANG="en_US.UTF-8" \ @@ -29,20 +21,16 @@ ENV \ OPENHAB_HTTPS_PORT="8443" \ OPENHAB_LOGDIR="/openhab/userdata/logs" \ OPENHAB_USERDATA="/openhab/userdata" \ + OPENHAB_VERSION="$OPENHAB_VERSION" \ USER_ID="9001" -# Set arguments on build -ARG BUILD_DATE -ARG VCS_REF -ARG VERSION - # Basic build-time metadata as defined at http://label-schema.org LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.docker.dockerfile="/Dockerfile" \ org.label-schema.license="EPL-2.0" \ org.label-schema.name="openHAB" \ org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ + org.label-schema.version=$OPENHAB_VERSION \ org.label-schema.description="An open source, technology agnostic home automation platform" \ org.label-schema.url="https://www.openhab.com/" \ org.label-schema.vcs-ref=$VCS_REF \ @@ -97,7 +85,12 @@ RUN mkdir -p "${JAVA_HOME}" && \ # Install openHAB # Set permissions for openHAB. Export TERM variable. See issue #30 for details! -RUN wget -nv -O /tmp/openhab.zip "https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-2.5.12-SNAPSHOT.zip" && \ +RUN version="$(echo $OPENHAB_VERSION | sed 's/snapshot/SNAPSHOT/g')" && \ + 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"; \ + elif [ $(echo $version | grep -E '^2\..+-SNAPSHOT$') ]; then url="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip"; \ + elif [ $(echo $version | grep -E '^3\..+-SNAPSHOT$') ]; then url="https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip"; \ + else url="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F${version}%2Fopenhab-${version}.zip"; fi && \ + wget -nv -O /tmp/openhab.zip "$url" && \ unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ rm /tmp/openhab.zip && \ if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ @@ -107,7 +100,7 @@ RUN wget -nv -O /tmp/openhab.zip "https://ci.openhab.org/job/openHAB-Distributio mkdir -p "${OPENHAB_HOME}/dist" && \ cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc -COPY update.sh ${OPENHAB_HOME}/runtime/bin/update +COPY update ${OPENHAB_HOME}/runtime/bin/update RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update # Expose volume with configuration and userdata dir @@ -118,9 +111,9 @@ EXPOSE 8080 8443 8101 5007 # Set working directory and entrypoint WORKDIR ${OPENHAB_HOME} -COPY entrypoint.sh / -RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +COPY entrypoint /entrypoint +RUN chmod +x /entrypoint +ENTRYPOINT ["/entrypoint"] # Execute command CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] diff --git a/2.4.0/debian/entrypoint.sh b/debian/entrypoint similarity index 100% rename from 2.4.0/debian/entrypoint.sh rename to debian/entrypoint diff --git a/2.4.0/debian/update.sh b/debian/update similarity index 100% rename from 2.4.0/debian/update.sh rename to debian/update diff --git a/entrypoint-alpine.sh b/entrypoint-alpine.sh deleted file mode 100755 index 0a4411b..0000000 --- a/entrypoint-alpine.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring OpenJDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "${JAVA_VERSION}" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 14 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID -D -g '' -h ${OPENHAB_HOME} -G openhab openhab - adduser openhab dialout - adduser openhab uucp -fi - - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar -c -f "${OPENHAB_BACKUPS}/${backup_file}" --exclude "backup/*" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "su-exec openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/entrypoint-debian.sh b/entrypoint-debian.sh deleted file mode 100755 index 1a263c0..0000000 --- a/entrypoint-debian.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -x - -interactive=$(if test -t 0; then echo true; else echo false; fi) -set -euo pipefail -IFS=$'\n\t' - -# Configure Java unlimited strength cryptography -if [ "${CRYPTO_POLICY}" = "unlimited" ]; then - echo "Configuring Zulu JDK ${JAVA_VERSION} unlimited strength cryptography policy..." - if [ "${JAVA_VERSION}" = "8" ]; then - java_security_file="${JAVA_HOME}/jre/lib/security/java.security" - elif [ "$JAVA_VERSION" = "11" ]; then - java_security_file="${JAVA_HOME}/conf/security/java.security" - fi - sed -i 's/^crypto.policy=limited/crypto.policy=unlimited/' "${java_security_file}" -fi - -# Deleting instance.properties to avoid karaf PID conflict on restart -# See: https://github.com/openhab/openhab-docker/issues/99 -rm -f "${OPENHAB_HOME}/runtime/instances/instance.properties" - -# The instance.properties file in openHAB 2.x/3.x is installed in the tmp -# directory -rm -f "${OPENHAB_USERDATA}/tmp/instances/instance.properties" - -# Add openhab user & handle possible device groups for different host systems -# Container base image puts dialout on group id 20, uucp on id 10 -# GPIO Group for RPI access -NEW_USER_ID=${USER_ID:-9001} -NEW_GROUP_ID=${GROUP_ID:-$NEW_USER_ID} -echo "Starting with openhab user id: $NEW_USER_ID and group id: $NEW_GROUP_ID" -if ! id -u openhab >/dev/null 2>&1; then - if [ -z "$(getent group $NEW_GROUP_ID)" ]; then - echo "Create group openhab with id ${NEW_GROUP_ID}" - groupadd -g $NEW_GROUP_ID openhab - else - group_name=$(getent group $NEW_GROUP_ID | cut -d: -f1) - echo "Rename group $group_name to openhab" - groupmod --new-name openhab $group_name - fi - echo "Create user openhab with id ${NEW_USER_ID}" - adduser -u $NEW_USER_ID --disabled-password --gecos '' --home "${OPENHAB_HOME}" --gid $NEW_GROUP_ID openhab - groupadd -g 14 uucp2 - groupadd -g 16 dialout2 - groupadd -g 18 dialout3 - groupadd -g 32 uucp3 - groupadd -g 997 gpio - adduser openhab dialout - adduser openhab uucp - adduser openhab uucp2 - adduser openhab dialout2 - adduser openhab dialout3 - adduser openhab uucp3 - adduser openhab gpio -fi - -initialize_volume() { - volume="$1" - source="$2" - - if [ -z "$(ls -A "$volume")" ]; then - echo "Initializing empty volume ${volume} ..." - cp -av "${source}/." "${volume}/" - fi -} - -# Initialize empty volumes and update userdata -initialize_volume "${OPENHAB_CONF}" "${OPENHAB_HOME}/dist/conf" -initialize_volume "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist/userdata" - -# Update userdata if versions do not match -if [ ! -z $(cmp "${OPENHAB_USERDATA}/etc/version.properties" "${OPENHAB_HOME}/dist/userdata/etc/version.properties") ]; then - echo "Image and userdata versions differ! Starting an upgrade." | tee "${OPENHAB_LOGDIR}/update.log" - - # Make a backup of userdata - backup_file=userdata-$(date +"%FT%H-%M-%S").tar - if [ ! -d "${OPENHAB_BACKUPS}" ]; then - mkdir "${OPENHAB_BACKUPS}" - fi - tar --exclude="${OPENHAB_BACKUPS}" -c -f "${OPENHAB_BACKUPS}/${backup_file}" "${OPENHAB_USERDATA}" - echo "You can find backup of userdata in ${OPENHAB_BACKUPS}/${backup_file}" | tee -a "${OPENHAB_LOGDIR}/update.log" - - exec "${OPENHAB_HOME}/runtime/bin/update" 2>&1 | tee -a "${OPENHAB_LOGDIR}/update.log" -fi - -# Set openhab folder permission -chown -R openhab:openhab "${OPENHAB_HOME}" -sync - -# Run s6-style init continuation scripts if existent -if [ -d /etc/cont-init.d ] -then - for script in $(find /etc/cont-init.d -type f | grep -v \~ | sort) - do - . "${script}" - done -fi - -# sync again after continuation scripts have been run -sync - -# Use server mode with the default command when there is no pseudo-TTY -if [ "$interactive" == "false" ] && [ "$(IFS=" "; echo "$@")" == "gosu openhab tini -s ./start.sh" ]; then - command=($@ server) - exec "${command[@]}" -else - exec "$@" -fi diff --git a/helper-functions b/helper-functions new file mode 100644 index 0000000..58fa02d --- /dev/null +++ b/helper-functions @@ -0,0 +1,241 @@ +#!/bin/bash +set -eo pipefail + +BUILDER="" +DISTRO_REPO="${DISTRO_REPO:=openhab/openhab-distro}" +VERSIONS="" + +get_released_versions_from_tags() { + git ls-remote --refs --tags "git://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 "" +} + +get_snapshot_version_from_pom() { + local branch_name="$1" + curl -sS "https://raw.githubusercontent.com/${DISTRO_REPO}/${branch_name}/pom.xml" | grep -E '^ ' | grep 'SNAPSHOT' | sed -E 's#.+(.+)-SNAPSHOT#\1-snapshot#g' || echo "" +} + +get_snapshot_versions_from_poms() { + get_snapshot_version_from_pom '2.5.x' + get_snapshot_version_from_pom 'master' +} + +get_versions() { + (get_released_versions_from_tags && get_snapshot_versions_from_poms) | sort --unique --version-sort +} + +VERSIONS=$(get_versions) + +# Supported base images +bases() { + echo "debian alpine" +} + +docker_repo() { + echo "${DOCKER_REPO:=openhab/openhab}" +} + +# Supported Docker platforms +platforms() { + local version="$1" + local base="$2" + + if [[ "$version" =~ ^3.*$ ]] && [ "$base" == "alpine" ]; then + # There is no linux/arm/v7 Alpine image for openHAB 3 because the openjdk11 package is unavailable for this architecture + echo "linux/amd64,linux/arm64" + else + echo "linux/amd64,linux/arm64,linux/arm/v7" + fi +} + +tags() { + local version="$1" + local base="$2" + + local tags=() + + if [ "$base" == "debian" ]; then + tags+=("$(docker_repo):$version") + fi + + tags+=("$(docker_repo):$version-$base") + + if [ "$version" == "$(last_stable_version)" ]; then + if [ "$base" == "debian" ]; then + tags+=("$(docker_repo):latest") + fi + tags+=("$(docker_repo):latest-$base") + fi + + milestone_maturity_version="$(last_milestone_version)" + if [ "$milestone_maturity_version" == "" ]; then + milestone_maturity_version="$(last_stable_version)" + fi + + if [ "$version" == "$milestone_maturity_version" ]; then + if [ "$base" == "debian" ]; then + tags+=("$(docker_repo):milestone") + fi + tags+=("$(docker_repo):milestone-$base") + fi + + if [ "$version" == "$(last_snapshot_version)" ]; then + if [ "$base" == "debian" ]; then + tags+=("$(docker_repo):snapshot") + fi + tags+=("$(docker_repo):snapshot-$base") + fi + + echo $(IFS=' '; echo "${tags[*]}") +} + +last_stable_version() { + grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' <<< $VERSIONS | tail -n 1 +} + +stable_versions() { + grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' <<< $VERSIONS +} + +last_stable_minor_versions() { + local minor_versions=$(grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' <<< $VERSIONS | sed -E 's/^([0-9]+\.[0-9]+).+/\1/' | sort --unique --version-sort) + for minor_version in $minor_versions; do + stable_versions | grep -E "^$minor_version" | tail -n 1 + done +} + +snapshot_versions() { + grep -E '^[0-9]+\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS || echo "" +} + +last_snapshot_version() { + grep -E '^[0-9]+\.[0-9]+\.[0-9]+-snapshot$' <<< $VERSIONS | tail -n 1 || echo "" +} + +next_stable_version() { + sed 's/-snapshot//' <<< $(last_snapshot_version) +} + +milestone_versions() { + grep -E "$(next_stable_version)\.(M|RC)[0-9]+$" <<< $VERSIONS | tail -n 3 || echo "" +} + +last_milestone_version() { + grep -E "$(next_stable_version)\.(M|RC)[0-9]+$" <<< $VERSIONS | tail -n 1 || echo "" +} + +generate_readme_versions() { + local text="$1" + local versions="$(echo "$2" | sort --reverse --version-sort | head -n 2)" + + if [ "$versions" != "" ]; then + echo "* $text" + for version in $versions; do + case $version in + *-snapshot) echo " * \`$version\`";; + *) echo " * \`$version\` ([Release notes](https://github.com/openhab/openhab-distro/releases/tag/$version))";; + esac + done + fi +} + +update_readme() { + local file=README.md + + local generate="false" + while IFS= read -r line + do + if [[ $line =~ ^\*\ \*\*Stable:\*\*.+$ ]]; then + generate="true" + else + if [ "$generate" == "true" ]; then + if [ "$line" == "" ]; then + generate="false" + + generate_readme_versions \ + '**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.' \ + "$(last_stable_minor_versions)" + generate_readme_versions \ + '**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.' \ + "$(milestone_versions)" + generate_readme_versions \ + '**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!' \ + "$(snapshot_versions)" + echo + fi + else + echo "$line" + fi + fi + done < $file > $file.new && mv $file.new $file + + sed -i "s#openhab/openhab:[0-9]*\.[0-9]*\.[0-9]*#openhab/openhab:$(last_stable_version)#g" $file + sed -i "s#OPENHAB_VERSION=[0-9]*\.[0-9]*\.[0-9]*#OPENHAB_VERSION=$(last_stable_version)#g" $file +} + +validate_readme_constraints() { + local count=$(wc -m &2 + exit 1 + else + echo "README.md contains $count characters which is below the 25000 character limit of Docker Hub" + fi +} + +update_dockerhub_readme() { + # Acquire token for Docker Hub API + local login_payload="{\"username\": \"${DOCKER_USERNAME}\", \"password\": \"${DOCKER_PASSWORD}\"}" + local token=$(curl -s -H "Content-Type: application/json" -X POST -d "${login_payload}" https://hub.docker.com/v2/users/login/ | sed -E 's#\{"token": "(.+)"\}#\1#g') + + # Send a PATCH request to update the description of the repository + echo "Updating README for $(docker_repo) on Docker Hub" + local readme_filepath="./README.md" + local repo_url="https://hub.docker.com/v2/repositories/$(docker_repo)/" + local response_code=$(curl -s --write-out %{response_code} --output /dev/null -H "Authorization: JWT ${token}" -X PATCH --data-urlencode full_description@${readme_filepath} ${repo_url}) + + if [ $response_code -eq 200 ]; then + echo "Successfully updated README for $(docker_repo) on Docker Hub" + else + echo "Failed to update README for $(docker_repo) on Docker Hub (Response code: $response_code)" >&2 + exit 1 + fi +} + +prepare_builder() { + if [ "$BUILDER" == "" ]; then + (docker buildx inspect builder &> /dev/null && echo -e "\nReusing existing builder") || \ + (docker buildx create --name builder --use &> /dev/null && echo -e "\nCreated builder") + BUILDER="builder" + fi +} + +build() { + prepare_builder + + local openhab_version="${1/SNAPSHOT/snapshot}" + local dist="$2" + local push="$3" + + local java_version="" + case $openhab_version in + 2.*) java_version="8";; + *) java_version="11";; + esac + + 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" + local tags=$(tags $openhab_version $dist) + local tag_options=${tags//$(docker_repo)/--tag $(docker_repo)} + local build_options="$build_arg_options --platform $(platforms $openhab_version $dist) $tag_options --progress plain $push" + local dockerfile_path="./$dist" + local build_command="docker buildx build $build_options $dockerfile_path" + + echo + echo "Building openHAB $openhab_version $dist Docker image" + echo + set -x + + $build_command + + { set +x; } 2> /dev/null + echo +} diff --git a/openhab-update.sh b/openhab-update.sh deleted file mode 100755 index 55789ab..0000000 --- a/openhab-update.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/sh - -setup() { - # Ask to run as root to prevent us from running sudo in this script. - if [ "$(id -u)" -ne 0 ]; then - echo "Please run this script as root! (e.g. use sudo)" >&2 - exit 1 - fi - - current_version="$(awk '/openhab-distro/{print $3}' "${OPENHAB_USERDATA}/etc/version.properties")" - oh_version="$(echo "${OPENHAB_VERSION}" | sed 's/snapshot/SNAPSHOT/')" - milestone_version="$(echo "${oh_version}" | awk -F'.' '{print $4}')" - - # Choose bintray for releases, jenkins for snapshots and artifactory for milestones or release candidates. - if test "${oh_version#*-SNAPSHOT}" != "${oh_version}"; then - addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons-legacy/target/openhab-addons-legacy-${oh_version}.kar" - elif [ "${oh_version}" = "$current_version" ]; then - echo "You are already on openHAB $current_version" >&2 - exit 1 - elif [ -n "$milestone_version" ]; then - addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons/${oh_version}/openhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab-addons-legacy/${oh_version}/openhab-addons-legacy-${oh_version}.kar" - else - addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons%2F${oh_version}%2Fopenhab-addons-${oh_version}.kar" - legacy_addons_download_location="https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab-addons-legacy%2F${oh_version}%2Fopenhab-addons-legacy-${oh_version}.kar" - fi -} - -run_command() { - string="$1" - string="$(echo "$string" | sed "s:\$OPENHAB_USERDATA:${OPENHAB_USERDATA:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_CONF:${OPENHAB_CONF:?}:g")" - string="$(echo "$string" | sed "s:\$OPENHAB_HOME:${OPENHAB_HOME:?}:g")" - - command="$(echo "$string" | awk -F';' '{print $1}')" - param1="$(echo "$string" | awk -F';' '{print $2}')" - param2="$(echo "$string" | awk -F';' '{print $3}')" - param3="$(echo "$string" | awk -F';' '{print $4}')" - - case $command in - 'DEFAULT') - if [ -f "$param1" ]; then - echo " Adding '.bak' to $param1" - mv "$param1" "$param1.bak" - fi - echo " Using default file $param1" - cp "$(echo "$param1" | sed "s:${OPENHAB_HOME}:${OPENHAB_HOME}/dist:g")" "$param1" - ;; - 'DELETE') - # We should be strict and specific here, i.e only delete one file. - if [ -f "$param1" ]; then - echo " Deleting File: $param1" - rm -f "$param1" - fi - ;; - 'DELETEDIR') - # We should be strict and specific here, i.e only delete one directory. - if [ -d "$param1" ]; then - echo " Deleting Directory: $param1" - rm -rf "$param1" - fi - ;; - 'MOVE') - # Avoid error if file or directory does not exist - if [ -e "$param1" ]; then - echo " Moving: From $param1 to $param2" - file_dir=$(dirname "$param2") - # Create directory with same ownership as file - if [ ! -d file_dir ]; then - mkdir -p "$file_dir" - prev_user_group=$(ls -ld "$param1" | awk '{print $3 ":" $4}') - chown -R "$prev_user_group" "$file_dir" - fi - mv "$param1" "$param2" - fi - ;; - 'REPLACE') - # Avoid error if file does not exist - if [ -f "$param3" ]; then - echo " Replacing: String $param1 to $param2 in file $param3" - sed -i "s:$param1:$param2:g" "$param3" - fi - ;; - 'NOTE') printf ' \033[32mNote:\033[m %s\n' "$param1";; - 'ALERT') printf ' \033[31mWarning:\033[m %s\n' "$param1";; - esac -} - -get_version_number() { - first_part="$(echo "$1" | awk -F'.' '{print $1}')" - second_part="$(echo "$1" | awk -F'.' '{print $2}')" - third_part="$(echo "$1" | awk -F'.' '{print $3}')" - third_part="${third_part%%-*}" - echo $((first_part*10000+second_part*100+third_part)) -} - -scan_versioning_list() { - section="$1" - version_message="$2" - in_section=false - in_new_version=false - - # Read the file line by line. - while IFS= read -r line - do - case $line in - '') - continue - ;; - # Flag to run the relevant [[section]] only. - "[[$section]]") - in_section=true - ;; - # Stop reading the file if another [[section]] starts. - "[["*"]]") - if $in_section; then - break - fi - ;; - # Detect the [version] and execute the line if relevant. - '['*'.'*'.'*']') - if $in_section; then - line_version="$(echo "$line" | awk -F'[][]' '{print $2}')" - line_version_number=$(get_version_number "$line_version") - if [ "$current_version_number" -lt "$line_version_number" ]; then - in_new_version=true - echo "" - echo "$version_message $line_version:" - else - in_new_version=false - fi - fi - ;; - *) - if $in_section && $in_new_version; then - run_command "$line" - fi - ;; - esac - done < "${OPENHAB_HOME}/runtime/bin/update.lst" -} - -echo "" -echo "################################################" -echo " openHAB Docker update script " -echo "################################################" -echo "" - -# Run the initialisation functions defined above -setup - -current_version_number=$(get_version_number "$current_version") -case $current_version in - *"-"* | *"."*"."*"."*) current_version_number=$((current_version_number-1));; -esac - -# Notify the user of important changes first -echo "The script will attempt to update openHAB to version ${oh_version}" -printf 'Please read the following \033[32mnotes\033[m and \033[31mwarnings\033[m:\n' -scan_versioning_list "MSG" "Important notes for version" -echo "" - -# Perform version specific pre-update commands -scan_versioning_list "PRE" "Performing pre-update tasks for version" - -echo "Replacing userdata system files with newer versions..." -while IFS= read -r file_name -do - full_path="${OPENHAB_HOME}/dist/userdata/etc/${file_name}" - if [ -f "$full_path" ]; then - cp "$full_path" "${OPENHAB_USERDATA}/etc/" - fi -done < "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" - -# Clearing the cache and tmp folders is necessary for upgrade. -echo "Clearing cache..." -rm -rf "${OPENHAB_USERDATA:?}/cache" -rm -rf "${OPENHAB_USERDATA:?}/tmp" - -# Perform version specific post-update commands -scan_versioning_list "POST" "Performing post-update tasks for version" - -# If there's an existing addons file, we need to replace it with the correct version. -addons_file="${OPENHAB_HOME}/addons/openhab-addons-${current_version}.kar" -if [ -f "$addons_file" ]; then - echo "Found an openHAB addons file, replacing with new version..." - rm -f "${addons_file:?}" - curl -Lf# "$addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-${oh_version}.kar" || { - echo "Download of addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi - -# Do the same for the legacy addons file. -legacy_addons_file="${OPENHAB_HOME}/addons/openhab-addons-legacy-${current_version}.kar" -if [ -f "$legacy_addons_file" ]; then - echo "Found an openHAB legacy addons file, replacing with new version..." - rm -f "${legacy_addons_file:?}" - curl -Lf# "$legacy_addons_download_location" -o "${OPENHAB_HOME}/addons/openhab-addons-legacy-${oh_version}.kar" || { - echo "Download of legacy addons file failed, please find it on the openHAB website (www.openhab.org)" >&2 - } -fi -echo "" - -echo "" -echo "SUCCESS: openHAB updated from ${current_version} to ${oh_version}" -echo "" diff --git a/images/openhab.png b/openhab.png similarity index 100% rename from images/openhab.png rename to openhab.png diff --git a/sync-docker-hub-readme.sh b/sync-docker-hub-readme.sh deleted file mode 100755 index 9da41d6..0000000 --- a/sync-docker-hub-readme.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# This script is based on the GitHub Docker Hub Description action. -# See: https://github.com/peter-evans/dockerhub-description/blob/master/entrypoint.sh - -# Acquire token for Docker Hub API -LOGIN_PAYLOAD="{\"username\": \"${DOCKER_USERNAME}\", \"password\": \"${DOCKER_PASSWORD}\"}" -TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "${LOGIN_PAYLOAD}" https://hub.docker.com/v2/users/login/ | jq -r .token) - -# Send a PATCH request to update the description of the repository -echo "Updating README for $DOCKER_REPO on Docker Hub" -README_FILEPATH="./README.md" -REPO_URL="https://hub.docker.com/v2/repositories/${DOCKER_REPO}/" -RESPONSE_CODE=$(curl -s --write-out %{response_code} --output /dev/null -H "Authorization: JWT ${TOKEN}" -X PATCH --data-urlencode full_description@${README_FILEPATH} ${REPO_URL}) - -if [ $RESPONSE_CODE -eq 200 ]; then - echo "Successfully updated README for $DOCKER_REPO on Docker Hub" - exit 0 -else - echo "Failed to update README for $DOCKER_REPO on Docker Hub (Response code: $RESPONSE_CODE)" - exit 1 -fi diff --git a/update-docker-files.sh b/update-docker-files.sh deleted file mode 100755 index 7097870..0000000 --- a/update-docker-files.sh +++ /dev/null @@ -1,351 +0,0 @@ -#!/bin/bash -set -eo pipefail - -. update-functions.sh - -# Distribution download URLs -openhab_release_url='https://bintray.com/openhab/mvn/download_file?file_path=org%2Fopenhab%2Fdistro%2Fopenhab%2F${version}%2Fopenhab-${version}.zip' -openhab_milestone_url='https://openhab.jfrog.io/openhab/libs-milestone-local/org/openhab/distro/openhab/${version}/openhab-${version}.zip' -openhab2_snapshot_url='https://ci.openhab.org/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip' -openhab3_snapshot_url='https://ci.openhab.org/job/openHAB3-Distribution/lastSuccessfulBuild/artifact/distributions/openhab/target/openhab-${version}.zip' - -# Zulu 8 download URLs -zulu8_amd64_url='https://cdn.azul.com/zulu/bin/zulu8.50.0.51-ca-jdk8.0.275-linux_x64.tar.gz' -zulu8_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch32hf.tar.gz' -zulu8_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu8.50.51.263-ca-jdk8.0.275-linux_aarch64.tar.gz' - -# Zulu 11 download URLs -zulu11_amd64_url='https://cdn.azul.com/zulu/bin/zulu11.43.21-ca-jdk11.0.9-linux_x64.tar.gz' -zulu11_armhf_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch32hf.tar.gz' -zulu11_arm64_url='https://cdn.azul.com/zulu-embedded/bin/zulu11.43.88-ca-jdk11.0.9-linux_aarch64.tar.gz' - -zulu_url_vars=(zulu8_amd64_url zulu8_armhf_url zulu8_arm64_url zulu11_amd64_url zulu11_armhf_url zulu11_arm64_url) - -# Generate header -print_header() { - cat > $1 <<-EOI - # openhab image - # - # ------------------------------------------------------------------------------ - # NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" - # - # PLEASE DO NOT EDIT IT DIRECTLY. - # ------------------------------------------------------------------------------ - # -EOI -} - -# Print selected image -print_baseimage() { - # Set Java version based on openHAB versions - case $version in - 2.*) java_version="8";; - 3.*) java_version="11";; - *) java_version="error";; - esac - - # Set Docker base image based on distributions - case $base in - alpine) base_image="alpine:3.12.2";; - debian) base_image="debian:10.7-slim";; - *) base_image="error";; - esac - - cat >> $1 <<-EOI - FROM $base_image - - # Set version variables - ENV \\ - JAVA_VERSION="$java_version" \\ - OPENHAB_VERSION="$version" - -EOI -} - -# Print metadata -print_basemetadata() { - cat >> $1 <<-'EOI' - # Set other variables - ENV \ - CRYPTO_POLICY="limited" \ - EXTRA_JAVA_OPTS="" \ - GROUP_ID="9001" \ - KARAF_EXEC="exec" \ - LC_ALL="en_US.UTF-8" \ - LANG="en_US.UTF-8" \ - LANGUAGE="en_US.UTF-8" \ - OPENHAB_BACKUPS="/openhab/userdata/backup" \ - OPENHAB_CONF="/openhab/conf" \ - OPENHAB_HOME="/openhab" \ - OPENHAB_HTTP_PORT="8080" \ - OPENHAB_HTTPS_PORT="8443" \ - OPENHAB_LOGDIR="/openhab/userdata/logs" \ - OPENHAB_USERDATA="/openhab/userdata" \ - USER_ID="9001" - - # Set arguments on build - ARG BUILD_DATE - ARG VCS_REF - ARG VERSION - - # Basic build-time metadata as defined at http://label-schema.org - LABEL org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.docker.dockerfile="/Dockerfile" \ - org.label-schema.license="EPL-2.0" \ - org.label-schema.name="openHAB" \ - org.label-schema.vendor="openHAB Foundation e.V." \ - org.label-schema.version=$VERSION \ - org.label-schema.description="An open source, technology agnostic home automation platform" \ - org.label-schema.url="https://www.openhab.com/" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vcs-type="Git" \ - org.label-schema.vcs-url="https://github.com/openhab/openhab-docker.git" \ - maintainer="openHAB " - -EOI -} - -# Print basepackages for Alpine -print_basepackages_alpine() { - cat >> $1 <<-'EOI' - # Install basepackages - RUN apk update --no-cache && \ - apk add --no-cache \ - arping \ - bash \ - ca-certificates \ - curl \ - fontconfig \ - libcap \ - nss \ - shadow \ - su-exec \ - tini \ - ttf-dejavu \ - openjdk${JAVA_VERSION} \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - rm -rf /var/cache/apk/* - -EOI -} - -# Print basepackages for Debian -print_basepackages_debian() { - cat >> $1 <<-'EOI' - # Install basepackages - RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ - arping \ - ca-certificates \ - curl \ - fontconfig \ - gosu \ - libcap2-bin \ - locales \ - locales-all \ - netbase \ - procps \ - tini \ - unzip \ - wget \ - zip && \ - chmod u+s /usr/sbin/arping && \ - ln -s -f /bin/true /usr/bin/chfn && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -EOI -} - -# Configure Java for Alpine -print_java_alpine() { - cat >> $1 <<-'EOI' - # Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography - ENV JAVA_HOME='/usr/lib/jvm/default-jvm' - RUN if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi - -EOI -} - -# Install Java for Debian -print_java_debian() { - cat >> $1 <<-'EOI' - # Install java - ENV JAVA_HOME='/usr/lib/jvm/default-jvm' - # Limit JDK crypto policy by default to comply with local laws which may prohibit use of unlimited strength cryptography - RUN mkdir -p "${JAVA_HOME}" && \ -EOI - - for zulu_url_var in ${zulu_url_vars[@]} - do - cat >> $1 <<-EOI - $zulu_url_var='${!zulu_url_var}' && \\ -EOI - done - - cat >> $1 <<-'EOI' - url_var="zulu${JAVA_VERSION}_$(dpkg --print-architecture)_url" && \ - eval "java_url=\$$url_var" && \ - wget -nv -O /tmp/java.tar.gz "${java_url}" && \ - tar --exclude='demo' --exclude='sample' --exclude='src.zip' -xf /tmp/java.tar.gz --strip-components=1 -C "${JAVA_HOME}" && \ - if [ "${JAVA_VERSION}" = "8" ]; then \ - sed -i 's/^#crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/jre/lib/security/java.security"; \ - elif [ "${JAVA_VERSION}" = "11" ]; then \ - sed -i 's/^crypto.policy=unlimited/crypto.policy=limited/' "${JAVA_HOME}/conf/security/java.security"; \ - fi && \ - rm /tmp/java.tar.gz && \ - update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 50 && \ - update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 50 - -EOI -} - -print_openhab_install() { - case $version in - *.M*|*.RC*) - openhab_url=$(eval "echo $openhab_milestone_url") - ;; - 2.*-snapshot) - openhab_url=$(eval "echo $openhab2_snapshot_url" | sed 's/snapshot/SNAPSHOT/g') - ;; - 3.*-snapshot) - openhab_url=$(eval "echo $openhab3_snapshot_url" | sed 's/snapshot/SNAPSHOT/g') - ;; - *) - openhab_url=$(eval "echo $openhab_release_url") - ;; - esac - - cat >> $1 <<-'EOI' - # Install openHAB - # Set permissions for openHAB. Export TERM variable. See issue #30 for details! -EOI - - cat >> $1 <<-EOI - RUN wget -nv -O /tmp/openhab.zip "${openhab_url}" && \\ -EOI - - cat >> $1 <<-'EOI' - unzip -q /tmp/openhab.zip -d "${OPENHAB_HOME}" -x "*.bat" "*.ps1" "*.psm1" && \ - rm /tmp/openhab.zip && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/update.lst" ]; then touch "${OPENHAB_HOME}/runtime/bin/update.lst"; fi && \ - if [ ! -f "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" ]; then wget -nv -O "${OPENHAB_HOME}/runtime/bin/userdata_sysfiles.lst" "https://raw.githubusercontent.com/openhab/openhab-distro/2.4.0/distributions/openhab/src/main/resources/bin/userdata_sysfiles.lst"; fi && \ - mkdir -p "${OPENHAB_LOGDIR}" && \ - touch "${OPENHAB_LOGDIR}/openhab.log" && \ - mkdir -p "${OPENHAB_HOME}/dist" && \ - cp -a "${OPENHAB_CONF}" "${OPENHAB_USERDATA}" "${OPENHAB_HOME}/dist" && \ - echo 'export TERM=${TERM:=dumb}' | tee -a ~/.bashrc - COPY update.sh ${OPENHAB_HOME}/runtime/bin/update - RUN chmod +x ${OPENHAB_HOME}/runtime/bin/update - -EOI -} - -# Add volumes for openHAB -print_volumes() { - cat >> $1 <<-'EOI' - # Expose volume with configuration and userdata dir - VOLUME ${OPENHAB_CONF} ${OPENHAB_USERDATA} ${OPENHAB_HOME}/addons - -EOI -} - -print_expose_ports() { - cat >> $1 <<-'EOI' - # Expose HTTP, HTTPS, Console and LSP ports - EXPOSE 8080 8443 8101 5007 - -EOI -} - -# Set working directory and entrypoint -print_entrypoint() { - cat >> $1 <<-'EOI' - # Set working directory and entrypoint - WORKDIR ${OPENHAB_HOME} - COPY entrypoint.sh / - RUN chmod +x /entrypoint.sh - ENTRYPOINT ["/entrypoint.sh"] - - # Execute command -EOI -} - -# Set command -print_command() { - case $base in - alpine) - cat >> $1 <<-'EOI' - CMD ["su-exec", "openhab", "tini", "-s", "./start.sh"] - EOI - ;; - debian) - cat >> $1 <<-'EOI' - CMD ["gosu", "openhab", "tini", "-s", "./start.sh"] - EOI - ;; - *) - cat >> $1 <<-'EOI' - CMD ["./start.sh"] - EOI - ;; - esac -} - -# Generate Dockerfile -generate_docker_file() { - file="$version/$base/Dockerfile" - mkdir -p $(dirname $file) 2>/dev/null - echo -n "Writing $file... " - print_header $file; - print_baseimage $file; - print_basemetadata $file; - - case $base in - alpine) - print_basepackages_alpine $file; - print_java_alpine $file; - ;; - debian) - print_basepackages_debian $file; - print_java_debian $file; - ;; - esac - - print_openhab_install $file; - print_volumes $file - print_expose_ports $file - print_entrypoint $file - print_command $file - - echo "done" -} - -# Remove previously generated container files -rm -rf ./2.* ./3.* - -# Generate new container files -for version in $(build_versions) -do - for base in $(bases) - do - # Generate Dockerfile - generate_docker_file - - # Copy base specific entrypoint.sh - case $base in - alpine) cp "entrypoint-alpine.sh" "$version/$base/entrypoint.sh";; - debian) cp "entrypoint-debian.sh" "$version/$base/entrypoint.sh";; - esac - - # Copy update script - cp "openhab-update.sh" "$version/$base/update.sh" - done -done diff --git a/update-functions.sh b/update-functions.sh deleted file mode 100755 index 9402d74..0000000 --- a/update-functions.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/bash -set -eo pipefail - -# Supported base images -bases() { - echo "alpine debian" -} - -docker_repo() { - echo "${DOCKER_REPO:=openhab/openhab}" -} - -# Supported Docker platforms -platforms() { - version="$1" - base="$2" - - if [[ "$version" =~ ^3.*$ ]] && [ "$base" == "alpine" ]; then - # There is no linux/arm/v7 Alpine image for openHAB 3 because the openjdk11 package is unavailable for this architecture - echo "linux/amd64,linux/arm64" - else - echo "linux/amd64,linux/arm64,linux/arm/v7" - fi -} - -tags() { - version="$1" - base="$2" - - tags=() - - if [ "$base" == "debian" ]; then - tags+=("$(docker_repo):$version") - fi - - tags+=("$(docker_repo):$version-$base") - - if [ "$version" == "$(last_stable_version)" ]; then - if [ "$base" == "debian" ]; then - tags+=("$(docker_repo):latest") - fi - tags+=("$(docker_repo):latest-$base") - fi - - milestone_maturity_version="$(last_milestone_version)" - if [ "$milestone_maturity_version" == "" ]; then - milestone_maturity_version="$(last_stable_version)" - fi - - if [ "$version" == "$milestone_maturity_version" ]; then - if [ "$base" == "debian" ]; then - tags+=("$(docker_repo):milestone") - fi - tags+=("$(docker_repo):milestone-$base") - fi - - if [ "$version" == "$(last_snapshot_version)" ]; then - if [ "$base" == "debian" ]; then - tags+=("$(docker_repo):snapshot") - fi - tags+=("$(docker_repo):snapshot-$base") - fi - - echo $(IFS=' '; echo "${tags[*]}") -} - -last_stable_version() { - grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' versions | sort --unique --version-sort | tail -n 1 -} - -stable_versions() { - grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' versions | sort --unique --version-sort -} - -stable_minor_versions() { - grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' versions | sed -E 's/^([0-9]+\.[0-9]+).+/\1/' | sort --unique --version-sort -} - -snapshot_versions() { - grep -E '^[0-9]+\.[0-9]+\.[0-9]+-snapshot$' versions | sort --unique --version-sort || echo "" -} - -last_snapshot_version() { - grep -E '^[0-9]+\.[0-9]+\.[0-9]+-snapshot$' versions | sort --unique --version-sort | tail -n 1 || echo "" -} - -next_stable_version() { - sed 's/-snapshot//' <<< $(last_snapshot_version) -} - -milestone_versions() { - grep -E "$(next_stable_version)\.(M|RC)[0-9]+$" versions | sort --unique --version-sort | tail -n 3 || echo "" -} - -last_milestone_version() { - grep -E "$(next_stable_version)\.(M|RC)[0-9]+$" versions | sort --unique --version-sort | tail -n 1 || echo "" -} - -build_versions() { - stable_minor1="$(stable_minor_versions | tail -n 3 | head -n 1)" - stable_minor2="$(stable_minor_versions | tail -n 2 | head -n 1)" - stable_minor3="$(stable_minor_versions | tail -n 1)" - build_stable_minor1="$(stable_versions | grep -E "^$stable_minor1" | tail -n 1)" - build_stable_minor2="$(stable_versions | grep -E "^$stable_minor2" | tail -n 1)" - build_stable_minor3="$(stable_versions | grep -E "^$stable_minor3" | tail -n 3 | xargs)" - echo "$build_stable_minor1 $build_stable_minor2 $build_stable_minor3 $(milestone_versions) $(snapshot_versions)" -} - -validate_readme_constraints() { - count=$(wc -m $file.new && mv $file.new $file -} - -update_last_stable_version() { - sed -i "s#openhab/openhab:[0-9]*\.[0-9]*\.[0-9]*#openhab/openhab:$(last_stable_version)#g" $file -} - -echo -n "Writing $file... " - -update_version_list -update_last_stable_version -validate_readme_constraints - -echo "done" diff --git a/update.sh b/update.sh deleted file mode 100755 index 936964f..0000000 --- a/update.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -eo pipefail - -./update-docker-files.sh -./update-readme.sh diff --git a/versions b/versions deleted file mode 100644 index d8b6c43..0000000 --- a/versions +++ /dev/null @@ -1,41 +0,0 @@ -2.2.0 -2.3.0 -2.4.0.M1 -2.4.0.M2 -2.4.0.M3 -2.4.0.M4 -2.4.0.M5 -2.4.0.M6 -2.4.0.M7 -2.4.0.M8 -2.4.0.RC1 -2.4.0 -2.5.0.M1 -2.5.0.M2 -2.5.0.M3 -2.5.0.M4 -2.5.0.M5 -2.5.0.M6 -2.5.0.RC1 -2.5.0 -2.5.1 -2.5.2 -2.5.3 -2.5.4 -2.5.5 -2.5.6 -2.5.7 -2.5.8 -2.5.9 -2.5.10 -2.5.11 -2.5.12-snapshot -3.0.0.M1 -3.0.0.M2 -3.0.0.M3 -3.0.0.M4 -3.0.0.M5 -3.0.0.RC1 -3.0.0.RC2 -3.0.0 -3.1.0-snapshot