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@maindrain.net>
pull/337/head
Wouter Born 2021-01-01 16:00:25 +01:00 committed by GitHub
parent 49ddec986d
commit 69b2534052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 485 additions and 4536 deletions

30
.github/workflows/build-images.yml vendored Normal file
View File

@ -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 }}

19
.github/workflows/validate-readme.yml vendored Normal file
View File

@ -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'

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

View File

@ -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

View File

@ -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 ""

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

View File

@ -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 <info@openhabfoundation.org>"
# 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"]

View File

@ -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

View File

@ -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 ""

111
README.md
View File

@ -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)

View File

@ -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"]

105
build Executable file
View File

@ -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

View File

@ -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"]

View File

@ -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

View File

@ -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

241
helper-functions Normal file
View File

@ -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 '^ <version>' | grep 'SNAPSHOT' | sed -E 's#.+<version>(.+)-SNAPSHOT</version>#\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 <README.md)
if [ $count -gt 25000 ]; then
echo "README.md contains $count characters which exceeds the 25000 character limit of Docker Hub" >&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
}

View File

@ -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 ""

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -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

View File

@ -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 <info@openhabfoundation.org>"
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

View File

@ -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 <README.md)
if [ $count -gt 25000 ]; then
echo "README.md contains $count characters which exceeds the 25000 character limit of Docker Hub"
exit 1
fi
}

View File

@ -1,56 +0,0 @@
#!/bin/bash
set -eo pipefail
. update-functions.sh
file=README.md
dockerfile_url='https://github.com/openhab/openhab-docker/blob/master/${version}/debian/Dockerfile'
generate_version_list() {
for version in $(build_versions)
do
url=$(eval "echo $dockerfile_url")
case $version in
2.*.M*|2.*.RC*|3.*.M*|3.*.RC*)
echo "* \`$version\` Experimental openHAB $version Milestone version ([Dockerfile]($url))"
;;
2.*-snapshot|3.*-snapshot)
echo "* \`$version\` Experimental openHAB $(echo $version | sed 's/-snapshot/ SNAPSHOT/g') version ([Dockerfile]($url))"
;;
2.5.*)
echo "* \`2.5.0\` - \`$version\` Stable openHAB $(echo $version | sed -E 's/^([0-9]+)\.([0-9])+\.([0-9])+$/\1\.\2\.x/g') version ([Dockerfile]($url))"
;;
*)
echo "* \`$version\` Stable openHAB $version version ([Dockerfile]($url))"
;;
esac
done
}
update_version_list() {
generate="false"
while IFS= read -r line
do
if [[ $line =~ ^.*\(\[Dockerfile\]\(https://github.com/openhab/openhab-docker/blob/master/.+/debian/Dockerfile\)\)$ ]]; then
generate="true"
else
if [ "$generate" == "true" ]; then
generate="false"
generate_version_list
fi
echo "$line"
fi
done < $file > $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"

View File

@ -1,5 +0,0 @@
#!/bin/bash
set -eo pipefail
./update-docker-files.sh
./update-readme.sh

View File

@ -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