quoting; posix sed;

This commit is contained in:
Darko Poljak 2017-11-23 10:20:03 +01:00
parent 9e0cfd5df5
commit ecc1dccd03
4 changed files with 26 additions and 18 deletions

View file

@ -60,7 +60,7 @@ prefix="#cdist:__cron/$__object_id"
suffix="#/cdist:__cron/$__object_id" suffix="#/cdist:__cron/$__object_id"
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V|^# \(Cronie version .\..\)$" filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V|^# \(Cronie version .\..\)$"
cat << DONE cat << DONE
crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" ' crontab -u '$user' -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
{ {
if (index(\$0,prefix)) { if (index(\$0,prefix)) {
triggered=1 triggered=1
@ -73,7 +73,7 @@ crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix"
print print
} }
} }
' | crontab -u $user - ' | crontab -u '$user' -
DONE DONE
case "$state_should" in case "$state_should" in
@ -81,21 +81,21 @@ case "$state_should" in
# if we insert new entry, filter also all entrys out with the same id # if we insert new entry, filter also all entrys out with the same id
cat <<EOF cat <<EOF
( (
crontab -u $user -l 2>/dev/null | grep -v -E '$filter' | grep -v '# $name\\$' 2>/dev/null || true crontab -u '$user' -l 2>/dev/null | grep -v -E '$filter' | grep -v '# $name\\$' 2>/dev/null || true
echo '$entry' echo '$entry'
) | crontab -u $user - ) | crontab -u '$user' -
EOF EOF
;; ;;
absent) absent)
if [ -f "$__object/parameter/raw_command" ]; then if [ -f "$__object/parameter/raw_command" ]; then
cat <<EOF cat <<EOF
( crontab -u $user -l 2>/dev/null | grep -v -E '$filter' 2>/dev/null || true ) | \\ ( crontab -u '$user' -l 2>/dev/null | grep -v -E '$filter' 2>/dev/null || true ) | \\
grep -v '^$entry\\$' | crontab -u $user - grep -v '^$entry\\$' | crontab -u '$user' -
EOF EOF
else else
cat <<EOF cat <<EOF
( crontab -u $user -l 2>/dev/null | grep -v -E '$filter' 2>/dev/null || true ) | \\ ( crontab -u '$user' -l 2>/dev/null | grep -v -E '$filter' 2>/dev/null || true ) | \\
grep -v '# $name\\$' | crontab -u $user - grep -v '# $name\\$' | crontab -u '$user' -
EOF EOF
fi fi
;; ;;

View file

@ -137,7 +137,8 @@ EOF
echo "rm -f '/etc/fstab.${name}'" echo "rm -f '/etc/fstab.${name}'"
# Remove jail entry from jail.conf # Remove jail entry from jail.conf
cat <<EOF cat <<EOF
sed -i .bak -E -e "/^${name} {\$/,/^}\\\$/d" /etc/jail.conf mv /etc/jail.conf /etc/jail.conf.bak
sed -E -e "/^${name} {\$/,/^}\\\$/d" /etc/jail.conf.bak > /etc/jail.conf
if [ -f "/etc/jail.conf.bak" ]; then if [ -f "/etc/jail.conf.bak" ]; then
rm -f "/etc/jail.conf.bak" rm -f "/etc/jail.conf.bak"
fi fi
@ -153,7 +154,8 @@ EOF
done done
jail_list="\${new_list}" jail_list="\${new_list}"
sed -i '.bak' "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf mv /etc/rc.conf /etc/rc.conf.bak
sed "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf.bak > /etc/rc.conf
unset jail_list unset jail_list
if [ -f "/etc/rc.conf.bak" ]; then if [ -f "/etc/rc.conf.bak" ]; then
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
@ -239,7 +241,8 @@ cat <<EOF
if [ -z "\$jail_enable" ]; then # no jail_enable line in rc.conf at all if [ -z "\$jail_enable" ]; then # no jail_enable line in rc.conf at all
echo "jail_enable=\"YES\"" >>/etc/rc.conf echo "jail_enable=\"YES\"" >>/etc/rc.conf
elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]' | tr -d '"')" = "YES" ]; then # jail_enable="NO" elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]' | tr -d '"')" = "YES" ]; then # jail_enable="NO"
sed -i '.bak' 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf # fix this -^ mv /etc/rc.conf /etc/rc.conf.bak
sed 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf.bak > /etc/rc.conf # fix this -^
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
fi fi
@ -313,7 +316,8 @@ if [ "$onboot" = "yes" ]; then
echo "jail_list=\"${name}\"" >>/etc/rc.conf echo "jail_list=\"${name}\"" >>/etc/rc.conf
else else
jail_list="\${jail_list} ${name}" jail_list="\${jail_list} ${name}"
sed -i '.bak' "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf mv /etc/rc.conf /etc/rc.conf.bak
sed "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf.bak > /etc/rc.conf
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
fi fi
unset jail_list unset jail_list

View file

@ -142,7 +142,8 @@ EOF
echo "rm -f '/etc/fstab.${name}'" echo "rm -f '/etc/fstab.${name}'"
# Remove jail_$name_* lines from rc.conf # Remove jail_$name_* lines from rc.conf
cat <<EOF cat <<EOF
sed -i '.bak' "/^jail_${name}_/d" /etc/rc.conf mv /etc/rc.conf /etc/rc.conf.bak
sed "/^jail_${name}_/d" /etc/rc.conf.bak > /etc/rc.conf
if [ -f "/etc/rc.conf.bak" ]; then if [ -f "/etc/rc.conf.bak" ]; then
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
fi fi
@ -158,7 +159,8 @@ EOF
done done
jail_list="\${new_list}" jail_list="\${new_list}"
sed -i '.bak' "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf mv /etc/rc.conf /etc/rc.conf.bak
sed "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf.bak > /etc/rc.conf
unset jail_list unset jail_list
if [ -f "/etc/rc.conf.bak" ]; then if [ -f "/etc/rc.conf.bak" ]; then
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
@ -241,7 +243,8 @@ cat <<EOF
if [ -z "\$jail_enable" ]; then # no jail_enable line in rc.conf at all if [ -z "\$jail_enable" ]; then # no jail_enable line in rc.conf at all
echo "jail_enable=\"YES\"" >>/etc/rc.conf echo "jail_enable=\"YES\"" >>/etc/rc.conf
elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]')" = "YES" ]; then # jail_enable="NO" elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]')" = "YES" ]; then # jail_enable="NO"
sed -i '.bak' 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf # fix this -^ mv /etc/rc.conf /etc/rc.conf.bak
sed 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf.bak > /etc/rc.conf # fix this -^
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
fi fi
cat >>/etc/rc.conf <<END cat >>/etc/rc.conf <<END
@ -309,7 +312,8 @@ if [ "$onboot" = "yes" ]; then
echo "jail_list=\"${name}\"" >>/etc/rc.conf echo "jail_list=\"${name}\"" >>/etc/rc.conf
else else
jail_list="\${jail_list} ${name}" jail_list="\${jail_list} ${name}"
sed -i '.bak' "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf mv /etc/rc.conf /etc/rc.conf.bak
sed "s/^jail_list=\".*\"/jail_list=\"\${jail_list}\"/" /etc/rc.conf.bak > /etc/rc.conf
rm -f /etc/rc.conf.bak rm -f /etc/rc.conf.bak
fi fi
unset jail_list unset jail_list

View file

@ -53,7 +53,7 @@ case "$state_should" in
present) present)
if [ "$runas" ] if [ "$runas" ]
then then
echo "su -c '$pip install -q $name' $runas" echo "su -c '$pip install -q $name' '$runas'"
else else
echo $pip install -q "$name" echo $pip install -q "$name"
fi fi
@ -61,7 +61,7 @@ case "$state_should" in
absent) absent)
if [ "$runas" ] if [ "$runas" ]
then then
echo "su -c '$pip uninstall -q -y $name' $runas" echo "su -c '$pip uninstall -q -y $name' '$runas'"
else else
echo $pip uninstall -q -y "$name" echo $pip uninstall -q -y "$name"
fi fi