summarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.SRCINFO20
-rw-r--r--PKGBUILD27
-rw-r--r--device-mapper.confd1
-rw-r--r--device-mapper.initd146
-rw-r--r--dmeventd.initd25
5 files changed, 219 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 00000000000..1b69106cb9b
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,20 @@
+pkgbase = device-mapper-openrc
+ pkgdesc = OpenRC device-mapper init script
+ pkgver = 20210106
+ pkgrel = 1
+ arch = any
+ license = GPL2
+ depends = device-mapper
+ depends = openrc
+ provides = init-device-mapper
+ conflicts = init-device-mapper
+ backup = etc/conf.d/device-mapper
+ source = device-mapper.confd
+ source = device-mapper.initd
+ source = dmeventd.initd
+ sha256sums = 57777904f12a35617e5a4193c964ebb32396452487fd02353e71e16e7b46bc22
+ sha256sums = 630fbe07721c2a264c1b2f0195caf658c591bdef13cb82d5605bb489f59971a4
+ sha256sums = b4b91555f1486754717073dae83715d1e03adfdd5e56d80be8ac9689a85bc717
+
+pkgname = device-mapper-openrc
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 00000000000..3a5551961b2
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,27 @@
+# Maintainer: m00n <lmarianski@protonmail.com>
+# Contributor: artoo <artoo@artixlinux.org>
+
+pkgname=device-mapper-openrc
+pkgver=20210106
+pkgrel=1
+pkgdesc="OpenRC device-mapper init script"
+arch=('any')
+license=('GPL2')
+provides=('init-device-mapper')
+depends=('device-mapper' 'openrc')
+conflicts=('init-device-mapper')
+backup=('etc/conf.d/device-mapper')
+source=("device-mapper.confd"
+ "device-mapper.initd"
+ "dmeventd.initd")
+sha256sums=('57777904f12a35617e5a4193c964ebb32396452487fd02353e71e16e7b46bc22'
+ '630fbe07721c2a264c1b2f0195caf658c591bdef13cb82d5605bb489f59971a4'
+ 'b4b91555f1486754717073dae83715d1e03adfdd5e56d80be8ac9689a85bc717')
+
+package() {
+ install -Dm755 "${srcdir}"/device-mapper.confd "${pkgdir}"/etc/openrc/conf.d/device-mapper
+
+ for f in device-mapper dmeventd; do
+ install -Dm755 "${srcdir}"/"$f".initd "${pkgdir}"/etc/openrc/init.d/"$f"
+ done
+}
diff --git a/device-mapper.confd b/device-mapper.confd
new file mode 100644
index 00000000000..bc7a2515863
--- /dev/null
+++ b/device-mapper.confd
@@ -0,0 +1 @@
+RC_AFTER="lvm"
diff --git a/device-mapper.initd b/device-mapper.initd
new file mode 100644
index 00000000000..dd4ec76e449
--- /dev/null
+++ b/device-mapper.initd
@@ -0,0 +1,146 @@
+#!/usr/bin/openrc-run
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ # As of .67-r1, we call ALL lvm start/stop scripts with --sysinit, that
+ # means dmeventd is NOT notified, as it cannot be safely running
+ before dmeventd checkfs fsck
+ after modules
+}
+
+dm_in_proc() {
+ local retval=0
+ for x in devices misc ; do
+ grep -qs 'device-mapper' /proc/${x}
+ retval=$((${retval} + $?))
+ done
+ return ${retval}
+}
+
+# char **build_dmsetup_command(volume)
+#
+# Returns complete dmsetup command given single volume name
+build_dmsetup_command() {
+ local count dmsetup_cmd
+
+ # Number of lines mentioning volume name
+ count=$(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | grep -c ${1})
+
+ # If there's just one line:
+ if [ ${count} -eq 1 ] ; then
+ echo "echo $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \
+ grep ${1} | awk '{$1=""; print $0}') | /usr/bin/dmsetup create ${1}"
+
+ # For all cases with more lines:
+ elif [ ${count} -gt 1 ] ; then
+ for c in $( seq 1 ${count} ) ; do
+ if [ ${c} -eq 1 ] ; then
+ # Heavy escaping in awk-statement because we cannot use apostrophes
+ dmsetup_cmd="echo -e $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \
+ grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})"
+ else
+ # Append starting with newline
+ dmsetup_cmd="${dmsetup_cmd}\\\\n \
+ $(grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \
+ grep ${1} | awk NR==${c}\ \{\$1=\"\"\;\ print\ \$0\})"
+ fi
+ done
+ echo "${dmsetup_cmd} | /usr/bin/dmsetup create ${1}"
+ fi
+
+ return 0
+}
+
+# char **get_new_dm_volumes(void)
+#
+# Return unique volumes from /etc/dmtab
+get_new_dm_volumes() {
+ local volume
+
+ # Filter comments and blank lines
+ grep -v -e '^[[:space:]]*\(#\|$\)' /etc/dmtab | \
+ awk '{ print $1 }' | \
+ uniq | \
+ while read volume ; do
+ # If it exists, skip it
+ dmvolume_exists "${volume%:}" && continue
+
+ echo "${volume%:}"
+ done
+
+ return 0
+}
+
+# int dmvolume_exists(volume)
+#
+# Return true if volume exists in DM table
+dmvolume_exists() {
+ local x line volume=$1
+
+ [ -z "${volume}" ] && return 1
+
+ /usr/bin/dmsetup ls 2>/dev/null | \
+ while read line ; do
+ for x in ${line} ; do
+ # the following conditonal return only breaks out
+ # of the while loop, as it is running in a pipe.
+ [ "${x}" = "${volume}" ] && return 1
+ # We only want to check the volume name
+ break
+ done
+ done
+
+ # if 1 was returned from the above loop, then indicate that
+ # volume exists
+ [ $? = 1 ] && return 0
+
+ # otherwise the loop exited normally and the volume does not
+ # exist
+ return 1
+}
+
+# int is_empty_dm_volume(volume)
+#
+# Return true if the volume exists in DM table, but is empty/non-valid
+is_empty_dm_volume() {
+ local table volume=$1
+
+ set -- $(/usr/bin/dmsetup table 2>/dev/null | grep -e "^${volume}:")
+ [ "${volume}" = "$1" -a -z "$2" ]
+}
+
+
+start() {
+ if [ -e /proc/modules ] && ! dm_in_proc ; then
+ modprobe dm-mod 2>/dev/null
+ fi
+ # Ensure the dirs exist for locking and running
+ checkpath -q -d -m 0700 -o root:root /run/lvm /run/lock/lvm
+
+ local x volume
+
+ if [ -x /usr/bin/dmsetup -a -c /dev/mapper/control -a -f /etc/dmtab ] ; then
+ [ -n "$(get_new_dm_volumes)" ] && \
+ einfo " Setting up device-mapper volumes:"
+
+ get_new_dm_volumes | \
+ while read x ; do
+ [ -n "${x}" ] || continue
+
+ volume="${x##* }"
+
+ ebegin " Creating volume: ${volume}"
+ if ! eval $(build_dmsetup_command ${volume}) >/dev/null 2>/dev/null ; then
+ eend 1 " Error creating volume: ${volume}"
+ # dmsetup still adds an empty volume in some cases,
+ # so lets remove it
+ is_empty_dm_volume "${volume}" && \
+ /usr/bin/dmsetup remove "${volume}" 2>/dev/null
+ else
+ eend 0
+ fi
+ done
+ fi
+}
+
diff --git a/dmeventd.initd b/dmeventd.initd
new file mode 100644
index 00000000000..746470418a6
--- /dev/null
+++ b/dmeventd.initd
@@ -0,0 +1,25 @@
+#!/usr/bin/openrc-run
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+PIDFILE=/run/dmeventd.pid
+BIN=/usr/bin/dmeventd
+
+depend() {
+ # As of .67-r1, we call ALL lvm start/stop scripts with --sysinit, that
+ # means dmeventd is NOT notified, as it cannot be safely running
+ after lvm device-mapper
+}
+
+start() {
+ ebegin "Starting dmeventd"
+ start-stop-daemon --start --exec $BIN --pidfile $PIDFILE
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping dmeventd"
+ start-stop-daemon --stop --exec $BIN --pidfile $PIDFILE
+ eend $?
+}
+