Initial commit.
This commit is contained in:
commit
2dda2e227d
52 changed files with 2704 additions and 0 deletions
118
bits/other-peoples/someone_elses_bash_ini_parser/README
Normal file
118
bits/other-peoples/someone_elses_bash_ini_parser/README
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
|
||||
bash_ini_parser -- Simple INI file parser
|
||||
=========================================
|
||||
|
||||
This is a comfortable and simple INI file parser to be used in
|
||||
bash scripts.
|
||||
|
||||
|
||||
|
||||
|
||||
COPYRIGHT
|
||||
---------
|
||||
|
||||
Copyright (c) 2009 Kevin Porter / Advanced Web Construction Ltd
|
||||
(http://coding.tinternet.info / http://webutils.co.uk)
|
||||
Copyright (c) 2010, 2011 Ruediger Meier <sweet_f_a@gmx.de>
|
||||
(https://github.com/rudimeier/)
|
||||
|
||||
|
||||
|
||||
|
||||
USAGE
|
||||
-----
|
||||
|
||||
You must source the bash file into your script:
|
||||
|
||||
> . read_ini.sh
|
||||
|
||||
and then use the read_ini function, defined as:
|
||||
|
||||
> read_ini INI_FILE [SECTION] [[--prefix|-p] PREFIX] [[--booleans|b] [0|1]]
|
||||
|
||||
If SECTION is supplied, then only the specified section of the file will
|
||||
be processed.
|
||||
|
||||
After running the read_ini function, variables corresponding to the ini
|
||||
file entries will be available to you. Naming convention for variable
|
||||
names is:
|
||||
|
||||
PREFIX__SECTION__VARNAME
|
||||
|
||||
PREFIX is 'INI' by default (but can be changed with the --prefix option),
|
||||
SECTION and VARNAME are the section name and variable name respectively.
|
||||
For example, to read and output the variables of this ini file:
|
||||
|
||||
-- START test1.ini file
|
||||
|
||||
var1="VAR 1"
|
||||
var2 = VAR 2
|
||||
|
||||
[section1]
|
||||
var1="section1 VAR 1"
|
||||
var2= section1 VAR 2
|
||||
|
||||
|
||||
-- END test1.ini file
|
||||
|
||||
you could do this:
|
||||
|
||||
-- START bash script
|
||||
|
||||
. read_ini.sh
|
||||
|
||||
read_ini test1.ini
|
||||
|
||||
echo "var1 = ${INI__var1}"
|
||||
echo "var2 = ${INI__var2}"
|
||||
echo "section1 var1 = ${INI__section1__var1}"
|
||||
echo "section1 var2 = ${INI__section1__var2}"
|
||||
|
||||
-- END bash script
|
||||
|
||||
|
||||
|
||||
|
||||
OPTIONS
|
||||
-------
|
||||
|
||||
[--prefix | -p] PREFIX
|
||||
String to prepend to generated variable names (automatically followed by '__').
|
||||
Default: INI
|
||||
|
||||
[--booleans | -b] [0|1]
|
||||
Whether to interpret special unquoted string values 'yes', 'no', 'true',
|
||||
'false', 'on', 'off' as booleans.
|
||||
Default: 1
|
||||
|
||||
|
||||
|
||||
|
||||
INI FILE FORMAT
|
||||
---------------
|
||||
|
||||
- Variables are stored as name/value pairs, eg:
|
||||
var=value
|
||||
|
||||
- Leading and trailing whitespace of the name and the value is discarded.
|
||||
|
||||
- Use double or single quotes to get whitespace in the values
|
||||
|
||||
- Section names in square brackets, eg:
|
||||
[section1]
|
||||
var1 = value
|
||||
|
||||
- Variable names can be re-used between sections (or out of section), eg:
|
||||
var1=value
|
||||
[section1]
|
||||
var1=value
|
||||
[section3]
|
||||
var1=value
|
||||
|
||||
- Dots are converted to underscores in all variable names.
|
||||
|
||||
- Special boolean values: unquoted strings 'yes', 'true' and 'on' are interpreted
|
||||
as 1; 'no', 'false' and 'off' are interpreted as 0
|
||||
|
||||
|
||||
|
||||
7
bits/other-peoples/someone_elses_bash_ini_parser/TODO
Normal file
7
bits/other-peoples/someone_elses_bash_ini_parser/TODO
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
- Tabs/newlines to be preserved
|
||||
|
||||
- [] notation for arrays (like PHP's parse_ini_file())
|
||||
|
||||
|
||||
272
bits/other-peoples/someone_elses_bash_ini_parser/read_ini.sh
Executable file
272
bits/other-peoples/someone_elses_bash_ini_parser/read_ini.sh
Executable file
|
|
@ -0,0 +1,272 @@
|
|||
#
|
||||
# Copyright (c) 2009 Kevin Porter / Advanced Web Construction Ltd
|
||||
# (http://coding.tinternet.info, http://webutils.co.uk)
|
||||
# Copyright (c) 2010, 2011 Ruediger Meier <sweet_f_a@gmx.de>
|
||||
# (https://github.com/rudimeier/)
|
||||
#
|
||||
# Simple INI file parser.
|
||||
#
|
||||
# See README for usage.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
function read_ini()
|
||||
{
|
||||
# Be strict with the prefix, since it's going to be run through eval
|
||||
function check_prefix()
|
||||
{
|
||||
if ! [[ "${VARNAME_PREFIX}" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] ;then
|
||||
echo "read_ini: invalid prefix '${VARNAME_PREFIX}'" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function check_ini_file()
|
||||
{
|
||||
if [ ! -r "$INI_FILE" ] ;then
|
||||
echo "read_ini: '${INI_FILE}' doesn't exist or not" \
|
||||
"readable" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# enable some optional shell behavior (shopt)
|
||||
function pollute_bash()
|
||||
{
|
||||
if ! shopt -q extglob ;then
|
||||
SWITCH_SHOPT="${SWITCH_SHOPT} extglob"
|
||||
fi
|
||||
if ! shopt -q nocasematch ;then
|
||||
SWITCH_SHOPT="${SWITCH_SHOPT} nocasematch"
|
||||
fi
|
||||
shopt -q -s ${SWITCH_SHOPT}
|
||||
}
|
||||
|
||||
# unset all local functions and restore shopt settings before returning
|
||||
# from read_ini()
|
||||
function cleanup_bash()
|
||||
{
|
||||
shopt -q -u ${SWITCH_SHOPT}
|
||||
unset -f check_prefix check_ini_file pollute_bash cleanup_bash
|
||||
}
|
||||
|
||||
local INI_FILE=""
|
||||
local INI_SECTION=""
|
||||
|
||||
# {{{ START Deal with command line args
|
||||
|
||||
# Set defaults
|
||||
local BOOLEANS=1
|
||||
local VARNAME_PREFIX=INI
|
||||
local CLEAN_ENV=0
|
||||
|
||||
# {{{ START Options
|
||||
|
||||
# Available options:
|
||||
# --boolean Whether to recognise special boolean values: ie for 'yes', 'true'
|
||||
# and 'on' return 1; for 'no', 'false' and 'off' return 0. Quoted
|
||||
# values will be left as strings
|
||||
# Default: on
|
||||
#
|
||||
# --prefix=STRING String to begin all returned variables with (followed by '__').
|
||||
# Default: INI
|
||||
#
|
||||
# First non-option arg is filename, second is section name
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
|
||||
case $1 in
|
||||
|
||||
--clean | -c )
|
||||
CLEAN_ENV=1
|
||||
;;
|
||||
|
||||
--booleans | -b )
|
||||
shift
|
||||
BOOLEANS=$1
|
||||
;;
|
||||
|
||||
--prefix | -p )
|
||||
shift
|
||||
VARNAME_PREFIX=$1
|
||||
;;
|
||||
|
||||
* )
|
||||
if [ -z "$INI_FILE" ]
|
||||
then
|
||||
INI_FILE=$1
|
||||
else
|
||||
if [ -z "$INI_SECTION" ]
|
||||
then
|
||||
INI_SECTION=$1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "$INI_FILE" ] && [ "${CLEAN_ENV}" = 0 ] ;then
|
||||
echo -e "Usage: read_ini [-c] [-b 0| -b 1]] [-p PREFIX] FILE"\
|
||||
"[SECTION]\n or read_ini -c [-p PREFIX]" >&2
|
||||
cleanup_bash
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! check_prefix ;then
|
||||
cleanup_bash
|
||||
return 1
|
||||
fi
|
||||
|
||||
local INI_ALL_VARNAME="${VARNAME_PREFIX}__ALL_VARS"
|
||||
if [ "${CLEAN_ENV}" = 1 ] ;then
|
||||
eval unset "\$${INI_ALL_VARNAME}"
|
||||
fi
|
||||
unset ${INI_ALL_VARNAME}
|
||||
|
||||
if [ -z "$INI_FILE" ] ;then
|
||||
cleanup_bash
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! check_ini_file ;then
|
||||
cleanup_bash
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Sanitise BOOLEANS - interpret "0" as 0, anything else as 1
|
||||
if [ "$BOOLEANS" != "0" ]
|
||||
then
|
||||
BOOLEANS=1
|
||||
fi
|
||||
|
||||
|
||||
# }}} END Options
|
||||
|
||||
# }}} END Deal with command line args
|
||||
|
||||
local LINE_NUM=0
|
||||
local SECTION=""
|
||||
|
||||
# IFS is used in "read" and we want to switch it within the loop
|
||||
local IFS=$' \t\n'
|
||||
local IFS_OLD="${IFS}"
|
||||
|
||||
# we need some optional shell behavior (shopt) but want to restore
|
||||
# current settings before returning
|
||||
local SWITCH_SHOPT=""
|
||||
pollute_bash
|
||||
|
||||
while read -r line
|
||||
do
|
||||
#echo line = "$line"
|
||||
|
||||
((LINE_NUM++))
|
||||
|
||||
# Skip blank lines and comments
|
||||
if [ -z "$line" -o "${line:0:1}" = ";" -o "${line:0:1}" = "#" ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Section marker?
|
||||
if [[ "${line}" =~ ^\[[a-zA-Z0-9_]{1,}\]$ ]]
|
||||
then
|
||||
|
||||
# Set SECTION var to name of section (strip [ and ] from section marker)
|
||||
SECTION="${line#[}"
|
||||
SECTION="${SECTION%]}"
|
||||
|
||||
continue
|
||||
fi
|
||||
|
||||
# Are we getting only a specific section? And are we currently in it?
|
||||
if [ ! -z "$INI_SECTION" ]
|
||||
then
|
||||
if [ "$SECTION" != "$INI_SECTION" ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Valid var/value line? (check for variable name and then '=')
|
||||
if ! [[ "${line}" =~ ^[a-zA-Z0-9._]{1,}[[:space:]]*= ]]
|
||||
then
|
||||
echo "Error: Invalid line:" >&2
|
||||
echo " ${LINE_NUM}: $line" >&2
|
||||
cleanup_bash
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
# split line at "=" sign
|
||||
IFS="="
|
||||
read -r VAR VAL <<< "${line}"
|
||||
IFS="${IFS_OLD}"
|
||||
|
||||
# delete spaces around the equal sign (using extglob)
|
||||
VAR="${VAR%%+([[:space:]])}"
|
||||
VAL="${VAL##+([[:space:]])}"
|
||||
VAR=$(echo $VAR)
|
||||
|
||||
|
||||
# Construct variable name:
|
||||
# ${VARNAME_PREFIX}__$SECTION__$VAR
|
||||
# Or if not in a section:
|
||||
# ${VARNAME_PREFIX}__$VAR
|
||||
# In both cases, full stops ('.') are replaced with underscores ('_')
|
||||
if [ -z "$SECTION" ]
|
||||
then
|
||||
VARNAME=${VARNAME_PREFIX}__${VAR//./_}
|
||||
else
|
||||
VARNAME=${VARNAME_PREFIX}__${SECTION}__${VAR//./_}
|
||||
fi
|
||||
eval "${INI_ALL_VARNAME}=\"\$${INI_ALL_VARNAME} ${VARNAME}\""
|
||||
|
||||
if [[ "${VAL}" =~ ^\".*\"$ ]]
|
||||
then
|
||||
# remove existing double quotes
|
||||
VAL="${VAL##\"}"
|
||||
VAL="${VAL%%\"}"
|
||||
elif [[ "${VAL}" =~ ^\'.*\'$ ]]
|
||||
then
|
||||
# remove existing single quotes
|
||||
VAL="${VAL##\'}"
|
||||
VAL="${VAL%%\'}"
|
||||
elif [ "$BOOLEANS" = 1 ]
|
||||
then
|
||||
# Value is not enclosed in quotes
|
||||
# Booleans processing is switched on, check for special boolean
|
||||
# values and convert
|
||||
|
||||
# here we compare case insensitive because
|
||||
# "shopt nocasematch"
|
||||
case "$VAL" in
|
||||
yes | true | on )
|
||||
VAL=1
|
||||
;;
|
||||
no | false | off )
|
||||
VAL=0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
# enclose the value in single quotes and escape any
|
||||
# single quotes and backslashes that may be in the value
|
||||
VAL="${VAL//\\/\\\\}"
|
||||
VAL="\$'${VAL//\'/\'}'"
|
||||
|
||||
eval "$VARNAME=$VAL"
|
||||
done <"${INI_FILE}"
|
||||
|
||||
cleanup_bash
|
||||
}
|
||||
|
||||
|
||||
28
bits/other-peoples/someone_elses_bash_ini_parser/test/test.sh
Executable file
28
bits/other-peoples/someone_elses_bash_ini_parser/test/test.sh
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
DIR=$(dirname $0)
|
||||
cd $DIR
|
||||
|
||||
TESTS=$(ls test*.sh | grep -v test.sh | sed 's/\.sh$//')
|
||||
|
||||
for test in $TESTS
|
||||
do
|
||||
|
||||
bash $test.sh &> $test.out
|
||||
# bash $test.sh >$test.out 2>$test.err
|
||||
|
||||
# Fail and bail out if test didn't pass
|
||||
PASSED=$(diff $test.out $test.out.correct 2>&1)
|
||||
if [ ! -z "$PASSED" ]
|
||||
then
|
||||
echo "Test $test failed. Output is in $DIR/$test.out"
|
||||
exit 1
|
||||
else
|
||||
rm -rf $test.out
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
||||
echo "All tests passed"
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
; Comment beginning with ';'
|
||||
# Comment beginning with '#'
|
||||
|
||||
; var1 - simple var
|
||||
var1=VAR 1
|
||||
|
||||
; var2 - space before '='; leading space that should be stripped
|
||||
var2 = VAR 2
|
||||
|
||||
; var3 - with leading and trailing space that should be stripped
|
||||
var3 = VAR 3
|
||||
|
||||
; var4 - value in double quotes
|
||||
var4="VAR 4"
|
||||
|
||||
; var5 - value in double quotes; value's leading and trailing whitespace should
|
||||
; be preserved; leading and trailing whitespace before/after double quotes should
|
||||
; not become part of the value
|
||||
var5 = " VAR 5 "
|
||||
|
||||
; var6 - value in double quotes; value's leading and trailing whitespace should
|
||||
; be preserved; leading and trailing whitespace before/after double quotes should
|
||||
; not become part of the value
|
||||
var6 = ' VAR 6 '
|
||||
|
||||
; var7 - value contains a single double quote
|
||||
var7 = VAR " 7
|
||||
|
||||
; var8 - value contains a single single quote
|
||||
var8 = VAR ' 8
|
||||
|
||||
; var9 - leading whitespace before variable name
|
||||
var9=VAR 9
|
||||
|
||||
; var10 - leading whitespace before variable name
|
||||
var10 = VAR 10
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
var1:VAR 1
|
||||
var2:VAR 2
|
||||
var3:VAR 3
|
||||
var4:VAR 4
|
||||
var5: VAR 5
|
||||
var6: VAR 6
|
||||
var7:VAR " 7
|
||||
var8:VAR ' 8
|
||||
var9:VAR 9
|
||||
var10:VAR 10
|
||||
21
bits/other-peoples/someone_elses_bash_ini_parser/test/test1.sh
Executable file
21
bits/other-peoples/someone_elses_bash_ini_parser/test/test1.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
|
||||
# Test 1
|
||||
#
|
||||
# Basic variable values; leading/trailing whitespace; comments
|
||||
|
||||
. ../read_ini.sh
|
||||
read_ini test1.ini
|
||||
|
||||
#echo "a:LOCALVAR=$LOCALVAR"
|
||||
echo "var1:$INI__var1"
|
||||
echo "var2:$INI__var2"
|
||||
echo "var3:$INI__var3"
|
||||
echo "var4:$INI__var4"
|
||||
echo "var5:$INI__var5"
|
||||
echo "var6:$INI__var6"
|
||||
echo "var7:$INI__var7"
|
||||
echo "var8:$INI__var8"
|
||||
echo "var9:$INI__var9"
|
||||
echo "var10:$INI__var10"
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
var1=VAR1
|
||||
|
||||
; Invalid line - should throw an error and stop processing
|
||||
INVALID LINE
|
||||
var2=VAR2
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Error: Invalid line:
|
||||
6: INVALID LINE
|
||||
8
bits/other-peoples/someone_elses_bash_ini_parser/test/test2.sh
Executable file
8
bits/other-peoples/someone_elses_bash_ini_parser/test/test2.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
# Test 2
|
||||
#
|
||||
# Invalid line
|
||||
|
||||
. ../read_ini.sh
|
||||
read_ini test2.ini
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
; Testing sections
|
||||
|
||||
var1=VAR 1
|
||||
var2= "VAR 2 "
|
||||
|
||||
[section1]
|
||||
var1="section 1 VAR 1"
|
||||
var2= "section 1 VAR 2"
|
||||
var3 = "section 1 VAR 3 "
|
||||
|
||||
[section2]
|
||||
var1 = section 2 VAR 1
|
||||
var2=" section 2 VAR 2"
|
||||
var3=section 2 VAR 3
|
||||
var4=section 2 VAR 4
|
||||
var5=section 2 VAR 5
|
||||
|
||||
[section3]
|
||||
var1="section 3 VAR 1"
|
||||
var2= "section 3 VAR 2"
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
var1:VAR 1
|
||||
var2:VAR 2
|
||||
setion1_var1:section 1 VAR 1
|
||||
setion1_var2:section 1 VAR 2
|
||||
setion1_var3:section 1 VAR 3
|
||||
setion2_var1:section 2 VAR 1
|
||||
setion2_var2: section 2 VAR 2
|
||||
setion2_var3:section 2 VAR 3
|
||||
setion2_var4:section 2 VAR 4
|
||||
setion2_var5:section 2 VAR 5
|
||||
setion3_var1:section 3 VAR 1
|
||||
setion3_var2:section 3 VAR 2
|
||||
25
bits/other-peoples/someone_elses_bash_ini_parser/test/test3.sh
Executable file
25
bits/other-peoples/someone_elses_bash_ini_parser/test/test3.sh
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
# Test 3
|
||||
#
|
||||
# Sections
|
||||
|
||||
. ../read_ini.sh
|
||||
read_ini test3.ini
|
||||
|
||||
echo "var1:$INI__var1"
|
||||
echo "var2:$INI__var2"
|
||||
|
||||
echo "setion1_var1:$INI__section1__var1"
|
||||
echo "setion1_var2:$INI__section1__var2"
|
||||
echo "setion1_var3:$INI__section1__var3"
|
||||
|
||||
echo "setion2_var1:$INI__section2__var1"
|
||||
echo "setion2_var2:$INI__section2__var2"
|
||||
echo "setion2_var3:$INI__section2__var3"
|
||||
echo "setion2_var4:$INI__section2__var4"
|
||||
echo "setion2_var5:$INI__section2__var5"
|
||||
|
||||
echo "setion3_var1:$INI__section3__var1"
|
||||
echo "setion3_var2:$INI__section3__var2"
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
; Testing dots in variable names (these get converted to underscores in
|
||||
; output variable names)
|
||||
|
||||
var.1 = "VAR 1"
|
||||
var.two="VAR 2"
|
||||
var.3.two_dots="VAR 3"
|
||||
|
||||
|
||||
[section1]
|
||||
var.1="section 1 VAR 1"
|
||||
var.two="section 1 VAR 2"
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
var_1:VAR 1
|
||||
var_two:VAR 2
|
||||
var_3_two_dots:VAR 3
|
||||
section 1 var_1:section 1 VAR 1
|
||||
section 1 var_two:section 1 VAR 2
|
||||
15
bits/other-peoples/someone_elses_bash_ini_parser/test/test4.sh
Executable file
15
bits/other-peoples/someone_elses_bash_ini_parser/test/test4.sh
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
# Test 4
|
||||
#
|
||||
# Dots in variable names (converted to underscores in output var names)
|
||||
|
||||
. ../read_ini.sh
|
||||
read_ini test4.ini
|
||||
|
||||
echo "var_1:$INI__var_1"
|
||||
echo "var_two:$INI__var_two"
|
||||
echo "var_3_two_dots:$INI__var_3_two_dots"
|
||||
|
||||
echo "section 1 var_1:$INI__section1__var_1"
|
||||
echo "section 1 var_two:$INI__section1__var_two"
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
; Testing prevention of in-value code execution via eval
|
||||
var1 = blah blah `ls` blah
|
||||
var2 = blah blah $(ls) blah
|
||||
|
||||
; these code injections worked on 0.3
|
||||
var3 = blah blah \\`ls\\` blah
|
||||
var4 = blah blah \\$(ls) blah
|
||||
|
||||
; these code injections could work with read -r
|
||||
var5 = blah blah \`ls\` blah
|
||||
var6 = blah blah \$(ls) blah
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
var1:blah blah `ls` blah
|
||||
var2:blah blah $(ls) blah
|
||||
var3:blah blah \\`ls\\` blah
|
||||
var4:blah blah \\$(ls) blah
|
||||
var5:blah blah \`ls\` blah
|
||||
var6:blah blah \$(ls) blah
|
||||
16
bits/other-peoples/someone_elses_bash_ini_parser/test/test5.sh
Executable file
16
bits/other-peoples/someone_elses_bash_ini_parser/test/test5.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
|
||||
# Test 5
|
||||
#
|
||||
# Prevention of in-value code execution via backticks or $() notation.
|
||||
# This must be done because the value is run through an eval statement.
|
||||
|
||||
. ../read_ini.sh
|
||||
read_ini test5.ini
|
||||
|
||||
echo "var1:$INI__var1"
|
||||
echo "var2:$INI__var2"
|
||||
echo "var3:$INI__var3"
|
||||
echo "var4:$INI__var4"
|
||||
echo "var5:$INI__var5"
|
||||
echo "var6:$INI__var6"
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
|
||||
; Testing processing of special boolean constants: unquoted
|
||||
; strings 'yes', 'true' and 'on' are interpreted as 1;
|
||||
; unquoted strings 'no', 'false' and 'off' as 0.
|
||||
|
||||
yes1 = yes
|
||||
yes2 = "yes"
|
||||
yes3 = Yes
|
||||
true1=true
|
||||
true2= true
|
||||
true3 = "tRuE"
|
||||
on1 = on
|
||||
on2 = oN
|
||||
on3 = "ON"
|
||||
|
||||
no1 = no
|
||||
no2 = "no"
|
||||
no3=No
|
||||
false1 = false
|
||||
false2 = faLSe
|
||||
false3 = "FALSE"
|
||||
off1 = off
|
||||
off2 = Off
|
||||
off3 = "off"
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
yes1:1
|
||||
yes2:yes
|
||||
yes3:1
|
||||
true1:1
|
||||
true2:1
|
||||
true3:tRuE
|
||||
on1:1
|
||||
on2:1
|
||||
on3:ON
|
||||
no1:0
|
||||
no2:no
|
||||
no3:0
|
||||
false1:0
|
||||
false2:0
|
||||
false3:FALSE
|
||||
off1:0
|
||||
off2:0
|
||||
off3:off
|
||||
yes1:1
|
||||
true2:1
|
||||
on3:ON
|
||||
no3:0
|
||||
false2:0
|
||||
off1:0
|
||||
yes1:yes
|
||||
true2:true
|
||||
on3:ON
|
||||
no3:No
|
||||
false2:faLSe
|
||||
off1:off
|
||||
56
bits/other-peoples/someone_elses_bash_ini_parser/test/test6.sh
Executable file
56
bits/other-peoples/someone_elses_bash_ini_parser/test/test6.sh
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
# Testing booleans processing
|
||||
|
||||
# First: with default booleans processing (on)
|
||||
. ../read_ini.sh
|
||||
read_ini test6.ini
|
||||
|
||||
echo "yes1:$INI__yes1"
|
||||
echo "yes2:$INI__yes2"
|
||||
echo "yes3:$INI__yes3"
|
||||
echo "true1:$INI__true1"
|
||||
echo "true2:$INI__true2"
|
||||
echo "true3:$INI__true3"
|
||||
echo "on1:$INI__on1"
|
||||
echo "on2:$INI__on2"
|
||||
echo "on3:$INI__on3"
|
||||
|
||||
echo "no1:$INI__no1"
|
||||
echo "no2:$INI__no2"
|
||||
echo "no3:$INI__no3"
|
||||
echo "false1:$INI__false1"
|
||||
echo "false2:$INI__false2"
|
||||
echo "false3:$INI__false3"
|
||||
echo "off1:$INI__off1"
|
||||
echo "off2:$INI__off2"
|
||||
echo "off3:$INI__off3"
|
||||
|
||||
|
||||
# Second: with booleans processing explicitly turned on via "--booleans 1"
|
||||
. ../read_ini.sh
|
||||
read_ini --booleans 1 test6.ini
|
||||
|
||||
echo "yes1:$INI__yes1"
|
||||
echo "true2:$INI__true2"
|
||||
echo "on3:$INI__on3"
|
||||
|
||||
echo "no3:$INI__no3"
|
||||
echo "false2:$INI__false2"
|
||||
echo "off1:$INI__off1"
|
||||
|
||||
|
||||
# Third: with booleans processing explicity switched off via "--booleans 0"
|
||||
. ../read_ini.sh
|
||||
read_ini test6.ini --booleans 0
|
||||
|
||||
echo "yes1:$INI__yes1"
|
||||
echo "true2:$INI__true2"
|
||||
echo "on3:$INI__on3"
|
||||
|
||||
echo "no3:$INI__no3"
|
||||
echo "false2:$INI__false2"
|
||||
echo "off1:$INI__off1"
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
; Simple definitions for testing --prefix option
|
||||
|
||||
var1=VAR 1
|
||||
|
||||
[section1]
|
||||
var1 = "section 1 VAR 1"
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# 1
|
||||
var1:VAR 1
|
||||
section1 var1:section 1 VAR 1
|
||||
# 2
|
||||
read_ini: invalid prefix 'PR:EFIX,'
|
||||
# 3
|
||||
read_ini: invalid prefix '1PREFIX'
|
||||
30
bits/other-peoples/someone_elses_bash_ini_parser/test/test7.sh
Executable file
30
bits/other-peoples/someone_elses_bash_ini_parser/test/test7.sh
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
# Test 7
|
||||
#
|
||||
# Option: [--prefix | -p] PREFIX
|
||||
|
||||
# First: valid value for prefix
|
||||
echo "# 1"
|
||||
. ../read_ini.sh
|
||||
read_ini test7.ini --prefix PREFIX1
|
||||
|
||||
echo "var1:$PREFIX1__var1"
|
||||
echo "section1 var1:$PREFIX1__section1__var1"
|
||||
|
||||
# Second: invalid value for prefix (contains illegal chars)
|
||||
echo "# 2"
|
||||
. ../read_ini.sh
|
||||
read_ini -p PR:EFIX, test7.ini &&
|
||||
{
|
||||
echo "var1:$PREFIX1__var1"
|
||||
echo "section1 var1:$PREFIX1__section1__var1"
|
||||
}
|
||||
|
||||
# Third: invalid value for prefix (begins with a number)
|
||||
echo "# 3"
|
||||
. ../read_ini.sh
|
||||
read_ini --prefix 1PREFIX test7.ini &&
|
||||
{
|
||||
echo "var1:$PREFIX1__var1"
|
||||
echo "section1 var1:$PREFIX1__section1__var1"
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
; this code injection via section worked on 0.3
|
||||
[x=blah; ls ;]
|
||||
var1 = blah
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Error: Invalid line:
|
||||
3: [x=blah; ls ;]
|
||||
9
bits/other-peoples/someone_elses_bash_ini_parser/test/test8.sh
Executable file
9
bits/other-peoples/someone_elses_bash_ini_parser/test/test8.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
|
||||
# Test 8
|
||||
#
|
||||
# Prevention of in-value code execution via invalid section
|
||||
|
||||
. ../read_ini.sh
|
||||
read_ini test8.ini
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
; Testing quoted quotes (didnt't worked in 0.3)
|
||||
|
||||
; code injection
|
||||
var1="" ls "."
|
||||
var2='' ls '.'
|
||||
|
||||
; or just an error: unexpected EOF while looking for matching `"'
|
||||
var3="""
|
||||
var4='''
|
||||
var5="
|
||||
var6='
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
var1:" ls ".
|
||||
var2:' ls '.
|
||||
var3:"
|
||||
var4:'
|
||||
var5:"
|
||||
var6:'
|
||||
16
bits/other-peoples/someone_elses_bash_ini_parser/test/test9.sh
Executable file
16
bits/other-peoples/someone_elses_bash_ini_parser/test/test9.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
# Test 9
|
||||
#
|
||||
# further stuff which didn't worked in 0.3
|
||||
|
||||
. ../read_ini.sh
|
||||
if ! read_ini test9.ini ;then exit 1; fi
|
||||
|
||||
|
||||
echo "var1:$INI__var1"
|
||||
echo "var2:$INI__var2"
|
||||
echo "var3:$INI__var3"
|
||||
echo "var4:$INI__var4"
|
||||
echo "var5:$INI__var5"
|
||||
echo "var6:$INI__var6"
|
||||
|
||||
1
bits/other-peoples/someone_elses_bash_ini_parser/url
Normal file
1
bits/other-peoples/someone_elses_bash_ini_parser/url
Normal file
|
|
@ -0,0 +1 @@
|
|||
https://github.com/rudimeier/bash_ini_parser
|
||||
Loading…
Add table
Add a link
Reference in a new issue