| ... | ... |
@@ -57,32 +57,64 @@ function cp_it {
|
| 57 | 57 |
# die $LINENO "message" |
| 58 | 58 |
function die() {
|
| 59 | 59 |
local exitcode=$? |
| 60 |
+ set +o xtrace |
|
| 61 |
+ local line=$1; shift |
|
| 60 | 62 |
if [ $exitcode == 0 ]; then |
| 61 | 63 |
exitcode=1 |
| 62 | 64 |
fi |
| 65 |
+ err $line "$*" |
|
| 66 |
+ exit $exitcode |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+ |
|
| 70 |
+# Checks an environment variable is not set or has length 0 OR if the |
|
| 71 |
+# exit code is non-zero and prints "message" and exits |
|
| 72 |
+# NOTE: env-var is the variable name without a '$' |
|
| 73 |
+# die_if_not_set $LINENO env-var "message" |
|
| 74 |
+function die_if_not_set() {
|
|
| 75 |
+ local exitcode=$? |
|
| 76 |
+ FXTRACE=$(set +o | grep xtrace) |
|
| 77 |
+ set +o xtrace |
|
| 78 |
+ local line=$1; shift |
|
| 79 |
+ local evar=$1; shift |
|
| 80 |
+ if ! is_set $evar || [ $exitcode != 0 ]; then |
|
| 81 |
+ die $line "$*" |
|
| 82 |
+ fi |
|
| 83 |
+ $FXTRACE |
|
| 84 |
+} |
|
| 85 |
+ |
|
| 86 |
+ |
|
| 87 |
+# Prints line number and "message" in error format |
|
| 88 |
+# err $LINENO "message" |
|
| 89 |
+function err() {
|
|
| 90 |
+ local exitcode=$? |
|
| 91 |
+ errXTRACE=$(set +o | grep xtrace) |
|
| 63 | 92 |
set +o xtrace |
| 64 | 93 |
local msg="[ERROR] $0:$1 $2" |
| 65 | 94 |
echo $msg 1>&2; |
| 66 | 95 |
if [[ -n ${SCREEN_LOGDIR} ]]; then
|
| 67 | 96 |
echo $msg >> "${SCREEN_LOGDIR}/error.log"
|
| 68 | 97 |
fi |
| 69 |
- exit $exitcode |
|
| 98 |
+ $errXTRACE |
|
| 99 |
+ return $exitcode |
|
| 70 | 100 |
} |
| 71 | 101 |
|
| 72 | 102 |
|
| 73 | 103 |
# Checks an environment variable is not set or has length 0 OR if the |
| 74 |
-# exit code is non-zero and prints "message" and exits |
|
| 104 |
+# exit code is non-zero and prints "message" |
|
| 75 | 105 |
# NOTE: env-var is the variable name without a '$' |
| 76 |
-# die_if_not_set $LINENO env-var "message" |
|
| 77 |
-function die_if_not_set() {
|
|
| 78 |
- ( |
|
| 79 |
- local exitcode=$? |
|
| 80 |
- set +o xtrace |
|
| 81 |
- local evar=$2; shift |
|
| 82 |
- if ! is_set $evar || [ $exitcode != 0 ]; then |
|
| 83 |
- die $@ |
|
| 84 |
- fi |
|
| 85 |
- ) |
|
| 106 |
+# err_if_not_set $LINENO env-var "message" |
|
| 107 |
+function err_if_not_set() {
|
|
| 108 |
+ local exitcode=$? |
|
| 109 |
+ errinsXTRACE=$(set +o | grep xtrace) |
|
| 110 |
+ set +o xtrace |
|
| 111 |
+ local line=$1; shift |
|
| 112 |
+ local evar=$1; shift |
|
| 113 |
+ if ! is_set $evar || [ $exitcode != 0 ]; then |
|
| 114 |
+ err $line "$*" |
|
| 115 |
+ fi |
|
| 116 |
+ $errinsXTRACE |
|
| 117 |
+ return $exitcode |
|
| 86 | 118 |
} |
| 87 | 119 |
|
| 88 | 120 |
|
| ... | ... |
@@ -538,6 +570,7 @@ function inicomment() {
|
| 538 | 538 |
sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" "$file" |
| 539 | 539 |
} |
| 540 | 540 |
|
| 541 |
+ |
|
| 541 | 542 |
# Uncomment an option in an INI file |
| 542 | 543 |
# iniuncomment config-file section option |
| 543 | 544 |
function iniuncomment() {
|
| ... | ... |
@@ -559,6 +592,7 @@ function iniget() {
|
| 559 | 559 |
echo ${line#*=}
|
| 560 | 560 |
} |
| 561 | 561 |
|
| 562 |
+ |
|
| 562 | 563 |
# Determinate is the given option present in the INI file |
| 563 | 564 |
# ini_has_option config-file section option |
| 564 | 565 |
function ini_has_option() {
|
| ... | ... |
@@ -570,6 +604,7 @@ function ini_has_option() {
|
| 570 | 570 |
[ -n "$line" ] |
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 |
+ |
|
| 573 | 574 |
# Set an option in an INI file |
| 574 | 575 |
# iniset config-file section option value |
| 575 | 576 |
function iniset() {
|
| ... | ... |
@@ -592,6 +627,7 @@ $option = $value |
| 592 | 592 |
fi |
| 593 | 593 |
} |
| 594 | 594 |
|
| 595 |
+ |
|
| 595 | 596 |
# Get a multiple line option from an INI file |
| 596 | 597 |
# iniget_multiline config-file section option |
| 597 | 598 |
function iniget_multiline() {
|
| ... | ... |
@@ -603,6 +639,7 @@ function iniget_multiline() {
|
| 603 | 603 |
echo ${values}
|
| 604 | 604 |
} |
| 605 | 605 |
|
| 606 |
+ |
|
| 606 | 607 |
# Set a multiple line option in an INI file |
| 607 | 608 |
# iniset_multiline config-file section option value1 value2 valu3 ... |
| 608 | 609 |
function iniset_multiline() {
|
| ... | ... |
@@ -632,6 +669,7 @@ $option = $v |
| 632 | 632 |
done |
| 633 | 633 |
} |
| 634 | 634 |
|
| 635 |
+ |
|
| 635 | 636 |
# Append a new option in an ini file without replacing the old value |
| 636 | 637 |
# iniadd config-file section option value1 value2 value3 ... |
| 637 | 638 |
function iniadd() {
|
| ... | ... |
@@ -643,6 +681,17 @@ function iniadd() {
|
| 643 | 643 |
iniset_multiline $file $section $option $values |
| 644 | 644 |
} |
| 645 | 645 |
|
| 646 |
+# Find out if a process exists by partial name. |
|
| 647 |
+# is_running name |
|
| 648 |
+function is_running() {
|
|
| 649 |
+ local name=$1 |
|
| 650 |
+ ps auxw | grep -v grep | grep ${name} > /dev/null
|
|
| 651 |
+ RC=$? |
|
| 652 |
+ # some times I really hate bash reverse binary logic |
|
| 653 |
+ return $RC |
|
| 654 |
+} |
|
| 655 |
+ |
|
| 656 |
+ |
|
| 646 | 657 |
# is_service_enabled() checks if the service(s) specified as arguments are |
| 647 | 658 |
# enabled by the user in ``ENABLED_SERVICES``. |
| 648 | 659 |
# |