diff --git a/config/functions b/config/functions index 86ac2d34a7..fea494a8e2 100644 --- a/config/functions +++ b/config/functions @@ -224,11 +224,13 @@ enable_service () { local target_dir=$INSTALL [ -f "$target_dir/$unit_dir/$unit" ] || exit 1 - [ -z "$target" ] && target=`grep '^WantedBy' $target_dir/$unit_dir/$unit | cut -f2 -d=` - - if [ -n "$target" ]; then - mkdir -p ${target_dir}/$unit_dir/${target}.wants - ln -sf ../${unit} ${target_dir}/$unit_dir/${target}.wants/ + if [ -z "$target" ] ; then + for target in `grep '^WantedBy' $target_dir/$unit_dir/$unit | cut -f2 -d=` ; do + if [ -n "$target" ]; then + mkdir -p ${target_dir}/$unit_dir/${target}.wants + ln -sf ../${unit} ${target_dir}/$unit_dir/${target}.wants/ + fi + done fi } diff --git a/packages/sysutils/entropy/package.mk b/packages/sysutils/entropy/package.mk new file mode 100644 index 0000000000..daf45f57fa --- /dev/null +++ b/packages/sysutils/entropy/package.mk @@ -0,0 +1,50 @@ +################################################################################ +# This file is part of OpenELEC - http://www.openelec.tv +# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv) +# +# OpenELEC 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. +# +# OpenELEC 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 OpenELEC. If not, see . +################################################################################ + +PKG_NAME="entropy" +PKG_VERSION="0" +PKG_REV="1" +PKG_ARCH="any" +PKG_LICENSE="GPL" +PKG_SITE="" +PKG_URL="" +PKG_DEPENDS_TARGET="toolchain" +PKG_PRIORITY="optional" +PKG_SECTION="system" +PKG_SHORTDESC="A simple way to add entropy at boot" +PKG_LONGDESC="A simple way to add entropy at boot" + +PKG_IS_ADDON="no" +PKG_AUTORECONF="no" + +make_target(){ + : +} + +makeinstall_target() { + mkdir -p $INSTALL/usr/lib/entropy + cp add-entropy $INSTALL/usr/lib/entropy + cp add-random-at-shutdown $INSTALL/usr/lib/entropy + + chmod +x $INSTALL/usr/lib/entropy/* +} + +post_install() { + enable_service add-entropy.service + enable_service add-random-at-shutdown.service +} diff --git a/packages/sysutils/entropy/sources/add-entropy b/packages/sysutils/entropy/sources/add-entropy new file mode 100644 index 0000000000..e3af8fab48 --- /dev/null +++ b/packages/sysutils/entropy/sources/add-entropy @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import os +import struct + +RNDADDENTROPY = 0x40085203 +import fcntl + +def add_entropy(fd, data): + add = struct.pack('ii', len(data)*8, len(data)) + data + fcntl.ioctl(fd, RNDADDENTROPY, add) + +if not os.path.isfile("/storage/.cache/random.data"): + os.system("dd if=/dev/urandom of=/storage/.cache/random.data count=4 >/dev/null") + +cache=os.open("/storage/.cache/random.data", os.O_RDONLY) + +rnd=os.open("/dev/random", os.O_RDWR) + +while True: + data=os.read(cache, 512) + if len(data) == 0: + break + add_entropy(rnd, data) diff --git a/packages/sysutils/entropy/sources/add-random-at-shutdown b/packages/sysutils/entropy/sources/add-random-at-shutdown new file mode 100644 index 0000000000..967712e5a6 --- /dev/null +++ b/packages/sysutils/entropy/sources/add-random-at-shutdown @@ -0,0 +1,2 @@ +#!/bin/sh +dd if=/dev/urandom of=/storage/.cache/random.data count=4 diff --git a/packages/sysutils/entropy/system.d/add-entropy.service b/packages/sysutils/entropy/system.d/add-entropy.service new file mode 100644 index 0000000000..ddfb1bec31 --- /dev/null +++ b/packages/sysutils/entropy/system.d/add-entropy.service @@ -0,0 +1,13 @@ +[Unit] +Description=Add random entropy from file +DefaultDependencies=no +After=systemd-tmpfiles-setup.service +Before=systemd-udevd.service + +[Service] +Type=oneshot +ExecStart=/usr/lib/entropy/add-entropy +RemainAfterExit=yes + +[Install] +WantedBy=basic.target diff --git a/packages/sysutils/entropy/system.d/add-random-at-shutdown.service b/packages/sysutils/entropy/system.d/add-random-at-shutdown.service new file mode 100644 index 0000000000..61ab2f7243 --- /dev/null +++ b/packages/sysutils/entropy/system.d/add-random-at-shutdown.service @@ -0,0 +1,12 @@ +[Unit] +Description=Save random entropy at shutdown +DefaultDependencies=no +Before=systemd-poweroff.service systemd-reboot.service systemd-halt.service + +[Service] +Type=oneshot +ExecStart=/usr/lib/entropy/add-random-at-shutdown +RemainAfterExit=yes + +[Install] +WantedBy=poweroff.target reboot.target halt.target diff --git a/packages/sysutils/systemd/package.mk b/packages/sysutils/systemd/package.mk index 94cbd41ac8..c23a72a568 100644 --- a/packages/sysutils/systemd/package.mk +++ b/packages/sysutils/systemd/package.mk @@ -23,7 +23,7 @@ PKG_ARCH="any" PKG_LICENSE="GPL" PKG_SITE="http://www.freedesktop.org/wiki/Software/systemd" PKG_URL="http://www.freedesktop.org/software/systemd/$PKG_NAME-$PKG_VERSION.tar.xz" -PKG_DEPENDS_TARGET="toolchain libcap kmod util-linux" +PKG_DEPENDS_TARGET="toolchain libcap kmod util-linux entropy" PKG_PRIORITY="required" PKG_SECTION="system" PKG_SHORTDESC="systemd: a system and session manager"