diff --git a/config/docker/changelog.txt b/config/docker/changelog.txt new file mode 100644 index 0000000000..ffbebe8438 --- /dev/null +++ b/config/docker/changelog.txt @@ -0,0 +1,2 @@ +100 +- Initial addon diff --git a/config/docker/package.mk b/config/docker/package.mk new file mode 100644 index 0000000000..91d7fcb5ed --- /dev/null +++ b/config/docker/package.mk @@ -0,0 +1,45 @@ +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2016 Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +PKG_NAME="@NAME@" +PKG_VERSION="@VERSION@" # Update bin/docker.@NAME@ accordingly +PKG_REV="100" +PKG_ARCH="@ARCH@" +PKG_DEPENDS_TARGET="toolchain" +PKG_SECTION="docker" +PKG_SITE="" +PKG_SHORTDESC="" +PKG_LONGDESC="" + +PKG_IS_ADDON="yes" +PKG_ADDON_NAME=" (@IMAGE@:$PKG_VERSION)" +PKG_ADDON_PROJECTS="@PROJECTS@" +PKG_ADDON_REQUIRES="service.system.docker:0.0.0" +PKG_ADDON_TYPE="xbmc.service" + +make_target() { + : # +} + +makeinstall_target() { + : # +} + +addon() { + : # +} diff --git a/config/docker/source/bin/docker b/config/docker/source/bin/docker new file mode 100644 index 0000000000..c003a413f7 --- /dev/null +++ b/config/docker/source/bin/docker @@ -0,0 +1,25 @@ +#!/bin/sh +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2016 Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +name="$(basename $0)" +. /etc/profile +oe_setup_addon "$name" + +docker rm "$name" 2>/dev/null +docker run --name="$name" \ diff --git a/config/docker/source/default.py b/config/docker/source/default.py new file mode 100644 index 0000000000..6c6b84a8a5 --- /dev/null +++ b/config/docker/source/default.py @@ -0,0 +1,35 @@ +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2016 Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +import subprocess +import xbmc +import xbmcaddon + + +class Monitor(xbmc.Monitor): + + def __init__(self, *args, **kwargs): + xbmc.Monitor.__init__(self) + self.id = xbmcaddon.Addon().getAddonInfo('id') + + def onSettingsChanged(self): + subprocess.call(['systemctl', 'restart', self.id]) + + +if __name__ == '__main__': + Monitor().waitForAbort() diff --git a/config/docker/source/resources/language/English/strings.po b/config/docker/source/resources/language/English/strings.po new file mode 100644 index 0000000000..23c8b7c56e --- /dev/null +++ b/config/docker/source/resources/language/English/strings.po @@ -0,0 +1,10 @@ +msgid "" +msgstr "" + +msgctxt "#30000" +msgid "Configuration" +msgstr "" + +msgctxt "#30001" +msgid "Note: Kodi remote sources can not be used as Docker volume host sources" +msgstr "" diff --git a/config/docker/source/resources/settings.xml b/config/docker/source/resources/settings.xml new file mode 100644 index 0000000000..bafc603a73 --- /dev/null +++ b/config/docker/source/resources/settings.xml @@ -0,0 +1,6 @@ + + + + +@SETTINGS@ + diff --git a/config/docker/source/system.d/docker.service b/config/docker/source/system.d/docker.service new file mode 100644 index 0000000000..1250444d2b --- /dev/null +++ b/config/docker/source/system.d/docker.service @@ -0,0 +1,14 @@ +[Unit] +Description=%p container +Requires=service.system.docker.service +After=service.system.docker.service + +[Service] +Restart=always +RestartSec=10s +TimeoutStartSec=0 +ExecStart=/bin/sh /storage/.kodi/addons/%p/bin/%p +ExecStop=/storage/.kodi/addons/service.system.docker/bin/docker kill %p + +[Install] +WantedBy=multi-user.target diff --git a/scripts/create_docker_package b/scripts/create_docker_package new file mode 100755 index 0000000000..0bd841e086 --- /dev/null +++ b/scripts/create_docker_package @@ -0,0 +1,184 @@ +#!/bin/sh + +FIRST_LABEL=30002 + +LABEL_DEVICE="D" +LABEL_ENV="E_" +LABEL_PORT="P_" +LABEL_VOLUME="V" + +STRING_DEVICE="-d " +STRING_ENV="-e " +STRING_PORT="-p " +STRING_VOLUME="-v " + +add_default() { + defaults="$defaults \n" +} + +add_device() { + add_label + default="${1%:*}" + docker="${1#*:}" + id="$LABEL_DEVICE${docker//\//_}" + add_default "$id" "$default" + add_option "--device=\"\$$id\"" + add_setting "" + add_string "$STRING_DEVICE$docker" +} + +add_env() { + add_label + default="${1#*=}" + docker="${1%%=*}" + id="$LABEL_ENV$docker" + add_default "$id" "$default" + add_option "-e $docker=\"$id\"" + add_setting "" + add_string "$STRING_ENV$docker" +} + +add_label() { + if [ -z $label ]; then + label=$FIRST_LABEL + else + label=$((label+1)) + fi +} + +add_option() { + if [ ! -z "$options" ]; then + options="$options "'\\\n' + fi + options="$options $1" +} + +add_port() { + add_label + default="${1%:*}" + docker="${1#*:}" + port="${docker%/*}" + id="$LABEL_PORT$port" + add_default "$id" "$default" + add_option "-p \"\$$id\":$docker" + add_setting "" + add_string "$STRING_PORT$port" +} + +add_setting() { + settings="$settings $1\n" +} + +add_string() { + strings="$strings\nmsgctxt \"$label\"\nmsgid \"$1\"\nmsgstr \"\"\n" +} + +add_volume() { + add_label + default="${1%:*}" + docker="${1#*:}" + id="$LABEL_VOLUME${docker//\//_}" + add_default "$id" "$default" + add_option "-v \"\$$id\":$docker" + add_setting "" + add_string "$STRING_VOLUME$docker" +} + + +case "$ARCH" in + arm) + projects="imx6 RPi RPi2" + ;; + x86_64) + projects="Generic" + ;; + *) + echo "Unkown project" + exit 1 + ;; +esac + +while [[ $# -gt 0 ]]; do + option="$1" + shift + case "$option" in + --device=*) + add_device "${option#--device=}" + ;; + --name=*) + ;; + --port=*) + add_port "${option#--port=}" + ;; + --volume=*) + add_volume "${option#--volume=}" + ;; + -e) + add_env "$1" + shift + ;; + + -p) + add_port "$1" + shift + ;; + -v) + add_volume "$1" + shift + ;; + -*) + add_option "$option" + ;; + */*) + add_option "$option" + image="${option%:*}" + version="${option#*:}" + if [ "$version" = "$option" ]; then + version="latest" + fi + if [ ! -z "$*" ]; then + add_option "$*" + fi + break + ;; + *) + add_option "$option" + ;; + esac +done + +if [ -z "$image" ]; then + echo "Failed to parse image" + exit 1 +fi + +name="${image//\//.}" +dir="packages/addons/docker/$name" + +if [ -d "$dir" ]; then + echo "Package already exists" + exit 1 +fi + +cp -R config/docker "$dir" + +sed -e "s|@NAME@|$name|g" \ + -e "s|@VERSION@|$version|g" \ + -e "s|@ARCH@|$arch|g" \ + -e "s|@IMAGE@|$image|g" \ + -e "s|@PROJECTS@|$projects|g" \ + -i "$dir/package.mk" + + +defaults="$(echo -en "$defaults" | sort)" +echo -en "\n$defaults\n" > "$dir/source/settings-default.xml" + +echo -en "$options" >> "$dir/source/bin/docker" + +sed -e "s|@SETTINGS@|$settings|g" \ + -i "$dir/source/resources/settings.xml" + +echo -en "$strings" >> "$dir/source/resources/language/English/strings.po" + +mv "$dir/source/bin/docker" "$dir/source/bin/docker.$name" +mv "$dir/source/system.d/docker.service" "$dir/source/system.d/docker.$name.service"