1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#!/bin/sh
set -e
# Edit lvm.conf to add filters, so that we don't see nested PV
# (if our cloud users setup LVM inside their volumes)
LVMCONF=/etc/lvm/lvm.conf
# check whether "scan =" appears uncommented in the configuration file
if ! grep -q -P '^\s*scan[ =]' ${LVMCONF}; then
# attempt to add "scan = []" after the appropriate comment block
# scan's value is irrelevant at this point as it will be set afterward
#
# match comment block start
# /^\s*# Configuration option devices\/scan\./,
# match comment block end (empty line)
# /^\s*$/
# substitute empty line with our payload
# s/^\s*$/\tscan = []\n/
sed -i '/^\s*# Configuration option devices\/scan\./,/^\s*$/s/^\s*$/\tscan = []\n/' ${LVMCONF}
# check again whether "scan =" appears uncommented in the configuration file
# (comment block used above might be missing)
if ! grep -q -P '^\s*scan[ =]' ${LVMCONF}; then
# add "scan = []" after "devices {"
sed -i '/^devices {/a scan = []' ${LVMCONF}
fi
fi
# idempotent sed to ensure scan's value
sed -i '/^\s*scan\s*=/s|=.*$|= [ "/dev/disk/by-path/" ]|' ${LVMCONF}
# same logic as above but for filter
if ! grep -q -P '^\s*filter[ =]' ${LVMCONF}; then
sed -i '/^\s*# Configuration option devices\/filter\./,/^\s*$/s/^\s*$/\tfilter = []\n/' ${LVMCONF}
if ! grep -q -P '^\s*filter[ =]' ${LVMCONF}; then
sed -i '/^devices {/a filter = []' ${LVMCONF}
fi
fi
sed -i '/^\s*filter\s*=/s/=.*$/= [ "r|ip-.*|" ]/' ${LVMCONF}
# and again, for global_filter
if ! grep -q -P '^\s*global_filter[ =]' ${LVMCONF}; then
sed -i '/^\s*# Configuration option devices\/global_filter\./,/^\s*$/s/^\s*$/\tglobal_filter = []\n/' ${LVMCONF}
if ! grep -q -P '^\s*global_filter[ =]' ${LVMCONF}; then
sed -i '/^devices {/a global_filter = []' ${LVMCONF}
fi
fi
sed -i '/^\s*global_filter\s*=/s/=.*$/= [ "r|ip-.*|" ]/' ${LVMCONF}
|