From: Dennis Schridde <devurandom-hi6Y0CQ0nG0@public.gmane.org>
To: initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Dennis Schridde <devurandom-hi6Y0CQ0nG0@public.gmane.org>
Subject: [PATCH 1/2] [40network] Add variable parsing framework for network related variables
Date: Thu, 11 Apr 2013 17:40:52 +0200 [thread overview]
Message-ID: <1365694853-7881-1-git-send-email-devurandom@gmx.net> (raw)
* Provides net_add_parse_vars function to install net_parse_vars hook when an interface comes online
* Provides net_parse_vars function to search and replace network related variables in a string
---
modules.d/40network/net-lib.sh | 56 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
index f9b461b..caa3b79 100644
--- a/modules.d/40network/net-lib.sh
+++ b/modules.d/40network/net-lib.sh
@@ -366,3 +366,59 @@ linkup() {
&& wait_for_if_up $1 2>/dev/null
}
+# net_parse_vars STRING IFUP
+# parse vars in STRING
+# IFUP may contain the interface that came online, triggering this hook
+net_parse_vars() {
+ local cur="$1" ifup="$2" var val iface
+
+ var="${cur#*%\{}"
+ var="${var%%\}*}"
+
+ while [ "${var}" != "${cur}" ] ; do
+ case "${var}" in
+ mac.*)
+ iface="${var##mac.}"
+ [ "${ifup}" = "${iface}" ] || exit
+ val="$(ip link show dev "${iface}" | sed -nre '/ether/s/^.*ether ([0-9a-f:]*) .*$/\1/' -e 's/://')"
+ ;;
+ hostname)
+ val="$(hostname)"
+ [ "${val}" = '(none)' ] && die 'No hostname (yet)'
+ ;;
+ *)
+ die "Unsupported cmdline variable '${var}'"
+ ;;
+ esac
+
+ cur="$(echo "${cur}" | sed "s/%{${var}}/${val}/")"
+ unset val
+
+ var="${cur#*%\{}"
+ var="${var%%\}*}"
+ done
+
+ echo "${cur}"
+}
+
+# net_add_parse_vars STRING LIB FUNCTION
+# add initqueue/online hook to parse vars in STRING
+# execute FUNCTION from LIB afterwards
+net_add_parse_vars() {
+ local string="$1" lib="$2" func="$3" jobid="$(cat /proc/sys/kernel/random/uuid)"
+
+ cat <<- EOF > "${hookdir}"/initqueue/online/40network.parse."${jobid}".sh
+ . /lib/"${lib}".sh
+
+ string="\$(net_parse_vars "${string}" "\$@")"
+ ${func} "\${string}"
+ unset string
+
+ > /tmp/40network.parse.finished."${jobid}"
+ EOF
+
+ cat <<- EOF > "${hookdir}"/initqueue/finished/40network.parse.wait."${jobid}".sh
+ echo "Waiting for nfs_parse_vars (${jobid}) to complete ..."
+ [ -f /tmp/40network.parse.finished."${jobid}" ] && rm -f /tmp/40network.parse.finished."${jobid}"
+ EOF
+}
--
1.8.1.5
next reply other threads:[~2013-04-11 15:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-11 15:40 Dennis Schridde [this message]
[not found] ` <1365694853-7881-1-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org>
2013-04-11 15:40 ` [PATCH 2/2] [40network] Provide a hostname fallback function, in case there is no executable of this name Dennis Schridde
[not found] ` <1365694853-7881-2-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org>
2013-04-11 15:48 ` Dennis Schridde
-- strict thread matches above, loose matches on Subject: below --
2013-04-11 15:39 [PATCH 1/2] [99fs-lib] Create generic mount framework Dennis Schridde
[not found] ` <1365694762-7806-1-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org>
2013-05-17 16:17 ` [PATCH 1/2] [40network] Add variable parsing framework for network related variables Dennis Schridde
[not found] ` <1368807440-9207-1-git-send-email-devurandom-hi6Y0CQ0nG0@public.gmane.org>
2013-05-17 16:22 ` Dennis Schridde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1365694853-7881-1-git-send-email-devurandom@gmx.net \
--to=devurandom-hi6y0cq0ng0@public.gmane.org \
--cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox