script: create_docker_package

This commit is contained in:
awiouy 2016-10-22 14:29:18 +02:00
parent 5c9861db71
commit 62cd1c76b7
8 changed files with 321 additions and 0 deletions

View File

@ -0,0 +1,2 @@
100
- Initial addon

45
config/docker/package.mk Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
################################################################################
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() {
: #
}

View File

@ -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 <http://www.gnu.org/licenses/>.
################################################################################
name="$(basename $0)"
. /etc/profile
oe_setup_addon "$name"
docker rm "$name" 2>/dev/null
docker run --name="$name" \

View File

@ -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 <http://www.gnu.org/licenses/>.
################################################################################
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()

View File

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

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category label="30000">
<setting label="30001" type="lsep" />
@SETTINGS@ </category>
</settings>

View File

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

184
scripts/create_docker_package Executable file
View File

@ -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 <setting id=\"$1\" value=\"$2\" />\n"
}
add_device() {
add_label
default="${1%:*}"
docker="${1#*:}"
id="$LABEL_DEVICE${docker//\//_}"
add_default "$id" "$default"
add_option "--device=\"\$$id\""
add_setting "<setting label=\"$label\" type=\"folder\" id=\"$id\" default=\"$default\" />"
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 "<setting label=\"$label\" type=\"text\" id=\"$id\" default=\"$default\" />"
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 "<setting label=\"$label\" type=\"number\" id=\"$id\" default=\"$default\" />"
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 "<setting label=\"$label\" type=\"folder\" id=\"$id\" default=\"$default\" />"
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 "<settings>\n$defaults\n</settings>" > "$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"