From cb3e011b15093ff43993c6a9880d7b40119f6015 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 6 Jun 2013 16:05:53 +0200 Subject: [vmchooser] put mount-var-lib in proper module, fix its PATH --- remote/modules/vmchooser/data/opt/openslx/bin/mount-lib-virt | 8 ++++++++ remote/rootfs/rootfs-stage32/data/opt/openslx/bin/mount-lib-virt | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100755 remote/modules/vmchooser/data/opt/openslx/bin/mount-lib-virt delete mode 100755 remote/rootfs/rootfs-stage32/data/opt/openslx/bin/mount-lib-virt diff --git a/remote/modules/vmchooser/data/opt/openslx/bin/mount-lib-virt b/remote/modules/vmchooser/data/opt/openslx/bin/mount-lib-virt new file mode 100755 index 00000000..27a8f55c --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/bin/mount-lib-virt @@ -0,0 +1,8 @@ +#!/bin/bash + +. /opt/openslx/config || exit 1 + +export PATH="$PATH:/opt/openslx/bin:/opt/openslx/usr/bin:/opt/openslx/sbin:/opt/openslx/usr/sbin" + +mkdir -p /var/lib/virt +mount -t nfs -o ro,async,nolock,vers=3 "$SLX_VM_NFS" /var/lib/virt diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/mount-lib-virt b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/mount-lib-virt deleted file mode 100755 index ac0dd1a4..00000000 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/mount-lib-virt +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -. /opt/openslx/config || exit 1 - -export PATH=/opt/openslx/bin:/opt/openslx/usr/bin:/opt/openslx/sbin:/opt/openslx/usr/sbin:/bin:/sbin:/usr/bin:/usr/sbin - -mkdir -p /var/lib/virt -mount -t nfs -o ro,async,nolock,vers=3 "$SLX_VM_NFS" /var/lib/virt -- cgit v1.2.3-55-g7522 From 43529b374c7da943cfab5773e70cb174c943afe7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 6 Jun 2013 18:10:24 +0200 Subject: [helper] Add key-value util Can be used to add simple key-value-pairs to files. It will error if the given key already exists and has a different value. If it does not exist in the target file, it will be appended/created. Otherwise, nothing will be done. --- helper/keyvalueutil.inc | 32 ++++++++++++++++++++++++++++++++ helper/string.inc | 5 +++++ 2 files changed, 37 insertions(+) create mode 100644 helper/keyvalueutil.inc diff --git a/helper/keyvalueutil.inc b/helper/keyvalueutil.inc new file mode 100644 index 00000000..a0a89db7 --- /dev/null +++ b/helper/keyvalueutil.inc @@ -0,0 +1,32 @@ +# Helper file for managing key-value containing files +# There are some specialized conveinience functions here first +# that mostly just pass a predefined filename to the genric function +# at the end + +# Add the given environment variable to /etc/environment +add_env () { + [ $# -ne 2 ] && perror "Usage: $0 'key' 'value'" + [ -z "$1" ] && perror "$0: Empty key!" + add_key_value "/etc/environment" "$1" "$2" +} + +# +# Adds the given key-value-pair to a given file +# The file will be relative to the current target build dir, +# even if it starts with a slash. +# Will perror if the key already exists with a different value +add_key_value () { + [ $# -ne 3 ] && perror "Usage: $0 'file' 'key' 'value'" + [ -z "$TARGET_BUILD_DIR" ] && perror "No TARGET_BUILD_DIR set. Aborting for safety." + local FILE="$TARGET_BUILD_DIR/$1" + local KEY="$2" + local VALUE="$(echo "$3" | sed "s/'/\\\\'/g")" # \\\\\\\\\\\\\\\\\\\\\\ßß + if [ -s "$FILE" ]; then + local CURRENT="$(grep -E "^\s*$KEY=.*$" "$FILE" | awk -F '=' '{$1=""; printf $0}' | itrim)" + [ -n "$CURRENT" -a "'$VALUE'" != "$CURRENT" ] && perror "Cannot set $KEY to '$VALUE' as it is already set to $CURRENT" + [ -n "$CURRENT" ] && return 0 + fi + mkdir -p "$(dirname "$FILE")" + echo "$KEY='$VALUE'" >> "$FILE" +} + diff --git a/helper/string.inc b/helper/string.inc index 9f18e4e0..04809a93 100644 --- a/helper/string.inc +++ b/helper/string.inc @@ -7,6 +7,11 @@ trim() { echo -n "$var" } +# Inline version of trim, use when piping +itrim () { + sed -r 's/^\s+//g;s/\s+$//g' +} + # usage: CANONICALIZED_STRING=$(canonalize ) # usage with relative path requires you to be in the correct directory. canonicalize() { -- cgit v1.2.3-55-g7522