Skip to content

Commit

Permalink
Merge pull request #25 from jtopjian/conditional-quoting
Browse files Browse the repository at this point in the history
Conditional quoting
  • Loading branch information
jtopjian committed Jul 3, 2015
2 parents 2c88220 + ac7c71f commit cf28cb3
Show file tree
Hide file tree
Showing 53 changed files with 422 additions and 397 deletions.
7 changes: 7 additions & 0 deletions kitchen/site/roles/ubuntu1204.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ stdlib.title ubuntu1204/tests

source /etc/lsb-release

stdlib.info "syntax check"
stdlib.enable_apache
stdlib.enable_augeas
stdlib.enable_mysql
stdlib.enable_nginx
stdlib.enable_rabbitmq

stdlib.info "groupadd"
stdlib.groupadd --group memcache --gid 999

Expand Down
7 changes: 7 additions & 0 deletions kitchen/site/roles/ubuntu1404.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ stdlib.title ubuntu1204/tests

source /etc/lsb-release

stdlib.info "syntax check"
stdlib.enable_apache
stdlib.enable_augeas
stdlib.enable_mysql
stdlib.enable_nginx
stdlib.enable_rabbitmq

stdlib.info "groupadd"
stdlib.groupadd --group memcache --gid 999

Expand Down
14 changes: 7 additions & 7 deletions lib/apache/resources/apache_section.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function apache.section {

if ! stdlib.command_exists augtool ; then
stdlib.error "Cannot find augtool."
if [[ $WAFFLES_EXIT_ON_ERROR == true ]]; then
if [[ -n "$WAFFLES_EXIT_ON_ERROR" ]]; then
exit 1
else
return 1
Expand Down Expand Up @@ -63,8 +63,8 @@ function apache.section {
stdlib.catalog.add "apache.section/$_name"

apache.section.read
if [[ ${options[state]} == absent ]]; then
if [[ $stdlib_current_state != absent ]]; then
if [[ "${options[state]}" == "absent" ]]; then
if [[ "$stdlib_current_state" != "absent" ]]; then
stdlib.info "$_name state: $stdlib_current_state, should be absent."
apache.section.delete
fi
Expand Down Expand Up @@ -96,15 +96,15 @@ function apache.section.read {
# Check if the parent type/name exists
if [[ -n "$_path" ]]; then
_result=$(augeas.get --lens Httpd --file "$_file" --path "$_parent_path")
if [[ $_result == "absent" ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="error"
return
fi
fi

# Check if the type exists
stdlib_current_state=$(augeas.get --lens Httpd --file "$_file" --path "$_path/${options[type]}/arg[. = '${options[name]}']")
if [[ $stdlib_current_state == "absent" ]]; then
if [[ "$stdlib_current_state" == "absent" ]]; then
return
fi

Expand All @@ -121,7 +121,7 @@ function apache.section.create {
_augeas_commands+=("set /files$_file/$_path/${options[type]}/arg '${options[name]}'")
local _result=$(augeas.run --lens Httpd --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ ^error ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error adding apache.section $_name with augeas: $_result"
return
fi
Expand All @@ -133,7 +133,7 @@ function apache.section.delete {

local _result=$(augeas.run --lens Httpd --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ "^error" ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error deleting apache.section $_name with augeas: $_result"
return
fi
Expand Down
18 changes: 9 additions & 9 deletions lib/apache/resources/apache_setting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function apache.setting {

if ! stdlib.command_exists augtool ; then
stdlib.error "Cannot find augtool."
if [[ $WAFFLES_EXIT_ON_ERROR == true ]]; then
if [[ -n $WAFFLES_EXIT_ON_ERROR ]]; then
exit 1
else
return 1
Expand Down Expand Up @@ -66,8 +66,8 @@ function apache.setting {
stdlib.catalog.add "apache.setting/$_name"

apache.setting.read
if [[ ${options[state]} == absent ]]; then
if [[ $stdlib_current_state != absent ]]; then
if [[ "${options[state]}" == "absent" ]]; then
if [[ "$stdlib_current_state" != "absent" ]]; then
stdlib.info "$_name state: $stdlib_current_state, should be absent."
apache.setting.delete
fi
Expand Down Expand Up @@ -103,22 +103,22 @@ function apache.setting.read {
# Check if the parent key/value exists
if [[ -n "$_path" ]]; then
_result=$(augeas.get --lens Httpd --file "$_file" --path "$_parent_path")
if [[ $_result == "absent" ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="error"
return
fi
fi

# Check if the key exists
stdlib_current_state=$(augeas.get --lens Httpd --file "$_file" --path "$_path/directive[. = '${options[key]}']")
if [[ $stdlib_current_state == "absent" ]]; then
if [[ "$stdlib_current_state" == "absent" ]]; then
return
fi

# Check if the value exists
for v in "${_values[@]}"; do
_result=$(augeas.get --lens Httpd --file "$_file" --path "$_path/directive[. = '${options[key]}']/arg[. = '$v']")
if [[ $_result == "absent" ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi
Expand All @@ -141,7 +141,7 @@ function apache.setting.create {

local _result=$(augeas.run --lens Httpd --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ ^error ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error adding apache.setting $_name with augeas: $_result"
return
fi
Expand All @@ -156,7 +156,7 @@ function apache.setting.update {

local _result=$(augeas.run --lens Httpd --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ ^error ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error adding apache.setting $_name with augeas: $_result"
return
fi
Expand All @@ -168,7 +168,7 @@ function apache.setting.delete {

local _result=$(augeas.run --lens Httpd --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ "^error" ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error deleting apache.setting $_name with augeas: $_result"
return
fi
Expand Down
4 changes: 2 additions & 2 deletions lib/augeas/augeas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ save
EOF
)

if [[ -n $_result ]]; then
if [[ -n "$_result" ]]; then
echo "error: $_result"
return
fi
Expand All @@ -43,7 +43,7 @@ match /files${_path}
EOF
)

if [[ $_result =~ "no matches" ]]; then
if [[ "$_result" =~ "no matches" ]]; then
echo "absent"
return
fi
Expand Down
14 changes: 7 additions & 7 deletions lib/augeas/resources/augeas_aptconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function augeas.aptconf {

if ! stdlib.command_exists augtool ; then
stdlib.error "Cannot find augtool."
if [[ $WAFFLES_EXIT_ON_ERROR == true ]]; then
if [[ -n "$WAFFLES_EXIT_ON_ERROR" ]]; then
exit 1
else
return 1
Expand All @@ -44,8 +44,8 @@ function augeas.aptconf {
stdlib.catalog.add "augeas.aptconf/${options[setting]}"

augeas.aptconf.read
if [[ ${options[state]} == absent ]]; then
if [[ $stdlib_current_state != absent ]]; then
if [[ "${options[state]}" == "absent" ]]; then
if [[ "$stdlib_current_state" != "absent" ]]; then
stdlib.info "$_name state: $stdlib_current_state, should be absent."
augeas.aptconf.delete
fi
Expand All @@ -72,13 +72,13 @@ function augeas.aptconf.read {

# Check if the setting exists
stdlib_current_state=$(augeas.get --lens Aptconf --file "${options[file]}" --path "/$_path")
if [[ $stdlib_current_state == absent ]]; then
if [[ "$stdlib_current_state" == "absent" ]]; then
return
fi

# Check if the value matches
_result=$(augeas.get --lens Aptconf --file "${options[file]}" --path "/${_path}[. = '${options[value]}']")
if [[ $_result == "absent" ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
fi
}
Expand All @@ -89,7 +89,7 @@ function augeas.aptconf.create {

local _result=$(augeas.run --lens Aptconf --file "${options[file]}" "${_augeas_commands[@]}")

if [[ $_result =~ ^error ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error adding aptconf $_name with augeas: $_result"
return
fi
Expand All @@ -100,7 +100,7 @@ function augeas.aptconf.delete {
_augeas_commands+=("rm /files${options[file]}/$_path")
local _result=$(augeas.run --lens Aptconf --file ${options[file]} "${_augeas_commands[@]}")

if [[ $_result =~ "^error" ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error deleting aptconf $_name with augeas: $_result"
return
fi
Expand Down
24 changes: 12 additions & 12 deletions lib/augeas/resources/augeas_cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function augeas.cron {

if ! stdlib.command_exists augtool ; then
stdlib.error "Cannot find augtool."
if [[ $WAFFLES_EXIT_ON_ERROR == true ]]; then
if [[ -n "$WAFFLES_EXIT_ON_ERROR" ]]; then
exit 1
else
return 1
Expand All @@ -53,8 +53,8 @@ function augeas.cron {
local _file="/etc/cron.d/${options[name]}"

augeas.cron.read
if [[ ${options[state]} == absent ]]; then
if [[ $stdlib_current_state != absent ]]; then
if [[ "${options[state]}" == "absent" ]]; then
if [[ "$stdlib_current_state" != "absent" ]]; then
stdlib.info "$_name state: $stdlib_current_state, should be absent."
augeas.cron.delete
fi
Expand All @@ -81,43 +81,43 @@ function augeas.cron.read {

# Check if the cron command exists
stdlib_current_state=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']")
if [[ $stdlib_current_state == absent ]]; then
if [[ "$stdlib_current_state" == "absent" ]]; then
return
fi

# If so, check if the other attributes match
_result=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']/time/minute[. = '${options[minute]}']")
if [[ $_result == absent ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi

_result=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']/time/hour[. = '${options[hour]}']")
if [[ $_result == absent ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi

_result=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']/time/dayofmonth[. = '${options[dom]}']")
if [[ $_result == absent ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi

_result=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']/time/month[. = '${options[month]}']")
if [[ $_result == absent ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi

_result=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']/time/dayofweek[. = '${options[dow]}']")
if [[ $_result == absent ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi

_result=$(augeas.get --lens Cron --file "$_file" --path "/entry[. = '${options[cmd]}']/user[. = '${options[user]}']")
if [[ $_result == absent ]]; then
if [[ "$_result" == "absent" ]]; then
stdlib_current_state="update"
return
fi
Expand All @@ -135,7 +135,7 @@ function augeas.cron.create {

local _result=$(augeas.run --lens Cron --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ ^error ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error adding cron ${options[name]} with augeas: $_result"
return
fi
Expand All @@ -146,7 +146,7 @@ function augeas.cron.delete {
_augeas_commands+=("rm /files${_file}/entry[. = '${options[cmd]}']")
local _result=$(augeas.run --lens Cron --file "$_file" "${_augeas_commands[@]}")

if [[ $_result =~ "^error" ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error deleting cron ${options[name]} with augeas: $_result"
return
fi
Expand Down
10 changes: 5 additions & 5 deletions lib/augeas/resources/augeas_file_line.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function augeas.file_line {

if ! stdlib.command_exists augtool ; then
stdlib.error "Cannot find augtool."
if [[ $WAFFLES_EXIT_ON_ERROR == true ]]; then
if [[ -n "$WAFFLES_EXIT_ON_ERROR" ]]; then
exit 1
else
return 1
Expand All @@ -41,8 +41,8 @@ function augeas.file_line {
stdlib.catalog.add "augeas.file_line/${options[name]}"

augeas.file_line.read
if [[ ${options[state]} == absent ]]; then
if [[ $stdlib_current_state != absent ]]; then
if [[ "${options[state]}" == "absent" ]]; then
if [[ "$stdlib_current_state" != "absent" ]]; then
stdlib.info "$_name state: $stdlib_current_state, should be absent."
augeas.file_line.delete
fi
Expand Down Expand Up @@ -77,7 +77,7 @@ function augeas.file_line.create {

local _result=$(augeas.run --lens Simplelines --file "${options[file]}" "${_augeas_commands[@]}")

if [[ $_result =~ ^error ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error adding file_line ${options[name]} with augeas: $_result"
return
fi
Expand All @@ -88,7 +88,7 @@ function augeas.file_line.delete {
_augeas_commands+=("rm /files${options[file]}/*[. = '${options[line]}']")
local _result=$(augeas.run --lens Simplelines --file ${options[file]} "${_augeas_commands[@]}")

if [[ $_result =~ "^error" ]]; then
if [[ "$_result" =~ ^error ]]; then
stdlib.error "Error deleting file_line ${options[name]} with augeas: $_result"
return
fi
Expand Down
Loading

0 comments on commit cf28cb3

Please sign in to comment.