--- /dev/null
+[submodule "helpers/libshell"]
+ path = helpers/libshell
+ url = git://git.infradead.org/users/jekeller/libshell.git
--- /dev/null
+Subproject commit fc6e764d9e22600b1f42c909f1787ea769d90191
+++ /dev/null
-The file
- shell-getopt
-Version 1.2 2008 by Alexey Gladkov <legion@altlinux.org>,
- 2008 by Dmitry V. Levin <ldv@altlinux.org>
-Version 1.1 2004 by Raphael <raphael at oninet dot pt>
-Version 1.0 1997 by Grigoriy Strokin (grg@philol.msu.ru), Public Domain
-
-The files
- shell-quote, shell-args
-are Copyright (C) 2007 Dmitry V. Levin <ldv@altlinux.org>,
- 2008 Alexey Gladkov <legion@altlinux.org>
-
-The file
- shell-ini-config
-are Copyright (C) 2008 Stanislav Ievlev <inger@altlinux.org>,
- 2008 Alexey Gladkov <legion@altlinux.org>
-
-The files
- shell-version, shell-cmdline, shell-config, shell-error,
- shell-ip-address, shell-mail-address, shell-unittest,
- shell-signal, shell-var, shell-source shell-run
-are Copyright (C) 2009-2011 Alexey Gladkov <legion@altlinux.org>
-
-All files in this package may be freely copied under the terms
-of the GNU General Public License (GPL), version 2, or at your
-option any later version.
+++ /dev/null
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
+++ /dev/null
-DESTDIR =
-datadir = /usr/share
-man3dir = ${datadir}/man/man3
-bindir = /bin
-
-bin_TARGETS = shell-args shell-cmdline shell-config shell-error shell-getopt \
- shell-ini-config shell-ip-address shell-mail-address shell-quote \
- shell-regexp shell-signal shell-unittest shell-version shell-var \
- shell-source shell-string shell-run
-
-data_TARGETS = COPYING SYMS
-
-man_TARGETS = docs/libshell.man docs/shell-error.man
-
-install: install-bin install-man
-
-install-bin: ${bin_TARGETS}
- install -d -m755 ${DESTDIR}${bindir}
- cp -a $^ ${DESTDIR}${bindir}/
-
-install-man: ${man_TARGETS}
- install -d -m755 ${DESTDIR}${man3dir}
- for i in $^; do \
- d="$${i%.man}.3"; d="$${d##*/}"; \
- install -m644 $$i ${DESTDIR}${man3dir}/$$d; \
- done
-
-check:
- @cd tests; ./runtests
+++ /dev/null
-shell-args opt_check_dir
-shell-args opt_check_number
-shell-args opt_check_read
-shell-args parse_common_option
-shell-args print_version
-shell-args show_help
-shell-args show_usage
-shell-cmdline cmdline_foreach
-shell-cmdline cmdline_get
-shell-config shell_config_comment
-shell-config shell_config_del
-shell-config shell_config_get
-shell-config shell_config_set
-shell-error fatal
-shell-error message
-shell-error verbose
-shell-getopt getopt
-shell-getopt getoptex
-shell-getopt getopts
-shell-getopt getsubopt
-shell-ini-config ini_config_comment
-shell-ini-config ini_config_del
-shell-ini-config ini_config_get
-shell-ini-config ini_config_set
-shell-ip-address ipv4_ip_subnet
-shell-ip-address ipv4_mask2prefix
-shell-ip-address ipv4_prefix2mask
-shell-ip-address valid_ipv4
-shell-mail-address valid_email
-shell-quote quote_sed_regexp
-shell-quote quote_sed_regexp_variable
-shell-quote quote_shell
-shell-quote quote_shell_args
-shell-quote quote_shell_variable
-shell-quote string_quote_remove
-shell-run run_if_executable
-shell-run run_scripts
-shell-signal set_cleanup_handler
-shell-signal signal_handler
-shell-signal unset_cleanup_handler
-shell-source source_if_executable
-shell-source source_if_exists
-shell-source source_if_notempty
-shell-string fill_mask
-shell-unittest appendTests
-shell-unittest assertEquals
-shell-unittest assertFalse
-shell-unittest assertNotEquals
-shell-unittest assertNotNull
-shell-unittest assertNotSame
-shell-unittest assertNull
-shell-unittest assertSame
-shell-unittest assertTrue
-shell-unittest messageTest
-shell-unittest registerTests
-shell-unittest runUnitTests
-shell-unittest setUp
-shell-unittest setUpTests
-shell-unittest shouldSkip
-shell-unittest showSummary
-shell-unittest tearDown
-shell-unittest tearDownTests
-shell-var shell_var_is_no
-shell-var shell_var_is_yes
-shell-var shell_var_trim
-shell-var shell_var_unquote
+++ /dev/null
-#From: "Grigoriy Strokin" <grg@philol.msu.ru>
-#Newsgroups: comp.unix.shell
-#Subject: BASH: getopt function that parses long-named options
-#Date: Mon, 22 Dec 1997 20:35:18 +0300
-
-#Hi, I have written a BASH function named getoptex, that is like bash builtin
-#"getopts", but does parse long-named options and optional arguments. It only
-#uses builtin bash commands, so it is very fast. In order to use it in your
-#bash scripts, include a command ". getopt.sh" (<dot> getopt.sh) to the file
-#containing your script, and that will define functions getopt, getoptex, and
-#optlistex (the file getopt.sh with its detailed description is listed
-#below).
-
-#*** file getopt.sh ***
-
-#! /bin/bash
-#
-# getopt.sh:
-# functions like getopts but do long-named options parsing
-# and support optional arguments
-#
-# Version 1.0 1997 by Grigoriy Strokin (grg@philol.msu.ru), Public Domain
-# Date created: December 21, 1997
-# Date modified: December 21, 1997
-#
-# IMPORTANT FEATURES
-#
-# 1) Parses both short and long-named options
-# 2) Supports optional arguments
-# 3) Only uses bash builtins, thus no calls to external
-# utilities such as expr or sed is done. Therefore,
-# parsing speed is high enough
-#
-#
-# DESCRIPTION
-#
-# FUNCTION getopt
-# Usage: getopt OPTLIST {"$@"|ALTERNATIVE_PARAMETERS}
-#
-# like getopts, but parse options with both required and optional arguments,
-# Options with optional arguments must have "." instead of ":" after them.
-# Furthemore, a variable name to place option name cannot be specified
-# and is always placed in OPTOPT variable
-#
-# This function is provided for compatibility with getopts()
-# OPTLIST style, and it actually calls getoptex (see bellow)
-#
-# NOTE that a list of parameters is required and must be either "$@",
-# if processing command line arguments, or some alternative parameters.
-#
-# FUNCTION getoptex
-# Usage: getoptex OPTION_LIST {"$@"|ALTERNATIVE_PARAMETERS}
-#
-# like getopts, but parse long-named options.
-#
-# Both getopt and getoptex return 0 if an option has been parsed,
-# and 1 if all options are already parsed or an error occured
-#
-# Both getopt and getoptex set or test the following variables:
-#
-# OPTERR -- tested for whether error messages must be given for invalid
-options
-#
-# OPTOPT -- set to the name of an option parsed,
-# or to "?" if no more options or error
-# OPTARG -- set to the option argument, if any;
-# unset if ther is no argument;
-# on error, set to the erroneous option name
-#
-# OPTIND -- Initialized to 1.
-# Then set to the number of the next parameter to be parsed
-# when getopt or getoptex will be called next time.
-# When all options are parsed, contains a number of
-# the first non-option argument.
-#
-#
-# OPTOFS -- If a parameter number $OPTIND containg an option parsed
-# does not contain any more options, OPTOFS is unset;
-# otherwise, OPTOFS is set to such a number of "?" signs
-# which is equal to the number of options parsed
-#
-# You might not set variables OPTIND and OPTOFS yourself
-# unless you want to parse a list of parameters more than once.
-# Otherwise, you whould unset OPTIND (or set it to 1)
-# and unset OPTOFS each time you want to parse a new parameters
-list
-#
-# Option list format is DIFFERENT from one for getopts or getopt.
-getopts-style
-# option list can be converted to getoptex-style using a function optlistex
-# (see bellow)
-#
-# DESCRIPTION of option list used with getoptex:
-# Option names are separated by whitespace. Options consiting of
-# more than one character are treated as long-named (--option)
-#
-# Special characters can appear at the and of option names specifying
-# whether an argument is required (default is ";"):
-# ";" (default) -- no argument
-# ":" -- required argument
-# "," -- optional argument
-#
-# For example, an option list "a b c help version f: file: separator."
-# defines the following options:
-# -a, -b, -c, --help, --version -- no argument
-# -f, --file -- argument required
-# --separator -- optional argument
-#
-# FUNCTION optlistex
-# Usage new_style_optlist=`optlistex OLD_STYLE_OPTLIST`
-#
-# Converts getopts-style option list in a format suitable for use with getoptex
-# Namely, it inserts spaces after each option name.
-#
-#
-# HOW TO USE
-#
-# In order o use in your bash scripts the functions described,
-# include a command ". getopt.sh" to the file containing the script,
-# which will define functions getopt, getoptex, and optlistex
-#
-# EXAMPLES
-#
-# See files 'getopt1' and 'getopt2' that contain sample scripts that use
-# getopt and getoptex functions respectively
-#
-#
-# Please send your comments to grg@philol.msu.ru
-
-function getoptex()
-{
- let $# || return 1
- local optlist="${1#;}"
- let OPTIND || OPTIND=1
- [ $OPTIND -lt $# ] || return 1
- shift $OPTIND
- if [ "$1" != "-" ] && [ "$1" != "${1#-}" ]
- then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ]
- then
- local o
- o="-${1#-$OPTOFS}"
- for opt in ${optlist#;}
- do
- OPTOPT="${opt%[;.:]}"
- unset OPTARG
- local opttype="${opt##*[^;:.]}"
- [ -z "$opttype" ] && opttype=";"
- if [ ${#OPTOPT} -gt 1 ]
- then # long-named option
- case $o in
- "--$OPTOPT")
- if [ "$opttype" != ":" ]; then return 0; fi
- OPTARG="$2"
- if [ -z "$OPTARG" ];
- then # error: must have an agrument
- let OPTERR && echo "$0: error: $OPTOPT must have an argument" >&2
- OPTARG="$OPTOPT";
- OPTOPT="?"
- return 1;
- fi
- OPTIND=$[OPTIND+1] # skip option's argument
- return 0
- ;;
- "--$OPTOPT="*)
- if [ "$opttype" = ";" ];
- then # error: must not have arguments
- let OPTERR && echo "$0: error: $OPTOPT must not have arguments" >&2
- OPTARG="$OPTOPT"
- OPTOPT="?"
- return 1
- fi
- OPTARG=${o#"--$OPTOPT="}
- return 0
- ;;
- esac
- else # short-named option
- case "$o" in
- "-$OPTOPT")
- unset OPTOFS
- [ "$opttype" != ":" ] && return 0
- OPTARG="$2"
- if [ -z "$OPTARG" ]
- then
- echo "$0: error: -$OPTOPT must have an argument" >&2
- OPTARG="$OPTOPT"
- OPTOPT="?"
- return 1
- fi
- OPTIND=$[OPTIND+1] # skip option's argument
- return 0
- ;;
- "-$OPTOPT"*)
- if [ $opttype = ";" ]
- then # an option with no argument is in a chain of options
- OPTOFS="$OPTOFS?" # move to the next option in the chain
- OPTIND=$[OPTIND-1] # the chain still has other options
- return 0
- else
- unset OPTOFS
- OPTARG="${o#-$OPTOPT}"
- return 0
- fi
- ;;
- esac
- fi
- done
- echo "$0: error: invalid option: $o"
- fi; fi
- OPTOPT="?"
- unset OPTARG
- return 1
-}
-function optlistex
-{
- local l="$1"
- local m # mask
- local r # to store result
- while [ ${#m} -lt $[${#l}-1] ]; do m="$m?"; done # create a "???..." mask
- while [ -n "$l" ]
- do
- r="${r:+"$r "}${l%$m}" # append the first character of $l to $r
- l="${l#?}" # cut the first charecter from $l
- m="${m#?}" # cut one "?" sign from m
- if [ -n "${l%%[^:.;]*}" ]
- then # a special character (";", ".", or ":") was found
- r="$r${l%$m}" # append it to $r
- l="${l#?}" # cut the special character from l
- m="${m#?}" # cut one more "?" sign
- fi
- done
- echo $r
-}
-function getopt()
-{
- local optlist=`optlistex "$1"`
- shift
- getoptex "$optlist" "$@"
- return $?
-}
-
-#**************************************
-# cut here
-#**************************************
-#*** (end of getopt.sh) ***
-
-
-#*** file getopt1 ***
-
-#! /bin/bash
-# getopt1:
-# Sample script using the function getopt
-#
-# Type something like "getopt1 -ab -d 10 -e20 text1 text2"
-# on the command line to see how it works
-#
-# See getopt.sh for more information
-#. getopt.sh
-#echo Using getopt to parse arguments:
-#while getopt "abcd:e." "$@"
-#do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-#done
-#shift $[OPTIND-1]
-#for arg in "$@"
-#do
-# echo "Non option argument <$arg>"
-#done
-#
-#**************************************
-# cut here
-#**************************************
-#*** (end of getopt1) ***
-#
-#
-#*** file getopt2 ***
-#
-#! /bin/bash
-# getopt2:
-# Sample script using the function getoptex
-#
-# Type something like "getopt2 -ab -d 10 -e20 --opt1 --opt4=100 text1 text2"
-# to see how it works
-#
-# See getopt.sh for more information
-. getopt.sh
-#echo Using getoptex to parse arguments:
-#while getoptex "a; b; c; d: e. opt1 opt2 opt3 opt4: opt5." "$@"
-#do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-#done
-#shift $[OPTIND-1]
-#for arg in "$@"
-#do
-# echo "Non option argument <$arg>"
-#done
-#
-#**************************************
-# cut here
-#**************************************
-#*** (end of getopt2) ***
-
+++ /dev/null
-#! /bin/bash
-#
-# getopt.sh:
-# functions like getopts but do long-named options parsing
-# and support optional arguments
-#
-# Version 1.1 2004 by Raphael <raphael at oninet dot pt>
-# Date modified: April 6, 2004
-# Version 1.0 1997 by Grigoriy Strokin (grg@philol.msu.ru), Public Domain
-# Date created: December 21, 1997
-# Date modified: December 21, 1997
-#
-# UPDATE (by raphael)
-#
-# I found the routine wouldn't report option that need arguments right
-# if they where between or before other options. Rather it would take
-# the following option as the argument. The routine now checks if
-# the required argument starts with a dash '-' indicating that it is an
-# option. See source below.
-#
-# IMPORTANT FEATURES
-#
-# 1) Parses both short and long-named options
-# 2) Supports optional arguments
-# 3) Only uses bash builtins, thus no calls to external
-# utilities such as expr or sed is done. Therefore,
-# parsing speed is high enough
-#
-#
-# DESCRIPTION
-#
-# FUNCTION getopt
-# Usage: getopt OPTLIST {"$@"|ALTERNATIVE_PARAMETERS}
-#
-# like getopts, but parse options with both required and optional arguments,
-# Options with optional arguments must have "." instead of ":" after them.
-# Furthemore, a variable name to place option name cannot be specified
-# and is always placed in OPTOPT variable
-#
-# This function is provided for compatibility with getopts()
-# OPTLIST style, and it actually calls getoptex (see bellow)
-#
-# NOTE that a list of parameters is required and must be either "$@",
-# if processing command line arguments, or some alternative parameters.
-#
-# FUNCTION getoptex
-# Usage: getoptex OPTION_LIST {"$@"|ALTERNATIVE_PARAMETERS}
-#
-# like getopts, but parse long-named options.
-#
-# Both getopt and getoptex return 0 if an option has been parsed,
-# and 1 if all options are already parsed or an error occured
-#
-# Both getopt and getoptex set or test the following variables:
-#
-# OPTERR -- tested for whether error messages must be given for invalid options
-#
-# OPTOPT -- set to the name of an option parsed,
-# or to "?" if no more options or error
-# OPTARG -- set to the option argument, if any;
-# unset if ther is no argument;
-# on error, set to the erroneous option name
-#
-# OPTIND -- Initialized to 1.
-# Then set to the number of the next parameter to be parsed
-# when getopt or getoptex will be called next time.
-# When all options are parsed, contains a number of
-# the first non-option argument.
-#
-#
-# OPTOFS -- If a parameter number $OPTIND containg an option parsed
-# does not contain any more options, OPTOFS is unset;
-# otherwise, OPTOFS is set to such a number of "?" signs
-# which is equal to the number of options parsed
-#
-# You might not set variables OPTIND and OPTOFS yourself
-# unless you want to parse a list of parameters more than once.
-# Otherwise, you whould unset OPTIND (or set it to 1)
-# and unset OPTOFS each time you want to parse a new parameters list
-#
-# Option list format is DIFFERENT from one for getopts or getopt. getopts-style
-# option list can be converted to getoptex-style using a function optlistex
-# (see bellow)
-#
-# DESCRIPTION of option list used with getoptex:
-# Option names are separated by whitespace. Options consiting of
-# more than one character are treated as long-named (--option)
-#
-# Special characters can appear at the and of option names specifying
-# whether an argument is required (default is ";"):
-# ";" (default) -- no argument
-# ":" -- required argument
-# "," -- optional argument
-#
-# For example, an option list "a b c help version f: file: separator."
-# defines the following options:
-# -a, -b, -c, --help, --version -- no argument
-# -f, --file -- argument required
-# --separator -- optional argument
-#
-# FUNCTION optlistex
-# Usage new_style_optlist=`optlistex OLD_STYLE_OPTLIST`
-#
-# Converts getopts-style option list in a format suitable for use with getoptex
-# Namely, it inserts spaces after each option name.
-#
-#
-# HOW TO USE
-#
-# In order o use in your bash scripts the functions described,
-# include a command ". getopt.sh" to the file containing the script,
-# which will define functions getopt, getoptex, and optlistex
-#
-# EXAMPLES
-#
-# See files 'getopt1' and 'getopt2' that contain sample scripts that use
-# getopt and getoptex functions respectively
-#
-#
-# Please send your comments to grg@philol.msu.ru
-
-function getoptex()
-{
- let $# || return 1
- local optlist="${1#;}"
- let OPTIND || OPTIND=1
- [ $OPTIND -lt $# ] || return 1
- shift $OPTIND
- if [ "$1" != "-" -a "$1" != "${1#-}" ]
- then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ]
- then
- local o
- o="-${1#-$OPTOFS}"
- for opt in ${optlist#;}
- do
- OPTOPT="${opt%[;.:]}"
- unset OPTARG
- local opttype="${opt##*[^;:.]}"
- [ -z "$opttype" ] && opttype=";"
- if [ ${#OPTOPT} -gt 1 ]
- then # long-named option
- case $o in
- "--$OPTOPT")
- if [ "$opttype" != ":" ]; then return 0; fi
- OPTARG="$2"
-
-# Added test on following argument being an option identified by '-' this way #
-# the routine no longer takes options as an argument thus breaking error #
-# detection. 2004-04-04 by raphael at oninet dot pt #
-
- if [ -z "$OPTARG" -o "${OPTARG:0:1}" = "-" ] ;
- then # error: must have an agrument
- let OPTERR && echo "$0: error: $OPTOPT must have an argument" >&2
- OPTARG="$OPTOPT";
- OPTOPT="?"
- return 1;
- fi
- OPTIND=$[OPTIND+1] # skip option's argument
- return 0
- ;;
- "--$OPTOPT="*)
- if [ "$opttype" = ";" ];
- then # error: must not have arguments
- let OPTERR && echo "$0: error: $OPTOPT must not have arguments" >&2
- OPTARG="$OPTOPT"
- OPTOPT="?"
- return 1
- fi
- OPTARG=${o#"--$OPTOPT="}
- return 0
- ;;
- esac
- else # short-named option
- case "$o" in
- "-$OPTOPT")
- unset OPTOFS
- [ "$opttype" != ":" ] && return 0
- OPTARG="$2"
-
-# Added test on following argument being an option identified by '-' this way #
-# the routine no longer takes options as an argument thus breaking error #
-# detection. 2004-04-04 by raphael at oninet dot pt #
-
- if [ -z "$OPTARG" -o "${OPTARG:0:1}" = "-" ] ;
- then
- echo "$0: error: -$OPTOPT must have an argument" >&2
- OPTARG="$OPTOPT"
- OPTOPT="?"
- return 1
- fi
- OPTIND=$[OPTIND+1] # skip option's argument
- return 0
- ;;
- "-$OPTOPT"*)
- if [ $opttype = ";" ]
- then # an option with no argument is in a chain of options
- OPTOFS="$OPTOFS?" # move to the next option in the chain
- OPTIND=$[OPTIND-1] # the chain still has other options
- return 0
- else
- unset OPTOFS
- OPTARG="${o#-$OPTOPT}"
- return 0
- fi
- ;;
- esac
- fi
- done
- echo "$0: error: invalid option: $o"
- fi; fi
- OPTOPT="?"
- unset OPTARG
- return 1
-}
-function optlistex
-{
- local l="$1"
- local m # mask
- local r # to store result
- while [ ${#m} -lt $[${#l}-1] ]; do m="$m?"; done # create a "???..." mask
- while [ -n "$l" ]
- do
- r="${r:+"$r "}${l%$m}" # append the first character of $l to $r
- l="${l#?}" # cut the first charecter from $l
- m="${m#?}" # cut one "?" sign from m
- if [ -n "${l%%[^:.;]*}" ]
- then # a special character (";", ".", or ":") was found
- r="$r${l%$m}" # append it to $r
- l="${l#?}" # cut the special character from l
- m="${m#?}" # cut one more "?" sign
- fi
- done
- echo $r
-}
-function getopt()
-{
- local optlist=`optlistex "$1"`
- shift
- getoptex "$optlist" "$@"
- return $?
-}
+++ /dev/null
-#!/bin/sh -efu
-
-if [ -z "${__included_shell_array-}" ]; then
-__included_shell_array=1
-
-if [ -n "${__libshell_experimental-}" ]; then
-
-#. shell-crc32
-
-# arr[ZZZ-zzz] = "XXX-xxx"
-#
-# ARRAY_arr_{n}_key="ZZZ-zzz"
-# ARRAY_arr_{n}_arg="XXX-xxx"
-# ARRAY_arr_{sign}={n}
-# ARRAY_arr={size}
-
-# Usage: array ARRNAME key value
-# or: array ARRNAME key
-# or: array ARRNAME
-array()
-{
- local arr key arg num i
- arr="$1"
- [ "$#" -lt 2 ] || key="$2"
- [ "$#" -lt 3 ] || arg="$3"
-
- eval "num=\${ARRAY_$arr:-0}"
- if [ "$#" -eq 1 ]; then
- printf '%d\n' "$num"
- return
- fi
-
- #shell_crc32 "sign" "$key"
- sign="$(printf '%s' "$key" |sha1sum)"
- sign="${sign%% *}"
- eval "i=\"\${ARRAY_${arr}_${sign}-}\""
-
- if [ "$#" -eq 2 ]; then
- if [ -n "$i" ]; then
- eval "arg=\$ARRAY_${arr}_${i}_arg"
- printf '%s\n' "$arg"
- return
- fi
- return 1
- fi
-
- if [ -z "$i" ]; then
- i="$num"
- num=$(($num+1))
- eval "ARRAY_$arr=\$num"
- fi
-
- eval "ARRAY_${arr}_${i}_key=\"\$key\""
- eval "ARRAY_${arr}_${i}_arg=\"\$arg\""
- eval "ARRAY_${arr}_${sign}=\"\$i\""
-}
-
-# Usage: shell_array_foreach ARRNAME callback
-array_foreach()
-{
- local arrname callback i num key arg
- arrname="$1"; shift
- callback="$1"; shift
-
- eval "num=\${ARRAY_$arrname:-0}"
- [ "$num" -gt 0 ] ||
- return 0
- i=0
- while [ $i -lt $num ]; do
- eval "key=\"\$ARRAY_${arrname}_${i}_key\""
- eval "arg=\"\$ARRAY_${arrname}_${i}_arg\""
- $callback "$i" "$key" "$arg"
- i=$(($i+1))
- done
-}
-
-array_flip()
-{
- local arrname tmp key1 key2 num1 num2
- arrname="$1"; shift
- key1="$1"; shift
- key2="$1"; shift
-
- eval
-}
-
-fi #__libshell_experimental
-
-fi #__included_shell_array
+++ /dev/null
-#!/bin/ash -efu
-
-# http://ru.wikipedia.org/wiki/CRC32#CRC-32
-#
-# Name : CRC-32
-# Poly : 0x04C11DB7 x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11
-# + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
-# Init : 0xFFFFFFFF
-# Revert: true
-# XorOut: 0xFFFFFFFF
-# Check : 0xCBF43926 ("123456789")
-#
-
-__shell_crc32_table=
-__shell_crc32_init()
-{
- [ -z "${__shell_crc32_table-}" ] ||
- return 0;
-
- local i=0 j crc
-
- while [ $i -lt 256 ]; do
- crc=$i
- j=0
- while [ $j -lt 8 ]; do
- [ $(($crc & 1)) -ne 0 ] &&
- crc=$((($crc >> 1) ^ 0xEDB88320)) ||
- crc=$((($crc >> 1)))
- j=$(($j+1))
- done
- __shell_crc32_table="$__shell_crc32_table $crc"
- i=$(($i+1))
- done
-}
-
-shell_crc32()
-{
- local __shell_crc32_crc __shell_crc32_name __shell_crc32_buf
- __shell_crc32_name="$1"; shift
- __shell_crc32_buf="$2"; shift
-
- __shell_crc32()
- {
- local c crc i=1 j
-
- __shell_crc32_init
- set -- ${__shell_crc32_table}
-
- local args= mask=
- while [ $i -lt ${#buf} ]; do
- mask="$mask?"
- i=$(($i+1))
- done
-
- while [ -n "$buf" ]; do
- args="$args '${buf%$mask}"
- buf=${buf#?}
- mask=${mask#?}
- done
-
- crc=$((0xFFFFFFFF))
- for c in $(printf '%d ' $args); do
- j=$((($crc ^ $c) & 0xFF))
- j=$(($j+1))
- eval "crc=\$((\${$j} ^ (\$crc >> 0x00000008)))"
- done
- __shell_crc32_crc=$(($crc ^ 0xFFFFFFFF))
- }
- __shell_crc32
- eval "$__shell_crc32_name=\"\${__shell_crc32_crc}\""
-}
-
-#shell_crc32 "" "123456789"
+++ /dev/null
-#!/bin/sh -efu
-
-if [ -z "${__included_shell_lists-}" ]; then
-__included_shell_lists=1
-
-. shell-quote
-
-shell_list_add() {
- local __shell_list_add_var="$1"
- shift
- local __shell_list_add_qvalue
- while [ "$#" -gt 0 ]; do
- quote_shell_variable __shell_list_add_qvalue "$1"
- eval "$__shell_list_add_var=\"\$$__shell_list_add_var \\\"\$__shell_list_add_qvalue\\\"\""
- shift
- done
-}
-
-shell_list_remove() {
- local __shell_list_remove_var __shell_list_remove_value
- __shell_list_remove_var="$1"; shift
- __shell_list_remove_value="$1"; shift
-
- local __shell_list_remove_qvalue __shell_list_remove_nvar=
-
- eval "__shell_list_remove_nvar=\$$var"
- eval "set -- $__shell_list_remove_nvar"
- eval "__shell_list_remove_nvar=''"
-
- while [ "$#" -gt 0 ]; do
- if [ "$__shell_list_remove_value" != "$1" ]; then
- quote_shell_variable __shell_list_remove_qvalue "$1"
- eval "__shell_list_remove_nvar=\"\$__shell_list_remove_nvar \\\"\$__shell_list_remove_qvalue\\\"\""
- fi
- shift
- done
-
- eval "$__shell_list_remove_var=\"\$__shell_list_remove_nvar\""
-}
-
-shell_list_get() {
- local __shell_list_get_var __shell_list_get_name __shell_list_get_value
- __shell_list_get_var="$1"; shift
- __shell_list_get_name="$1"; shift
- __shell_list_get_value="$1"; shift
-
- local __shell_list_get_lst=
- eval "__shell_list_get_lst=\"\$$__shell_list_get_var\""
- eval "set -- $__shell_list_get_lst"
- [ "$__shell_list_get_value" -le "$#" ] ||
- return 1
- eval "$__shell_list_get_name=\"\${$__shell_list_get_value-}\""
-}
-
-SHELLLIST_FOREACH=1
-shell_list_foreach() {
- local __shell_list_foreach_var __shell_list_foreach_name
- __shell_list_foreach_var="$1"; shift
- __shell_list_foreach_name="$1"; shift
-
- local __shell_list_foreach_lst=
- eval "__shell_list_foreach_lst=\"\$$__shell_list_foreach_var\""
- eval "set -- $__shell_list_foreach_lst"
- if [ "$SHELLLIST_FOREACH" -gt "$#" ]; then
- SHELLLIST_FOREACH=1
- return 1
- fi
- eval "$__shell_list_foreach_name=\"\$$SHELLLIST_FOREACH\""
- SHELLLIST_FOREACH=$(( $SHELLLIST_FOREACH + 1 ))
-}
-
-fi # __included_shell_lists
+++ /dev/null
-#!/bin/ash -efu
-
-if [ -z "${__included_shell_sort-}" ]; then
-__included_shell_sort=1
-
-if [ -n "${__libshell_experimental-}" ]; then
-
-. ./shell-array
-
-INSERTIONSORT='__shell_compare_sort'
-QUICKSORT='__shell_compare_sort'
-HEAPSORT='__shell_compare_sort'
-__shell_compare_sort() {
- test "$1" "$3" "$2" || return 1
-}
-
-__insertion_sort() {
- local arr="$1" first="$2" last="$3"
- local i j=0 key_i key_j
-
- j=$(($first+1))
- while [ $j -lt $last ]; do
- array_get "$arr[$j]" key_j
- i=$(($j-1))
-
- while [ $i -ge $first ]; do
- array_get "$arr[$i]" key_i
- if array_compare "$INSERTIONSORT" "$arr[$i]" "$arr[$j]" "$order"; then
- array_set "$arr[$(($i+1))]" "$key_i"
- i=$(($i-1))
- else
- break
- fi
- done
- array_set "$arr[$(($i+1))]" "$key_j"
- j=$(($j+1))
- done
-}
-
-# Usage: insertion_sort ARR
-insertion_sort() {
- local order=-ge arr r
- arr="$1"; shift
- array_size "$arr" r
- __insertion_sort "$arr" 0 "$r"
-}
-
-__shell_partition() {
- local var="$1" arr="$2" p="$3" r="$4"
- local i=$p j=$p
-
- while [ "$j" -lt "$r" ]; do
- if array_compare "$QUICKSORT" "$arr[$r]" "$arr[$j]" "$order"; then
- array_swap "$arr[$i]" "$arr[$j]"
- i=$(($i+1))
- fi
- j=$(($j+1))
- done
- array_swap "$arr[$i]" "$arr[$r]"
- eval "$var=\"$i\""
-}
-
-__quicksort() {
- local q arr="$1" p="$2" r="$3"
- while [ "$p" -lt "$r" ]; do
- __shell_partition q "$arr" "$p" "$r"
- __quicksort "$arr" "$p" "$(($q-1))"
- p=$(($q+1))
- done
-}
-
-# Usage: quicksort ARR [order]
-quicksort() {
- local order=-le arr r
- arr="$1"; shift
- [ "$#" -eq 0 ] || order=-ge
-
- array_size "$arr" r
- __quicksort "$arr" 0 "$(($r-1))"
-}
-
-heapsort() {
- local arr siz c p i=1 order=-gt
- arr="$1"; shift
- [ "$#" -eq 0 ] || order=-lt
-
- array_size "$arr" siz
- while [ $i -lt $siz ]; do
- c=$i
- while [ $c -gt 0 ]; do
- p=$(($c-1))
- if array_compare "$HEAPSORT" "$arr[$p]" "$arr[$c]" "$order"; then
- array_swap "$arr[$p]" "$arr[$c]"
- c=$p
- else
- break
- fi
- done
- i=$(($i+1))
- done
-}
-
-fi #__libshell_experimental
-
-fi #__included_shell_sort
+++ /dev/null
-#!/bin/sh -efu
-
-stack_push() {
- local name str last stack
- name="$1"; shift
- str="$1"; shift
-
- eval "stack=\"\${__${name}:-}\";"
- set $stack
- last=$(($# + 1))
-
- eval "__${name}=\"\${__$name:+\$__$name }${last}\";
- __${name}_${last}=\"\$str\";"
-}
-
-stack_pop() {
- local name var last stack
- name="$1"; shift
- var="$1"; shift
-
- eval "stack=\"\${__${name}:-}\";"
- set $stack
- last="$#"
-
- if [ "$last" = 0 ]; then
- eval "$var=''"
- return
- fi
-
- eval "$var=\"\${__${name}_${last}:-}\";
- unset __${name}_${last};
- __${name}=\"\${__${name}% *}\";"
-}
-
-stack_shift() {
- local name var last stack
- name="$1"; shift
- var="$1"; shift
-
- eval "stack=\"\${__${name}:-}\";"
- set $stack
- last="$#"
-
- if [ "$last" = 0 ]; then
- eval "$var=''"
- return
- fi
-
- last="${stack%% *}"
- last="${last## }"
-
- eval "$var=\"\${__${name}_${last}:-}\";
- unset __${name}_${last};
- __${name}=\"\${__${name}#* }\";"
-}
-
-stack_unshift() {
- local name str last stack
- name="$1"; shift
- str="$1"; shift
-
- eval "stack=\"\${__${name}:-}\";"
- set $stack
- last="$(($# + 1))"
-
- eval "__${name}=\"${last}\${__$name:+ \$__$name}\";
- __${name}_${last}=\"\$str\";"
-}
+++ /dev/null
-.\" Copyright (C) 2008 Alexey Gladkov <legion@altlinux.org>
-.\"
-.\" Additional documentation for the libshell.
-.\"
-.\" This file is free software; you can redistribute it and/or modify
-.\" it under the terms of the GNU General Public License as published by
-.\" the Free Software Foundation; either version 2 of the License, or
-.\" (at your option) any later version.
-.\"
-.\" This program is distributed in the hope that it will be useful,
-.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
-.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-.\" GNU General Public License for more details.
-.\"
-.\" You should have received a copy of the GNU General Public License
-.\" along with this program; if not, write to the Free Software
-.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-.
-.TH "LIBSHELL" "3" "November 2008" "libshell" "File Formats"
-.SH NAME
-libshell \- the library of shell functions
-.
-.
-.SH DESCRIPTION
-.
-The
-.B libshell
-library is a set of the most commonly-used shell functions.
-All functions use minimum of external utilities and written for POSIX-shell.
-.
-.
-.SH STRUCTURE
-.
-Library has modular structure. Each module used for own special purpose.
-Some modules use the functionality of each other and load the necessary dependence.
-.TP
-.BR shell-getopt
-Shell implementation of getopt(1) utility and getopt family;
-.TP
-.BR shell-config
-Functions to work (read, change and remove variables) with a shell-like config files;
-.TP
-.BR shell-ini-config
-Functions to work with a ini-like config files;
-.TP
-.BR shell-signal
-Functions to change the action taken by a process on receipt of a specific signal;
-.TP
-.BR shell-args
-Functions to check argument type, display version and program usage;
-.TP
-.BR shell-ip-address
-Functions to validate the IP address;
-.TP
-.BR shell-mail-address
-Functions to validate the domain and email address;
-.TP
-.BR shell-quote
-Functions to quote variables;
-.TP
-.BR shell-unittest
-Unit testing framework for shell (xUnit compatible);
-.TP
-.BR shell-error
-Functions to display error and verbose messages;
-.TP
-.BR shell-version
-Module contain libshell ABI version.
-.BR
-.
-.
-.
-.SH USING MODULES
-All
-.B libshell
-modules
-.I MUST
-be kept in the PATH and could be not executable. It really helps to include
-these modules in the shell-program:
-.RS
-.IP
-.EX
-\&#!/bin/sh
-\&. shell-error
-\&. shell-getopt
-\&
-\&# something useful ...
-.EE
-.RE
-.PP
-The
-.B bash-completion
-will not find these modules in the PATH, if they are not executable.
-.
-.
-.SH AUTHOR
-.PP
-This manual page written by
-.MT legion@altlinux.org
-Alexey Gladkov
-.ME .
-.PP
-Authors and contributors of the programs included in the
-.B libshell
-package are listed in the COPYING file.
-.
-.
-.SH SEE ALSO
-.PP
-.na
-.nh
-.tr -\(hy
-.BR sh (1),
-.BR bash (1),
-.BR dash (1).
+++ /dev/null
-.\" Copyright (C) 2008 Alexey Gladkov <legion@altlinux.org>
-.\"
-.\" Additional documentation for the libshell.
-.\"
-.\" This file is free software; you can redistribute it and/or modify
-.\" it under the terms of the GNU General Public License as published by
-.\" the Free Software Foundation; either version 2 of the License, or
-.\" (at your option) any later version.
-.\"
-.\" This program is distributed in the hope that it will be useful,
-.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
-.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-.\" GNU General Public License for more details.
-.\"
-.\" You should have received a copy of the GNU General Public License
-.\" along with this program; if not, write to the Free Software
-.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-.
-.TH "SHELL-ERROR" "3" "November 2008" "libshell" "File Formats"
-.SH NAME
-message, fatal, verbose \- functions to display error and verbose messages
-.
-.
-.SH SYNOPSIS
-.nf
-.B . shell-error
-.sp
-.BI "PROG=" "${0##*/}"
-.sp
-.BI "message " TEXT
-.sp
-.BI "fatal " TEXT
-.sp
-.BI "verbose= quiet="
-.sp
-.BI "verbose " TEXT
-.ad b
-.SH DESCRIPTION
-The
-.BR message ()
-function show
-.B TEXT
-message to the stderr.
-.PP
-Function
-.BR fatal ()
-is equivalent to the function message(), except that
-the script will be completed after displaying a message.
-.PP
-.BR verbose ()
-will show message if
-.B $verbose
-is set and
-.B $quiet
-unset.
-.SH AUTHOR
-.PP
-This manual page written by
-.MT legion@altlinux.org
-Alexey Gladkov
-.ME .
-.PP
-Authors and contributors of the programs included in the
-.B libshell
-package are listed in the COPYING file.
-.
-.
-.SH SEE ALSO
-.PP
-.na
-.nh
-.tr -\(hy
-.BR libshell (3).
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_args-}" ]; then
-__included_shell_args=1
-
-. shell-error
-
-# Checks that given option value is a readable file.
-# Arguments: $1 is option name, $2 is option value.
-# If $2 is a readable file, outputs canonicalized file name,
-# otherwise fails.
-opt_check_read() {
- local value
- [ -r "$2" ] &&
- value="$(readlink -ev "$2")" ||
- fatal "$1: $2: file not available."
- printf %s "$value"
-}
-
-# Checks that given option value is a traversable directory.
-# Arguments: $1 is option name, $2 is option value.
-# If $2 is a readable file, outputs canonicalized directory name,
-# otherwise fails.
-opt_check_dir() {
- local value
- [ -d "$2" -a -x "$2" ] &&
- value="$(readlink -ev "$2")" ||
- fatal "$1: $2: directory not available."
- printf %s "$value"
-}
-
-# Checks that given option value is a positive decimal number.
-# Arguments: $1 is option name, $2 is option value.
-# If $2 is a positive decimal number, outputs it, otherwise fails.
-opt_check_number()
-{
- [ -n "${2##0*}" -a -n "${2##*[!0-9]*}" ] &&
- [ "$2" -gt 0 ] 2>/dev/null ||
- fatal "$1: $2: invalid number."
- printf %s "$2"
-}
-
-show_usage() {
- [ -z "$*" ] || message "$*"
- echo "Try \`$PROG --help' for more information." >&2
- exit 1
-}
-
-show_help() {
- fatal "show_help(): Undefined function"
-}
-
-print_version() {
- fatal "print_version() Undefined function"
-}
-
-readonly getopt_common_opts="q,v,V,h"
-readonly getopt_common_longopts="quiet,verbose,version,help"
-parse_common_option() {
- case "$1" in
- -h|--help) show_help
- ;;
- -q|--quiet) quiet=-q; verbose=
- ;;
- -v|--verbose) verbose=-v; quiet=
- ;;
- -V|--version) print_version "$PROG"
- ;;
- *) fatal "Unrecognized option: $1"
- ;;
- esac
-}
-
-fi #__included_shell_args
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_cmdline-}" ]; then
-__included_shell_cmdline=1
-
-. shell-string
-
-# Run handler for each variable in /proc/cmdline.
-#
-cmdline_foreach() {
- local l h c= m=
-
- l="$1"; shift
- h="$1"; shift
-
- __is_set() {
- [ $(( $1 & $2 )) -eq $2 ]
- }
-
- fill_mask m "$l"
-
- local state=$((0x00))
- local VALUE=$((0x02))
- local EQUAL=$((0x04))
- local QUOTE=$((0x10))
-
- local n= v=
-
- while [ -n "$l" ]; do
- c="${l%$m}"
-
- case "$c" in
- '"')
- __is_set $state $QUOTE &&
- state=$(($state ^ $QUOTE)) ||
- state=$(($state | $QUOTE))
- ;;
- ' ')
- if __is_set $state $QUOTE; then
- v="$v$c"
- else
- __is_set $state $EQUAL ||
- v=1
- $h "$n" "$v" ||
- break
- n= v=
- state=$((0x00))
- fi
- ;;
- '=')
- ! __is_set $state $VALUE ||
- v="$v$c"
- state=$(($state | $VALUE | $EQUAL))
- ;;
- *)
- if ! __is_set $state $VALUE; then
- [ "$c" != '-' ] || c='_'
- n="$n$c"
- else
- v="$v$c"
- fi
- ;;
- esac
-
- l="${l#?}"
- m="${m#?}"
- done
-
- [ -z "$n" ] ||
- $h "$n" "$v" ||:
-
- unset __is_set
-}
-
-# Find spicified variable in /proc/cmdline and store result into variable.
-# Usage example:
-# read cmdline < /proc/cmdline
-# cmdline_get 'initrd_value' 'initrd' "$cmdline"
-# echo "$initrd_value"
-# or:
-# cmdline_get 'initrd_value' 'initrd'
-# echo "$initrd_value"
-#
-cmdline_get() {
- local __cmdline __retv __getn
-
- __retv="$1"; shift
- __getn="$1"; shift
- if [ "$#" -eq 0 ]; then
- read __cmdline < /proc/cmdline
- else
- __cmdline="$1"
- fi
-
- local c m l="$__getn"
- __getn=
-
- fill_mask m "$l"
- while [ -n "$l" ]; do
- c="${l%$m}"
- [ "$c" != '-' ] || c='_'
- __getn="$__getn$c"
- l="${l#?}"
- m="${m#?}"
- done
- unset c m l
-
- __getval() {
- [ "$1" != "$__getn" ] || eval "$__retv=\"\$2\""
- }
- cmdline_foreach "$__cmdline" __getval
- unset __getval
-}
-
-fi #__included_shell_cmdline
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_config-}" ]; then
-__included_shell_config=1
-
-. shell-error
-. shell-quote
-
-__shell_config_comment='#'
-
-shell_config_get() {
- [ "$#" -ge 2 -a "$#" -le 3 ] ||
- fatal "Usage: shell_config_get file name [delim]"
- local file="$1" name="$2" delim="${3-=}"
-
- [ -s "$file" ] ||
- return 0
- quote_sed_regexp_variable name "$name"
- sed -n -e "s/^[[:space:]]*$name$delim//p" -- "$file"
-}
-
-shell_config_set() {
- [ "$#" -ge 3 -a "$#" -le 5 ] ||
- fatal "Usage: shell_config_set file name value [read-delim [write-delim]]"
-
- local file="$1" name="$2" value="$3" r_delim="${4-=}" w_delim="${5-=}"
- local n v nv= created=
-
- if [ ! -f "$file" ]; then
- if [ ! -w "${file%/*}" ]; then
- message "${file%/*}: not writable."
- return 1
- fi
- touch -- "$file" ||
- return 1
- created=1
- fi
-
- if [ -z "$created" ]; then
- quote_sed_regexp_variable n "$name"
-
- if v="$(grep -m1 "^[[:space:]]*$n$r_delim" -- "$file" 2>/dev/null)"; then
- if [ "${v#*$name$r_delim}" != "$value" ]; then
- quote_sed_regexp_variable nv "$w_delim$value"
- sed -i -e "s/^[[:space:]]*$n$r_delim.*/$n$nv/" -- "$file"
- fi
- return
- fi
-
- if [ -n "${__shell_config_comment-}" ] &&
- v="$(grep -m1 "^[[:space:]]*${__shell_config_comment:-#}[[:space:]]*$n$r_delim" -- "$file" 2>/dev/null)"; then
- quote_sed_regexp_variable v "$v"
- quote_sed_regexp_variable nv "$w_delim$value"
- sed -i -e "s/^$v\$/$n$nv/" -- "$file"
- return
- fi
- fi
-
- printf '%s\n' "$name$w_delim$value" >> "$file"
-}
-
-shell_config_del() {
- [ "$#" -ge 2 -a "$#" -le 3 ] ||
- fatal "Usage: shell_config_del file name [delim]"
- local file="$1" name="$2" delim="${3-=}"
-
- [ -s "$file" ] ||
- return 0
- quote_sed_regexp_variable name "$name"
- sed -i -e "/^[[:space:]]*$name$delim/d" -- "$file"
-}
-
-shell_config_comment() {
- [ "$#" -ge 2 -a "$#" -le 3 ] ||
- fatal "Usage: shell_config_comment file name [delim]"
- local file="$1" name="$2" delim="${3-=}"
-
- [ -s "$file" ] ||
- return 0
- quote_sed_regexp_variable name "$name"
- sed -i -e "s/^[[:space:]]*$name$delim.*/${__shell_config_comment:-#}&/" -- "$file"
-}
-
-fi #__included_shell_config
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_error-}" ]; then
-__included_shell_error=1
-
-PROG="${PROG:-${0##*/}}"
-
-message_time=
-message_time_format=
-message() {
- local prefix=
- [ -z "$message_time" ] ||
- prefix="$(date +"${message_time_format:-[%Y-%m-%d %T]} " 2>/dev/null)" ||:
- printf %s\\n "${prefix}$PROG: $*" >&2
-}
-
-fatal() {
- message "$@"
- exit 1
-}
-
-quiet="${quiet-}"
-verbose="${verbose-}"
-verbose() {
- [ -n "$verbose" ] || return 0
- message "$@"
-}
-
-fi #__included_shell_error
+++ /dev/null
-#! /bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_getopt-}" ]; then
-__included_shell_getopt=1
-
-. shell-error
-. shell-quote
-. shell-string
-
-# Ignore unknown options.
-GETOPT_ALLOW_UNKNOWN=
-
-# Long options may be abbreviated, as long as the abbreviation is not ambiguous.
-GETOPT_ALLOW_ABBREV=1
-
-# Allow long options to start with a single ‘-’. See (getopt -a).
-GETOPT_ALLOW_ALTERNATIVE=
-
-OPTERR=1
-OPTTYP=
-OPTUKN=
-OPTOPT=
-OPTARG=
-OPTIND=1
-OPTOFS=
-
-#*** Example ***
-### Usage: getopt2 -ab -d 10 -e20 --opt1 --opt4=100 text1 text2
-###
-# . shell-getopt
-# echo Using getoptex to parse arguments:
-# while getoptex "a; b; c; d: e. opt1 opt2 opt3 opt4: opt5." "$@"; do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-# done
-# shift $(($OPTIND-1))
-# set -- $@ ${OPTUKN-}
-# for arg in "$@"; do
-# echo "Non option argument <$arg>"
-# done
-
-getoptex() {
- [ "$#" -gt 0 ] ||
- return 1
-
- [ "${OPTIND-}" -gt 0 ] 2>/dev/null ||
- OPTIND=1
-
- [ "$OPTIND" -lt "$#" ] ||
- return 1
-
- getoptex_badarg() {
- [ -z "${OPTERR-}" ] ||
- message "option requires an argument -- '$OPTOPT'"
- OPTARG="$OPTOPT"
- OPTOPT='?'
- }
- getoptex_argument() {
- [ "$OPTTYP" = ':' ] ||
- return 0
- OPTARG="$1"
- # Added test on following argument being an option identified by '-' this way #
- # the routine no longer takes options as an argument thus breaking error #
- # detection. 2004-04-04 by raphael at oninet dot pt #
-
- [ -n "$OPTARG" -a -n "${OPTARG%%-*}" ] ||
- { getoptex_badarg; return 1; }
-
- OPTARG="${1#[#]}"
- OPTIND=$(($OPTIND+1)) # skip option's argument
- }
- getoptex_option_long() {
- local arg="$1" v p
- for p in '--' ${GETOPT_ALLOW_ALTERNATIVE:+'-'}; do
- if [ -n "${GETOPT_ALLOW_ABBREV-}" ]; then
- arg="${1%%=*}" v="${1#*=}" o="$p$OPTOPT"
- if [ -z "${o##$arg*}" ]; then
- [ "$arg" != "$v" ] &&
- arg="$o=$v" ||
- arg="$o"
- unset o v
- fi
- fi
- case "$arg" in
- $p$OPTOPT=*)
- [ -n "$OPTTYP" ] ||
- { getoptex_badarg; return 3; }
- OPTARG="${arg#$p$OPTOPT=}"
- return 1
- ;;
- $p$OPTOPT)
- getoptex_argument "$2" ||
- return 3
- return 1
- ;;
- esac
- done
- }
- getoptex_option_short() {
- local o="-${1#-${OPTOFS-}}"
- case "$o" in
- -$OPTOPT)
- OPTOFS=
- getoptex_argument "$2" ||
- return 3
- return 1
- ;;
- -$OPTOPT*)
- if [ -z "$OPTTYP" ]; then # an option with no argument is in a chain of options
- OPTOFS="${OPTOFS-}?" # move to the next option in the chain
- OPTIND=$(($OPTIND-1)) # the chain still has other options
- else
- OPTOFS=
- OPTARG="${o#-$OPTOPT}"
- fi
- return 1
- ;;
- esac
- }
-
- local optlist="${1#;}" value=
- shift $OPTIND
-
- [ "$#" -lt 2 ] ||
- value="#$2"
-
- OPTTYP=
- # test whether $1 is an option.
- if [ "$1" = '--' ]; then
- OPTTYP='--'
- OPTIND=$(($OPTIND+1))
- elif [ "$1" != '-' -a "$1" != "${1#-}" ]; then
- OPTIND=$(($OPTIND+1))
-
- local cmd argtype
- for opt in $optlist; do
- OPTOPT="${opt%[;.:]}"
- OPTARG=
- OPTTYP=
- [ "$OPTTYP" = ';' ] ||
- OPTTYP="${opt#$OPTOPT}"
-
- cmd=long
- [ "${#OPTOPT}" -gt 1 ] ||
- cmd=short
-
- getoptex_option_$cmd "$1" "$value" ||
- return $(($?-1))
- done
- OPTOPT='?'
- OPTARG=
-
- if [ -n "${GETOPT_ALLOW_UNKNOWN-}" ]; then
- local q_arg
- quote_shell_variable q_arg "$1"
- OPTUKN="${OPTUKN-} \"$q_arg\""
- return 0
- fi
- message "unrecognized option '$1'"
- return 2
- fi
- OPTOPT='?'
- OPTARG=
- return 1
-}
-
-#*** Example ***
-### Usage: getopt1 -ab -d 10 -e20 text1 text2
-###
-# . shell-getopt
-# echo "Using getopt to parse arguments:"
-# while getopts "abcd:e." "$@"; do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-# done
-# shift $(($OPTIND-1))
-# set -- $@ ${OPTUKN-}
-# for arg in "$@"; do
-# echo "Non option argument <$arg>"
-# done
-
-getopts() {
- local l="$1"
- local m= # mask
- local r= # to store result
- fill_mask m "$l" # create a "???..." mask
-
- while [ -n "$l" ]; do
- r="${r:+"$r "}${l%$m}" # append the first character of $l to $r
- l="${l#?}" # cut the first charecter from $l
- m="${m#?}" # cut one "?" sign from m
- if [ "${l#[:.;]}" != "$l" ]; then # a special character (";", ".", or ":") was found
- r="$r${l%$m}" # append it to $r
- l="${l#?}" # cut the special character from l
- m="${m#?}" # cut one more "?" sign
- fi
- done
- shift
- getoptex "$r" "$@" ||
- return $?
-}
-
-
-#*** Example ***
-# . shell-getopt
-# while getsubopt 'rw mode: path: dev:' 'rw,mode=755,path="/zzz xxx",dev=/dev/zzz'; do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-# done
-
-__getsubopt_arguments=
-getsubopt() {
- local l="$2"
-
- if [ -z "$__getsubopt_arguments" ]; then
- local ch m=
- fill_mask m "$l"
-
- __getsubopt_arguments='--'
- while [ -n "$l" ]; do
- ch="${l%$m}"
- l="${l#?}"
- m="${m#?}"
-
- case "$ch" in
- ,) ch=' --' ;;
- [\\\\\`\$\"\ ]) ch="\\$ch" ;;
- esac
-
- __getsubopt_arguments="$__getsubopt_arguments$ch"
- done
- fi
-
- local GETOPT_ALLOW_ABBREV=
- eval getoptex "\"$1\"" "$__getsubopt_arguments" ||
- return $?
-}
-
-. shell-version
-
-GETOPT_POSIXLY_CORRECT=
-
-getopt() {
- __getopt_version() {
- cat <<-EOF
- $PROG version $libshell_version
- Written by Alexey Gladkov <gladkov.alexey@gmail.com>
-
- Copyright (C) 2008 Alexey Gladkov <gladkov.alexey@gmail.com>
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- EOF
- }
- __getopt_usage() {
- cat <<-EOF
- Try \`$PROG --help' for more information.
- EOF
- }
- __getopt_help() {
- cat <<-EOF
- Usage: $PROG optstring parameters
- or: $PROG [options] [--] optstring parameters
- or: $PROG [options] -o|--options optstring [options] [--] parameters
-
- Options ignored:
- -s, --shell=shell Set shell quoting conventions;
- -u, --unqote Do not quote the output;
-
- Options:
- -a, --alternative Allow long options starting with single -;
- -l, --longoptions=longopts Long options to be recognized;
- -n, --name=progname The name under which errors are reported;
- -o, --options=optstring Short options to be recognized;
- -q, --quiet Disable error reporting;
- -Q, --quiet-output No normal output;
- -T, --test Test for getopt version;
- -V, --version Output version information;
- -h, --help This small usage guide.
-
- Report bugs to http://bugzilla.altlinux.org/
-
- EOF
- }
-
- local PROG='getopt' OPTIND=1 OPTERR=1 prg= opts= lopts= quiet_output= alt= order= rc
- local GETOPT_POSIXLY_CORRECT
-
- while getoptex 'a alternative h help l: longoptions: n: name: o: options: q quiet Q quiet-output s shell T test u unquoted V version' "$@" && rc=0 || rc=$?; do
- case "$rc" in
- 2) __getopt_usage; return 2 ;;
- 1) break ;;
- esac
-
- case "$OPTOPT" in
- a|alternative) alt=1 ;;
- n|name) prg="$OPTARG" ;;
- o|options) opts="$OPTARG " ;;
- l|longoptions) lopts="$OPTARG" ;;
- q|quiet) OPTERR= ;;
- Q|quiet-output) quiet_output=1 ;;
- T|test) return 4 ;;
- V|version)
- __getopt_version
- return 0
- ;;
- h|help)
- __getopt_help
- return 2
- ;;
- esac
- done
-
- shift $(($OPTIND-1))
- set -- "$@"
-
- if [ -z "${opts##+*}" ]; then
- opts="${opts#+}"
- GETOPT_POSIXLY_CORRECT=1
- elif [ -z "${opts##-*}" ]; then
- opts="${opts#-}"
- order=1
- fi
- if [ -z "$opts" ]; then
- if [ "$#" -gt 1 -a "${1#-}" = "$1" -a "$1" != '--' ]; then
- opts="$1"
- shift
- else
- message "$PROG: missing optstring argument"
- __getopt_usage
- return 2
- fi
- fi
- opts="${lopts:+$lopts,}$opts"
- while :; do
- case "$opts" in
- *,*) opts="${opts%%,*} ${opts#*,}" ;;
- *::*) opts="${opts%%::*}.${opts#*::}" ;;
- *) break ;;
- esac
- done
-
- local OPTIND=1 OPTOFS= GETOPT_ALLOW_ALTERNATIVE="${alt:+1}"
- local ret=0 out=' -- '
-
- ! printenv POSIXLY_CORRECT >/dev/null 2>&1 ||
- GETOPT_POSIXLY_CORRECT=1
-
- __getopt_out_arg() {
- local q_arg
- shift $(($OPTIND-1))
- quote_shell_variable q_arg "$1"
- [ -z "$order" ] &&
- out="${out%% -- *} -- ${out#* -- } \"$q_arg\"" ||
- out="${out%% -- *} \"$q_arg\" -- ${out#* -- }"
- }
-
- PROG="$prg"
- while getoptex "$opts" "$@" && rc=0 || rc=$?; do
- case "$rc" in
- 1)
- [ $# -ge $OPTIND -a -z "${GETOPT_POSIXLY_CORRECT-}" ] ||
- break
- __getopt_out_arg "$@"
- OPTIND=$(($OPTIND+1))
- [ "$OPTTYP" != '--' ] ||
- break
- continue
- ;;
- 2) ret=1
- ;;
- esac
- if [ "$OPTOPT" = '?' ]; then
- if [ -n "$GETOPT_ALLOW_UNKNOWN" ]; then
- out="${out%% -- *} -- ${out#* -- }$OPTUKN"
- OPTUKN=
- fi
- continue
- fi
- pfx='-'
- [ "${#OPTOPT}" -eq 1 ] ||
- pfx='--'
- out="${out%% -- *} $pfx$OPTOPT${OPTTYP:+ '$OPTARG'} -- ${out#* -- }"
- done
-
- local q_arg
- shift $(($OPTIND-1))
- set -- "$@"
- while [ "$#" -gt 0 ]; do
- quote_shell_variable q_arg "$1"
- out="${out%% -- *} -- ${out#* -- } \"$q_arg\""
- shift
- done
-
- [ -n "$quiet_output" ] ||
- printf '%s\n' "$out${OPTUKN:+$OPTUKN}"
- return $ret
-}
-
-fi #__included_shell_getopt
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_ini_config-}" ]; then
-__included_shell_ini_config=1
-
-shell_ini_config_comment='#'
-
-. shell-error
-. shell-var
-
-# Usage: ini_config_get file section var
-ini_config_get() {
- local fn section var sect= str eof= n v
- fn="$1" section="$2" var="$3"
-
- while [ -z "$eof" ]; do
- read -r str || eof=1
-
- case "$str" in
- "["*"]")
- [ "$str" != "[$section]" ] ||
- sect=1
- ;;
- "$shell_ini_config_comment"*|'')
- ;;
- *)
- if [ -n "$sect" ]; then
- shell_var_trim n "${str%%=*}"
-
- if [ "$n" = "$var" ]; then
- shell_var_trim v "${str#*=}"
- printf '%s\n' "$v"
- break
- fi
- fi
- ;;
- esac
- done < "$fn"
-}
-
-# Usage: ini_config_is_set file section var
-ini_config_is_set()
-{
- local fn section var sect= str eof= n v
- fn="$1" section="$2" var="$3"
-
- while [ -z "$eof" ]; do
- read -r str || eof=1
-
- case "$str" in
- "["*"]")
- [ "$str" != "[$section]" ] ||
- sect=1
- ;;
- "$shell_ini_config_comment"*|'')
- ;;
- *)
- if [ -n "$sect" ]; then
- shell_var_trim n "${str%%=*}"
-
- if [ "$n" = "$var" ]; then
- # Return success, since we found match.
- return 0
- fi
- fi
- ;;
- esac
- done < "$fn"
-
- # We did not find match, so return failure.
- return 1
-}
-
-# Usage: ini_config_set file section var value
-ini_config_set() {
- local fn fn_tmp section var value sect= don= str eof= n v
-
- fn="$1" section="$2" var="$3" value="$4"
- fn_tmp="$(mktemp "$fn.XXXXXX")"
-
- while [ -z "$eof" ]; do
- read -r str || eof=1
-
-
- case "$str" in
- "[$section]")
- sect=2
- printf '%s\n' "$str"
- ;;
- "["*"]")
- if [ "$sect" = 2 -a -z "$don" ]; then
- printf '\t%s\n' "$var = $value"
- don=1
- fi
- sect=1
- printf '%s\n' "$str"
- ;;
- "$shell_ini_config_comment"*|'')
- [ -n "$str" ] &&
- printf ${sect:+'\t'}'%s\n' "$str" ||
- printf '\n'
- ;;
- *)
- shell_var_trim n "${str%%=*}"
- shell_var_trim v "${str#*=}"
-
- if [ "$sect" = 2 -a "$n" = "$var" ]; then
- [ -n "$don" ] ||
- printf '\t%s\n' "$n = $value"
- don=1
- continue
- fi
- printf '\t%s\n' "$n = $v"
- ;;
- esac
-
- if [ -n "$eof" -a -z "$don" ]; then
- [ "$sect" = 2 ] ||
- printf '[%s]\n' "$section"
- printf '\t%s\n' "$var = $value"
- fi
-
- done < "$fn" > "$fn_tmp"
- mv -f -- "$fn_tmp" "$fn"
-}
-
-__ini_config_del_comment() {
- local fn_tmp sect= str eof= n v
- fn_tmp="$(mktemp "$fn.XXXXXX")"
-
- while [ -z "$eof" ]; do
- read -r str || eof=1
-
- case "$str" in
- "["*"]")
- sect=1
- [ "$str" != "[$section]" ] ||
- sect=2
- printf '%s\n' "$str"
- ;;
- "$shell_ini_config_comment"*|'')
- [ -n "$str" ] &&
- printf ${sect:+'\t'}'%s\n' "$str" ||
- printf '\n'
- ;;
- *)
- shell_var_trim n "${str%%=*}"
- shell_var_trim v "${str#*=}"
-
- [ "$sect" = 2 ] &&
- __ini_config_action "$n" "$v" ||
- printf '\t%s\n' "$n = $v"
- ;;
- esac
- done < "$fn" > "$fn_tmp"
- mv -f -- "$fn_tmp" "$fn"
- unset __ini_config_action
-}
-
-# Usage: ini_config_del file section [var]
-ini_config_del() {
- local fn="$1" section="$2" var="${3-}"
-
- __ini_config_action() {
- [ -z "$var" -o "$1" = "$var" ] ||
- printf '\t%s\n' "$1 = $2"
- }
- __ini_config_del_comment
-}
-
-# Usage: ini_config_comment file section [var]
-ini_config_comment() {
- local fn="$1" section="$2" var="${3-}"
-
- __ini_config_action() {
- if [ -n "$var" -a "$1" != "$var" ]; then
- printf '\t%s\n' "$1 = $2"
- return
- fi
- printf '\t%s\n' "$shell_ini_config_comment $1 = $2"
- }
- __ini_config_del_comment
-}
-
-fi #__included_shell_ini_config
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_ip_address-}" ]; then
-__included_shell_ip_address=1
-
-# Regexp for single byte
-readonly regex_byte='([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])'
-
-# Regexp for 4-byte address
-readonly regex_ipaddr="$regex_byte(\.$regex_byte){3}"
-
-# Regexp for IPv4 address
-#
-# (http://en.wikipedia.org/wiki/IP_address)
-#
-# Some first-octet values have special meanings:
-#
-# * First octet 127 represents the local computer, regardless of what network
-# it is really in. This is useful when testing internal operations.
-#
-# * First octet 224 and above are reserved for special purposes such as
-# multicasting.
-#
-# Octets 0 and 255 are not acceptable values in some situations, but 0 can be used
-# as the second and/or third octet (e.g. 10.2.0.100).
-#
-readonly __regex_fbyte='([1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])'
-readonly __regex_sbyte='([1]?[0-9][0-9]?|2[0-4][0-9]|25[0-4])'
-readonly __regex_lbyte='([1]?[0-9][0-9]?|2[0-4][0-9]|25[0-4])'
-
-readonly regex_ipv4="${__regex_fbyte}(\.${__regex_sbyte}){2}\.${__regex_lbyte}"
-
-# Checks that given option value is a valid IPv4 address.
-valid_ipv4() {
- local ipaddr="$1"
- local i=0 byte
-
- byte="${ipaddr##*.}"
- ipaddr="${ipaddr%.$byte}"
-
- [ "$byte" -gt 0 -a "$byte" -lt 255 ] 2>/dev/null ||
- return 1
-
- while [ $i -lt 3 ]; do
- byte="${ipaddr##*.}"
-
- [ "$byte" != "$ipaddr" ] ||
- break
-
- ipaddr="${ipaddr%.$byte}"
-
- [ "$byte" -ge 0 -a "$byte" -lt 255 ] 2>/dev/null ||
- return 1
-
- i=$(($i+1))
- done
-
- [ $i -eq 2 -a \
- "$byte" -ne 127 -a "$byte" -gt 0 -a "$byte" -lt 224 ] 2>/dev/null ||
- return 1
-}
-
-__ipv4_hex() {
- [ -n "${1-}" ] ||
- return 2
-
- local IFS=.
- set -- $1
-
- local i=0
- for b; do
- [ "$b" -ge 0 -a "$b" -le 255 ] 2>/dev/null ||
- return 2
- i=$(($i + 1))
- done
-
- [ "$i" -eq 4 ] ||
- return 2
-
- printf '0x'
- printf '%02x' "$@"
-}
-
-# Checks that IP address is in subnet
-# Usage example:
-# ipv4_ip_subnet 172.16.1.2 172.16.1.0/24; echo res=$?
-# res=0
-#
-# ipv4_ip_subnet 172.16.3.2 172.16.1.0/24; echo res=$?
-# res=1
-ipv4_ip_subnet() {
- local ip net prefix
- ip="${1-}"; shift
- net="${1-}"; shift
- prefix="${net##*/}"
-
- [ -n "$prefix" -a "$prefix" -ge 0 ] 2>/dev/null ||
- return 2
-
- local hex_addr hex_net hex_mask p
-
- hex_addr="$(__ipv4_hex "$ip")" &&
- hex_net="$(__ipv4_hex "${net%%/*}")" ||
- return 2
-
- p=$((0xFFFFFFFF))
- hex_mask="$(($p - ($p >> $prefix)))"
- [ "$(($hex_net & $hex_mask))" -eq "$(($hex_addr & $hex_mask))" ] ||
- return 1
-}
-
-# Convert netmask to routing prefix.
-# Usage example:
-# ipv4_mask2prefix 255.255.0.0
-# 16
-#
-# ipv4_prefix2mask 255.255.255.0
-# 24
-ipv4_mask2prefix() {
- local hex_mask
- hex_mask="$(__ipv4_hex "${1-}")" ||
- return 2
-
- local p i=0 prefix=
-
- p=$((~$hex_mask & 0xFFFFFFFF))
-
- while [ "$p" -ne 0 ]; do
- p=$(($p >> 1 & 0xFFFFFFFF))
- i=$(($i + 1))
- done
- prefix=$((32 - $i))
-
- [ "$prefix" -ge 0 -a "$prefix" -le 32 ] ||
- return 1
- echo "$prefix"
-}
-
-# Convert routing prefix to netmask.
-# Usage example:
-# ipv4_prefix2mask 16
-# 255.255.0.0
-#
-# ipv4_prefix2mask 24
-# 255.255.255.0
-ipv4_prefix2mask() {
- local len
- len="${1-}"
-
- [ "$len" -ge 0 -a "$len" -le 32 ] 2>/dev/null ||
- return 1
-
- local position=$((0xFFFFFFFF))
- local mask=$(($position - ($position >> $len)))
-
- printf '%s.%s.%s.%s\n' \
- "$(($mask >> 24 & 0xFF))" \
- "$(($mask >> 16 & 0xFF))" \
- "$(($mask >> 8 & 0xFF))" \
- "$(($mask & 0xFF))"
-}
-
-fi #__included_shell_ip_address
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_mail_address-}" ]; then
-__included_shell_mail_address=1
-
-if [ -n "${shell_mail_address_strict-}" ]; then
- #
- # (http://en.wikipedia.org/wiki/Country_code_top-level_domain)
- #
- # A country code top-level domain (ccTLD) is an Internet top-level domain
- # generally used or reserved for a country or a dependent territory.
- #
- readonly regex_cctld_active='(a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstwyz]|c[acdfghiklmnoruvxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[adefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklnrstwy]|qa|r[eosuw]|s[abcdeghiklmnrtuvyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|ye|z[amw])'
- readonly regex_cctld_reserved='(um|bl|eh|mf)'
- readonly regex_cctld_allocated='(bv|gb|pm|sj|so|yt)'
- readonly regex_cctld_phaseout='(tp|yu)'
- readonly regex_cctld_deleted='(cs|dd|zr)'
-
- # (http://en.wikipedia.org/wiki/GTLD)
- #
- # A generic top-level domain (gTLD) is a top-level domain used by a
- # particular class of organization.
- #
- readonly regex_gtld='(aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel)'
-
- regex_tld="($regex_gtld|$regex_cctld_active|$regex_cctld_reserved|$regex_cctld_allocated|$regex_cctld_phaseout)"
-else
- regex_tld='([a-zA-Z]{2,4}|museum|travel)'
-fi
-
-# 6. ADDRESS SPECIFICATION (http://tools.ietf.org/html/rfc822)
-#
-# addr-spec = local-part "@" domain ; global address
-# local-part = word *("." word) ; uninterpreted
-# ; case-preserved
-# domain = sub-domain *("." sub-domain)
-# sub-domain = domain-ref / domain-literal
-# domain-ref = atom ; symbolic reference
-#
-# 6.2.3. DOMAIN TERMS
-# A domain-ref must be THE official name of a registry, network,
-# or host.
-
-# This regexp should be used ignoring case.
-readonly regex_domain="([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)\.$regex_tld"
-
-# Regexp can be used to check and parse email address. This regexp
-# should be used ignoring case.
-# Usage example:
-# username="$(printf '%s' "$email" |sed -e "s/^$regex_email\$/\1/i")
-# domain="$(printf '%s' "$email" |sed -e "s/^$regex_email\$/\2/i")
-#
-readonly regex_email="([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*)@($regex_domain)"
-
-# Checks that given option value is a valid email address.
-valid_email() {
- local email="$1"
- printf '%s' "$email" |
- egrep -iqs "^$regex_email\$" ||
- return 1
-}
-
-fi #__included_shell_mail_address
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_quote-}" ]; then
-__included_shell_quote=1
-
-. shell-version
-. shell-error
-. shell-string
-
-# Quote argument for sed basic regular expression and store result into variable.
-# Usage example:
-# quote_sed_regexp_variable var_pattern "$pattern"
-# quote_sed_regexp_variable var_replace "$replace"
-# sed "s/$var_pattern/$var_replace/"
-quote_sed_regexp_variable() {
- local __quote_set_regexp_variable_var __quote_set_regexp_variable_out
- __quote_set_regexp_variable_var="$1"; shift
- __quote_set_regexp_variable_out="$*"
- if [ -z "${__quote_set_regexp_variable_out##*[\[\].*&^\$\\\\/]*}" ]; then
- __quote_set_regexp_variable_out="$(printf %s "$__quote_set_regexp_variable_out" |
- sed -e 's/[].*&^$[\/]/\\&/g')" ||
- return 1
- fi
- eval "$__quote_set_regexp_variable_var=\"\$__quote_set_regexp_variable_out\""
-}
-
-# Quote given arguments for sed basic regular expression.
-# Usage example: sed "s/$(quote_sed_regexp "$var_pattern")/$(quote_sed_regexp "$var_replacement")/"
-quote_sed_regexp() {
- local result
- quote_sed_regexp_variable result "$@"
- printf %s "$result"
-}
-
-# Quote argument for shell and store result into variable.
-# Usage example:
-# quote_shell_variable var_name "$var_value"
-# printf '%s\n' "$var_name"
-quote_shell_variable() {
- local __quote_shell_variable_var __quote_shell_variable_out
- __quote_shell_variable_var="$1"; shift
- __quote_shell_variable_out="$*"
- if [ -z "${__quote_shell_variable_out##*[\"\$\`\\\\]*}" ]; then
- __quote_shell_variable_out="$(printf %s "$__quote_shell_variable_out" |
- sed -e 's/[\"$\`\\]/\\&/g')" ||
- return 1
- fi
- eval "$__quote_shell_variable_var=\"\$__quote_shell_variable_out\""
-}
-
-# Quote argument for shell.
-# Usage example: eval "$var_name=\"$(quote_shell "$var_value")\""
-quote_shell() {
- local result
- quote_shell_variable result "$@"
- printf %s "$result"
-}
-
-# Quote argument for shell and store result into variable.
-#
-# Usage example:
-# quote_shell_args args "$var_args"
-# eval "set -- $args"
-quote_shell_args() {
-# This is an internal function to avoid the use of ugly namespace.
-__quote_shell_args() {
- local m= r= c= l="$1"
- # backslash/double/single quote mode
- local bq= dq= sq=
-
- __quote_shell_args_toggle() {
- # toggle $1 value
- eval [ -n \"\$$1\" ] && eval "$1=" || eval "$1=\$$2"
- }
-
- fill_mask m "$l"
-
- while [ -n "$l" ]; do
- c="${l%$m}"
- l="${l#?}"
- m="${m#?}"
-
- case "$c" in
- \")
- # toggle double quote mode unless
- # in backslash or single quote mode
- [ -n "$bq$sq" ] || __quote_shell_args_toggle dq c
- ;;
- \')
- # toggle single quote mode unless
- # in backslash or double quote mode
- [ -n "$bq$dq" ] || __quote_shell_args_toggle sq c
- ;;
- \$|\`)
- # quote special character unless
- # in backslash or single quote mode
- [ -n "$bq$sq" ] || bq=\\
- ;;
- \\)
- # toggle backslash quote mode unless
- # in single quote mode
- if [ -z "$sq" ]; then
- if [ -z "$bq" ]; then
- # enter backslash quote mode
- bq=\\
- continue
- else
- # leave backslash quote mode
- r="$r\\"
- bq=
- fi
- fi
- ;;
- [!A-Za-z0-9_\ \ ])
- # quote non-regular character unless
- # in any quote mode
- [ -n "$bq$dq$sq" ] || bq=\\
- ;;
- esac
- r="$r$bq$c"
- # leave backslash quote mode if any
- bq=
- done
-
- [ -z "$bq$dq$sq" ] ||
- { message "unmatched character ($bq$dq$sq) found"; return 1; }
- __quote_shell_args_out="$r"
-}
- local __quote_shell_args_out= __quote_shell_args_rc=0
- __quote_shell_args "$2" ||
- __quote_shell_args_rc=1
- eval "$1=\"\$__quote_shell_args_out\""
-
- # Remove internal functions from user namespace.
- unset __quote_shell_args __quote_shell_args_toggle
-
- return $__quote_shell_args_rc
-}
-
-if [ -n "${__export_compatibility_string_quote_remove-}" ]; then
-# Obsolete function. You shouldn't use it.
-string_quote_remove() {
- local out="$1"
- if [ -z "${1##*\'}${1%%\'*}" ]; then
- out="${1#\'}"
- out="${out%\'}"
- elif [ -z "${1##*\"}${1%%\"*}" ]; then
- out="${1#\"}"
- out="${out%\"}"
- fi
- printf %s "$out"
-}
-fi # __export_compatibility_string_quote_remove
-
-fi #__included_shell_quote
+++ /dev/null
-shell-quote
\ No newline at end of file
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_run-}" ]; then
-__included_shell_run=1
-
-. shell-args
-. shell-source
-
-# Execute command if file is executable.
-# Usage: run_if_executable /file arg1 arg2
-# or: run_if_executable file arg1 arg2
-run_if_executable() {
- local v f
- f="$1"; shift
- ! __shell_source_find v "$f" || [ ! -x "$v" ] || "$v" "$@"
-}
-
-# Run scripts from directory.
-# Usage: run_scripts <dir> [args]
-RUN_SCRIPTS_EXCLUDE='*.rpm* *.swp *,v *~ *.\#'
-run_scripts() {
- [ "$#" -ge 1 ] ||
- fatal "Usage: run_scripts <dir> [args]"
- local p f d rc=0
- d="$(opt_check_dir "dir" "$1")"; shift
-
- for f in $(find -L "$d" -mindepth 1 -maxdepth 1 -type f); do
- for p in $RUN_SCRIPTS_EXCLUDE; do
- [ -n "${f##$p}" ] ||
- continue 2
- done
- run_if_executable "$f" "$@" || rc=1
- done
- return $rc
-}
-
-fi #__included_shell_run
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_signal-}" ]; then
-__included_shell_signal=1
-
-. shell-error
-. shell-quote
-
-__shell_signal_handlers=
-# Set handler code whan any of the specified signals are received.
-# Return code of handler function will be ignored. Special handlers is
-# SIG_IGN and SIG_DFL (See signal(2)).
-#
-# Usage example:
-# signal_handler 'echo $arg' TERM EXIT HUP
-# signal_handler SIG_IGN TERM EXIT HUP
-# signal_handler SIG_DFL TERM EXIT HUP
-signal_handler() {
- local action real_action sign
- action="$1"; shift
-
- for sign; do
- sign="${sign#SIG}"
- case "$action" in
- SIG_IGN)
- eval "unset __signal_handlers_$sign"
- real_action=:
- trap : "$sign"
- ;;
- SIG_DFL)
- eval "unset __signal_handlers_$sign"
- real_action=-
- trap - "$sign"
- ;;
- *)
- eval "handler=\"\${__signal_handlers_$sign-} \$action;\""
- trap "$handler" "$sign"
- eval "__signal_handlers_$sign=\"\$handler\""
- ;;
- esac
- done
-}
-
-# Set exit handler. Return code of handler function will be ignored.
-#
-# Usage example:
-# exit_function() { echo "Exit with return code '$1'"; }
-# set_cleanup_handler exit_function
-__cleanup_handler_name=
-set_cleanup_handler() {
- __cleanup_handler_name="${1-}"
- __cleanup_handler() {
- trap - EXIT
- [ -z "${__cleanup_handler_name-}" ] ||
- "$__cleanup_handler_name" "$1" ||:
- exit "$1"
- }
- signal_handler '__cleanup_handler $?' EXIT
- signal_handler '__cleanup_handler 1' HUP PIPE INT QUIT TERM
-}
-
-# Remove exit handler.
-#
-# Usage example: unset_cleanup_handler
-unset_cleanup_handler() {
- signal_handler SIG_DFL EXIT HUP PIPE INT QUIT TERM
- __cleanup_handler_name=
-}
-
-fi #__included_shell_signal
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_source-}" ]; then
-__included_shell_source=1
-
-__shell_source_find() {
- local r f IFS=:
- r="$1"; shift
- f="$1"; shift
-
- if [ -n "${f##*/*}" ]; then
- set -- ${PATH-}
- while [ "$#" -gt 0 ]; do
- if [ -e "$1/$f" ]; then
- f="$1/$f"
- break
- fi
- shift
- done
- fi
- [ -e "$f" ] || return 1
- eval "$r=\"\$f\""
-}
-
-# Execute commands from file in the current environment if file exists.
-# Usage: source_if_exists /file arg1 arg2
-# or: source_if_exists file arg1 arg2
-source_if_exists() {
- local v f
- f="$1"; shift
- ! __shell_source_find v "$f" || [ ! -f "$v" ] || . "$v"
-}
-
-# Execute commands from file in the current environment if file is not empty.
-# Usage: source_if_notempty /file arg1 arg2
-# or: source_if_notempty file arg1 arg2
-source_if_notempty() {
- local v f
- f="$1"; shift
- ! __shell_source_find v "$f" || [ ! -s "$v" ] || . "$v"
-}
-
-# Execute commands from file in the current environment if file is executable.
-# Usage: source_if_executable /file arg1 arg2
-# or: source_if_executable file arg1 arg2
-source_if_executable() {
- local v f
- f="$1"; shift
- ! __shell_source_find v "$f" || [ ! -x "$v" ] || . "$v"
-}
-
-fi #__included_shell_source
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_string-}" ]; then
-__included_shell_string=1
-
-# Creates a mask of equal length string.
-# Usage: fill_mask var str [full-length]
-fill_mask() {
- local __i=0 __m= __v="$1" __s="$2"
- while [ $__i -lt ${#__s} ]; do
- __m="$__m?????"
- __i=$(($__i + 5))
- done
- case $((${#__m} - ${#__s})) in
- 5) __m="${__m#?????}" ;;
- 4) __m="${__m#????}" ;;
- 3) __m="${__m#???}" ;;
- 2) __m="${__m#??}" ;;
- 1) __m="${__m#?}" ;;
- esac
- [ -n "${3-}" ] || __m="${__m#?}"
- eval "$__v=\$__m"
-}
-
-fi #__included_shell_string
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_unittest-}" ]; then
-__included_shell_unittest=1
-
-. shell-error
-
-# Append tests condition to comment message if test failed.
-unittest_show_condition="${unittest_show_condition-}"
-
-# Called before each test is run.
-setUp() { :; }
-
-# Called after each test is run.
-tearDown() { :; }
-
-# Called before any test is run.
-setUpTests() { :; }
-
-# Called after any test is run.
-tearDownTests() { :; }
-
-# Register new testing function.
-# appendTests (TestFunc)
-__shell_unit_tests=
-appendTests() {
- while [ "$#" -gt 0 ]; do
- __shell_unit_tests="$__shell_unit_tests
-$1"
- shift
- done
-}
-
-# Automatically register test functions with 'UnitTest' comment.
-# Name of current shell script will be used if argument is not present.
-# registerTests([/tmp/Tests-File])
-# Example:
-# my_testcase_function() { # UnitTest
-# blah blah blah ...
-# }
-registerTests() {
- local l="$(sed -ne 's/^\([[:alnum:]_]\+\)().*[[:space:]]*#[[:space:]]*UnitTest/\1/p' "${1:-$0}")"
- [ -z "$l" ] || appendTests $l
-}
-
-# Skip test (called in testing function)
-shouldSkip() {
- exit 2
-}
-
-# Asserts that a given shell test condition (or integer) is true.
-# assertTrue([comment], condition)
-# assertTrue([comment], integer)
-assertTrue() {
- local comment= condition
- [ "$#" -lt 2 ] ||
- { comment="$1"; shift; }
- condition="$1"; shift
-
- [ -z "$unittest_show_condition" ] ||
- comment="${comment:+$comment }($condition) == false"
-
- if [ -n "${condition##*[!0-9\-]*}" ]; then
- [ $condition -ne 0 ] ||
- return 0
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-
- if ! ( eval "$condition" ) >/dev/null; then
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-}
-
-# Asserts that a given shell test condition (or integer) is false.
-# assertFalse([comment], condition)
-# assertFalse([comment], integer)
-assertFalse() {
- local comment= condition
- [ "$#" -lt 2 ] ||
- { comment="$1"; shift; }
- condition="$1"; shift
-
- [ -z "$unittest_show_condition" ] ||
- comment="${comment:+$comment }($condition) == true"
-
- if [ -n "${condition##*[!0-9\-]*}" ]; then
- [ $condition -eq 0 ] ||
- return 0
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-
- if ( eval "$condition" ) >/dev/null; then
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-}
-
-# Asserts that two arguments are equal to one another.
-# assertEquals([comment], expected, actual)
-assertEquals() {
- local comment= expected actual
- [ "$#" -lt 3 ] ||
- { comment="$1"; shift; }
- expected="$1"; shift
- actual="$1"; shift
-
- if [ "$expected" != "$actual" ]; then
- [ -z "$unittest_show_condition" ] ||
- comment="${comment:+$comment }($expected) != ($actual)"
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-}
-
-# Asserts that two arguments are same.
-# assertSame([comment], expected, actual)
-assertSame() {
- assertEquals "${@-}"
-}
-
-# Asserts that two arguments are not equal to one another.
-# assertNotEquals([comment], expected, actual)
-assertNotEquals() {
- local comment= expected actual
- [ "$#" -lt 3 ] ||
- { comment="$1"; shift; }
- expected="$1"; shift
- actual="$1"; shift
-
- if [ "$expected" = "$actual" ]; then
- [ -z "$unittest_show_condition" ] ||
- comment="${comment:+$comment }($expected) == ($actual)"
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-}
-
-# Asserts that two arguments are not same.
-# assertNotSame([comment], expected, actual)
-assertNotSame() {
- assertNotEquals "${@-}"
-}
-
-# Asserts that argument is a zero-length string.
-# assertNull([comment], value)
-assertNull() {
- local comment= value
- [ "$#" -lt 2 ] ||
- { comment="$1"; shift; }
- value="$1"; shift
-
- if [ -n "$value" ]; then
- [ -z "$unittest_show_condition" ] ||
- comment="${comment:+$comment }($value) == ''"
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-}
-
-# Asserts that argument is not empty string.
-# assertNotNull([comment], value)
-assertNotNull() {
- local comment= value
- [ "$#" -lt 2 ] ||
- { comment="$1"; shift; }
- value="$1"; shift
-
- if [ -z "$value" ]; then
- [ -z "$unittest_show_condition" ] ||
- comment="${comment:+$comment }($value) != ''"
- [ -z "$comment" ] ||
- printf '%s' "$comment"
- exit 1
- fi
-}
-
-# Display status message after each test.
-messageTest() {
- case "$3" in
- 0) printf '[done]' ;;
- 1) printf '[FAIL]' ;;
- 2) printf '[skip]' ;;
- *) printf '[status=%s]' $3 ;;
- esac
- printf ' (%s) %s\n' "$1" "$2"
-}
-
-# Display summary statistic.
-showSummary() {
- if [ "$total" -eq 0 ]; then
- message "Nothing to do"
- return
- fi
- printf '\n'
- printf 'tests passed: %6d %3d%%\n' "$passed" "$((($passed*100)/$total))"
- printf 'tests failed: %6d %3d%%\n' "$failed" "$((($failed*100)/$total))"
- printf 'tests skipped: %6d %3d%%\n' "$skipped" "$((($skipped*100)/$total))"
- printf 'tests total: %6d\n\n' "$total"
-}
-
-# Run tests.
-runUnitTests() {
-
- run_or_exit() {
- "$@" || fatal "$1() fail rc=$?"
- }
-
- run_or_exit setUpTests
-
- local IFS='
-'
- __shell_unit_tests="$(printf '%s\n' "$__shell_unit_tests" |sort -u)"
- set -- ${__shell_unit_tests-}
-
- local retval=0 rc passed=0 failed=0 skipped=0 total="$#"
-
- while [ "$#" -gt 0 ]; do
- run_or_exit setUp
-
- rc=0
- msg="$("$1")" || rc=$?
-
- case "$rc" in
- 0) passed=$(($passed+1)) ;;
- 1) failed=$(($failed+1)); retval=1; ;;
- 2) skipped=$(($skipped+1)) ;;
- esac
- run_or_exit messageTest "$1" "$msg" "$rc"
-
- run_or_exit tearDown
- shift
- done
- run_or_exit showSummary
- run_or_exit tearDownTests
-
- return $retval
-}
-
-fi #__included_shell_unittest
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_var-}" ]; then
-__included_shell_var=1
-
-. shell-error
-
-shell_var_is_yes() {
- [ "$#" -eq 1 ] ||
- fatal "Usage: shell_var_yes value"
- case "$1" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|[Yy]|1) return 0 ;;
- esac
- return 1
-}
-
-shell_var_is_no() {
- [ "$#" -eq 1 ] ||
- fatal "Usage: shell_var_no value"
- case "$1" in
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|[Nn]|0) return 0 ;;
- esac
- return 1
-}
-
-# Strip whitespace from the beginning and end of a string
-# Usage: shell_var_trim retval " aaa bb aaa "; echo "[$retval]"
-# [aaa bb aaa]
-shell_var_trim() {
- [ "$#" -eq 2 ] ||
- fatal "Usage: shell_var_trim varname value"
- local __shell_var_trim_var="$1" __shell_var_trim_ret="$2"
- local IFS='
-'
- set -- $__shell_var_trim_ret
- if [ "$#" -eq 0 ]; then
- eval "$__shell_var_trim_var=''"
- return
- fi
- __shell_var_trim_ret="$1${__shell_var_trim_ret#*$1}"
- shift $(($#-1))
- __shell_var_trim_ret="${__shell_var_trim_ret%$1*}$1"
- eval "$__shell_var_trim_var=\"\$__shell_var_trim_ret\""
-}
-
-# Remove quote symbol from string
-# Usage example:
-# for i in "\"str1\"" "'str2'" "\"str3'"; do
-# shell_var_unquote var "$i";
-# echo "$var";
-# done
-#
-# Result:
-# str1
-# str2
-# "str3'
-#
-shell_var_unquote() {
- [ "$#" -eq 2 ] ||
- fatal "Usage: shell_var_unquote varname value"
- local __shell_var_unquote_var="$1" __shell_var_unquote_out="$2"
- if [ -z "${__shell_var_unquote_out##*\'}${__shell_var_unquote_out%%\'*}" ]; then
- __shell_var_unquote_out="${__shell_var_unquote_out#\'}"
- __shell_var_unquote_out="${__shell_var_unquote_out%\'}"
- elif [ -z "${__shell_var_unquote_out##*\"}${__shell_var_unquote_out%%\"*}" ]; then
- __shell_var_unquote_out="${__shell_var_unquote_out#\"}"
- __shell_var_unquote_out="${__shell_var_unquote_out%\"}"
- fi
- eval "$__shell_var_unquote_var=\"\$__shell_var_unquote_out\""
-}
-
-fi #__included_shell_var
+++ /dev/null
-#!/bin/sh -efu
-# This file is covered by the GNU General Public License,
-# which should be included with libshell as the file LICENSE.
-# All copyright information are listed in the COPYING.
-
-if [ -z "${__included_shell_version-}" ]; then
-__included_shell_version=1
-
-libshell_version=3
-
-__export_compatibility_string_quote_remove=1
-
-fi #__included_shell_version
+++ /dev/null
-#!/bin/ash -efu
-
-CMDLINE='ro rw= root=LABEL=ROOT resume=/dev/sda1 panic=30 foo.bar="zzz xxx" BOOT_IMAGE=/bad/param BOOT-IMAGE=/boot/vmlinuz'
-
-cmdline_get_test1() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'resume' "$CMDLINE"
- assertEquals "resume=[$result]" "$result" '/dev/sda1'
-}
-
-cmdline_get_test2() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'ro' "$CMDLINE"
- assertEquals "ro=[$result]" "$result" '1'
-}
-
-cmdline_get_test3() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'rw' "$CMDLINE"
- assertEquals "rw=[$result]" "$result" ''
-}
-
-cmdline_get_test4() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'root' "$CMDLINE"
- assertEquals "root=[$result]" "$result" 'LABEL=ROOT'
-}
-
-cmdline_get_test5() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'foo.bar' "$CMDLINE"
- assertEquals "foo.bar=[$result]" "$result" 'zzz xxx'
-}
-
-cmdline_get_test6() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'BOOT-IMAGE' "$CMDLINE"
- assertEquals "BOOT-IMAGE=[$result]" "$result" '/boot/vmlinuz'
-}
-
-cmdline_get_test7() { # UnitTest
- . ../shell-cmdline
-
- local result
- cmdline_get 'result' 'BOOT_IMAGE' "$CMDLINE"
- assertEquals "BOOT_IMAGE=[$result]" "$result" '/boot/vmlinuz'
-}
+++ /dev/null
-a b "c d" 'e f'
+++ /dev/null
-[a] [b] [c d] [e f]
+++ /dev/null
-a b "c ' d" 'e " f'
+++ /dev/null
-[a] [b] [c ' d] [e " f]
+++ /dev/null
-a b "c \" d" e f
+++ /dev/null
-[a] [b] [c " d] [e] [f]
+++ /dev/null
-a $HOME \$HOME \\$HOME \\\$HOME \\\\$HOME c
+++ /dev/null
-[a] [$HOME] [$HOME] [\$HOME] [\$HOME] [\\$HOME] [c]
+++ /dev/null
-a "$HOME \$HOME \\$HOME \\\$HOME \\\\$HOME" c
+++ /dev/null
-[a] [$HOME $HOME \$HOME \$HOME \\$HOME] [c]
+++ /dev/null
-a '$HOME \$HOME \\$HOME \\\$HOME \\\\$HOME' c
+++ /dev/null
-[a] [$HOME \$HOME \\$HOME \\\$HOME \\\\$HOME] [c]
+++ /dev/null
-/bin/shell-* /bin/shell-[a-z]* /bin/shell-{error,getopt}
+++ /dev/null
-[/bin/shell-*] [/bin/shell-[a-z]*] [/bin/shell-{error,getopt}]
+++ /dev/null
-"/bin/shell-* /bin/shell-[a-z]* /bin/shell-{error,getopt}"
+++ /dev/null
-[/bin/shell-* /bin/shell-[a-z]* /bin/shell-{error,getopt}]
+++ /dev/null
-/bin/shell-* "/bin/shell-[a-z]* /bin/shell-{error,getopt}"
+++ /dev/null
-[/bin/shell-*] [/bin/shell-[a-z]* /bin/shell-{error,getopt}]
+++ /dev/null
-'/bin/shell-* /bin/shell-[a-z]* /bin/shell-{error,getopt}'
+++ /dev/null
-[/bin/shell-* /bin/shell-[a-z]* /bin/shell-{error,getopt}]
+++ /dev/null
-`echo $HOME` "`echo $HOME`" '`echo $HOME`' "(`echo $HOME`)"
+++ /dev/null
-[`echo] [$HOME`] [`echo $HOME`] [`echo $HOME`] [(`echo $HOME`)]
+++ /dev/null
-echo |- echo;echo echo echo||echo "echo||echo" 'echo||echo'
+++ /dev/null
-[echo] [|-] [echo;echo] [echo] [echo||echo] [echo||echo] [echo||echo]
+++ /dev/null
-a b "c \\\" ' d" 'e " f'
+++ /dev/null
-[a] [b] [c \" ' d] [e " f]
+++ /dev/null
-a b <<EOF "<<EOF" '<<EOF' <<'__EOF__' c
+++ /dev/null
-[a] [b] [<<EOF] [<<EOF] [<<EOF] [<<__EOF__] [c]
+++ /dev/null
-a || b && c "&&" d '&&' e &
+++ /dev/null
-[a] [||] [b] [&&] [c] [&&] [d] [&&] [e] [&]
+++ /dev/null
-a ! b "! c" '!' d
+++ /dev/null
-[a] [!] [b] [! c] [!] [d]
+++ /dev/null
-echo ~ "echo ~" 'echo ~'
+++ /dev/null
-[echo] [~] [echo ~] [echo ~]
+++ /dev/null
-. /etc/passwd ". /etc/passwd"
+++ /dev/null
-[.] [/etc/passwd] [. /etc/passwd]
+++ /dev/null
-1"22"333"4444
+++ /dev/null
-1'22'333'4444
+++ /dev/null
-\123 \xab \" \\ \a \b \c \d \e \f \n \r \t \v
+++ /dev/null
-[123] [xab] ["] [\] [a] [b] [c] [d] [e] [f] [n] [r] [t] [v]
+++ /dev/null
-$'\n' $"\r"
+++ /dev/null
-[$\n] [$\r]
+++ /dev/null
-#!/bin/ash -efu
-
-PROG='TEST'
-
-fatal_test1() { # UnitTest
- . ../shell-error
- expect="$PROG: message message;"
- result=`fatal "message message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-fatal_test2() { # UnitTest
- . ../shell-error
- expect="$PROG: message;message;"
- result=`fatal "message
-message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-fatal_test3() { # UnitTest
- . ../shell-error
- zzz=ZZZ
- expect="$PROG: message ZZZ message;"
- result=`fatal "message $zzz message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-fatal_test4() { # UnitTest
- . ../shell-error
- expect="$PROG: message message;"
- result=`{ fatal "message message" 2>&1; echo "another message"; } |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-fill_mask_test01() { # UnitTest
- . ../shell-quote
- local result string='1234567890'
- fill_mask result "$string"
- assertEquals "$string" "$result" "?????????"
-}
-
-fill_mask_test02() { # UnitTest
- . ../shell-quote
- local result string='1234567890123'
- fill_mask result "$string"
- assertEquals "$string" "$result" "????????????"
-}
-
-fill_mask_test03() { # UnitTest
- . ../shell-quote
- local result string='1234567890123'
- fill_mask result "$string" 1
- assertEquals "$string" "$result" "?????????????"
-}
-
-fill_mask_test04() { # UnitTest
- . ../shell-quote
- local result string='1'
- fill_mask result "$string"
- assertEquals "$string" "$result" ""
-}
-
-fill_mask_test05() { # UnitTest
- . ../shell-quote
- local result string='12'
- fill_mask result "$string"
- assertEquals "$string" "$result" "?"
-}
-
-fill_mask_test06() { # UnitTest
- . ../shell-quote
- local result string='123'
- fill_mask result "$string"
- assertEquals "$string" "$result" "??"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-normalize() {
- sed \
- -e "s/\"/'/g" \
- -e 's/[[:space:]]\+/ /g' \
- -e 's/^[[:space:]]\+//' \
- -e 's/[[:space:]]\+$//'
-}
-
-getopt_test001() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test002() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o ' ' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o ' ' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test003() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o '' -l ' ' -- ZZZ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o '' -l ' ' -- ZZZ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-
-getopt_test004() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -- -abc -a -b -c ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -- -abc -a -b -c ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test005() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -abc --caa 'AAA' --cba='BBB' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -abc --caa 'AAA' --cba='BBB' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test006() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- --cb 'AAA' --c='BBB' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- --cb 'AAA' --c='BBB' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test007() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- --cbz 'AAA' --c='BBB' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- --cbz 'AAA' --c='BBB' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test008() { # UnitTest
- LANG=C
- expect=`{ getopt -a -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -cb 'AAA' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -a -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -cb 'AAA' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test009() { # UnitTest
- LANG=C
- expect=`{ getopt -a -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -c='AAA' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -a -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -c='AAA' ; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- (assertEquals "$result" "$result" "$expect") ||:
- shouldSkip
-}
-
-getopt_test010() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -c='AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- -c='AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- (assertEquals "$result" "$result" "$expect") ||:
- shouldSkip
-}
-
-getopt_test011() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -l 'abcd:,cbce:' -- --abcx 'AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -l 'abcd:,cbce:' -- --abcx 'AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test012() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a:,b,c' -- -abc 'AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a:,b,c' -- -abc 'AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test013() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a::,b,c' -- -a -bc 'AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a::,b,c' -- -a -bc 'AAA'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test014() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- 'BBB' 'XXX ZZZ'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o 'a,b,c' -l 'caa:,cba:' -- 'BBB' 'XXX ZZZ'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test015() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o '+a,b,c' -l 'caa:,cba:' -- --caa='AAA' 'BBB' --zzz -x; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o '+a,b,c' -l 'caa:,cba:' -- --caa='AAA' 'BBB' --zzz -x; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-
-getopt_test016() { # UnitTest
- LANG=C
- expect=`{ getopt -n TEST -o '-a,b,c' -l 'caa:,cba:' -- 'AAA' --caa='BBB' 'CCC'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- . ../shell-getopt
- result=`{ getopt -n TEST -o '-a,b,c' -l 'caa:,cba:' -- 'AAA' --caa='BBB' 'CCC'; echo rc=$?; } 2>&1 |normalize |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-getopt_test017() { # UnitTest
- LANG=C
- . ../shell-getopt
- expect=' -a -b --
- -a -b --
- -a -b -- '
- result=`for i in 1 2 3; do getopt -n TEST -o 'a,b' -- -ab; done 2>&1`
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-[global]
- user= Foo Bar
-email = foo@bar
-
-[sect1]
-opt=OPT
-opt1=OPT1
-opt=OPT
-
-# Blah Blah
-[sect]
-opt="ZZZ XXX"
\ No newline at end of file
+++ /dev/null
-#!/bin/ash -efu
-
-ini_config_get_test1() { # UnitTest
- . ../shell-ini-config
- local result expect="Foo Bar"
- result="$(ini_config_get ini-config/z.ini global user)"
- assertEquals "$result" "$result" "$expect"
-}
-
-ini_config_get_test2() { # UnitTest
- . ../shell-ini-config
- local result expect="foo@bar"
- result="$(ini_config_get ini-config/z.ini global email)"
- assertEquals "$result" "$result" "$expect"
-}
-
-ini_config_get_test3() { # UnitTest
- . ../shell-ini-config
- local result expect="\"ZZZ XXX\""
- result="$(ini_config_get ini-config/z.ini sect opt)"
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-ini_config_set_test1() { # UnitTest
- . ../shell-ini-config
- local result expect="Aaa Bbb"
- cp -f ini-config/z.ini ini-config/t1.ini
-
- ini_config_set ini-config/t1.ini global user "$expect"
-
- result="$(ini_config_get ini-config/t1.ini global user)"
- assertEquals "$result" "$result" "$expect"
-}
-
-ini_config_set_test2() { # UnitTest
- . ../shell-ini-config
- local result expect='$1 \n\1 "Bbb"'
- cp -f ini-config/z.ini ini-config/t2.ini
-
- ini_config_set ini-config/t2.ini global user "$expect"
-
- result="$(ini_config_get ini-config/t2.ini global user)"
- assertEquals "$result" "$result" "$expect"
-}
-
-ini_config_set_test3() { # UnitTest
- . ../shell-ini-config
- local result expect='XXX'
- cp -f ini-config/z.ini ini-config/t3.ini
-
- ini_config_del ini-config/t3.ini global user
- ini_config_set ini-config/t3.ini global user "$expect"
-
- result="$(ini_config_get ini-config/t3.ini global user)"
- assertEquals "$result" "$result" "$expect"
-}
-
-ini_config_set_test4() { # UnitTest
- . ../shell-ini-config
- local result expect='XXX'
- cp -f ini-config/z.ini ini-config/t4.ini
-
- ini_config_comment ini-config/t4.ini global user
- ini_config_set ini-config/t4.ini global user "$expect"
-
- result="$(ini_config_get ini-config/t4.ini global user)"
- assertEquals "$result" "$result" "$expect"
-}
-
-ini_config_set_test5() { # UnitTest
- . ../shell-ini-config
- local result expect='ZZZ'
- cp -f ini-config/z.ini ini-config/t5.ini
-
- ini_config_set ini-config/t5.ini sect1 opt "$expect"
-
- result="$(ini_config_get ini-config/t5.ini sect1 opt)"
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-PROG='TEST'
-
-message_test1() { # UnitTest
- . ../shell-error
- expect="$PROG: message message;"
- result=`message "message message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-message_test2() { # UnitTest
- . ../shell-error
- expect="$PROG: message;message;"
- result=`message "message
-message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-message_test3() { # UnitTest
- . ../shell-error
- zzz=ZZZ
- expect="$PROG: message ZZZ message;"
- result=`message "message $zzz message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-message_test4() { # UnitTest
- . ../shell-error
- expect="$PROG: message message;another message;"
- result=`{ message "message message" 2>&1; echo "another message"; } |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-opt_check_dir_test1() { # UnitTest
- . ../shell-args
-
- [ -d "$WORKDIR/dir-644" ] ||
- mkdir -m644 "$WORKDIR/dir-644"
- cd "$WORKDIR"
-
- expect="$(message "DIR: ./dir-644: directory not available." 2>&1)"
- result="$(opt_check_dir "DIR" "./dir-644" 2>&1)" ||:
- rmdir "dir-644"
-
- assertEquals "$result" "$result" "$expect"
-}
-
-opt_check_dir_test2() { # UnitTest
- . ../shell-args
-
- [ -d "$WORKDIR/dir-755" ] ||
- mkdir -m755 "$WORKDIR/dir-755"
- cd "$WORKDIR"
-
- expect="$(readlink -ev ./dir-755 2>&1)" ||:
- result="$(opt_check_dir "DIR" "./dir-755" 2>&1)" ||:
- rmdir "dir-755"
-
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-opt_check_number_test1() { # UnitTest
- . ../shell-args
-
- string="1234"
- expect="1234"
- result="$(opt_check_number "NUM" "$string" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
-
-opt_check_number_test2() { # UnitTest
- . ../shell-args
-
- string="0001"
- expect="$(message "NUM: $string: invalid number." 2>&1)"
- result="$(opt_check_number "NUM" "$string" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
-
-opt_check_number_test3() { # UnitTest
- . ../shell-args
-
- string="1 2"
- expect="$(message "NUM: $string: invalid number." 2>&1)"
- result="$(opt_check_number "NUM" "$string" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-opt_check_read_test1() { # UnitTest
- . ../shell-args
-
- if [ ! -f "$WORKDIR/file-000" ]; then
- > "$WORKDIR/file-000"
- chmod 000 "$WORKDIR/file-000"
- fi
- cd "$WORKDIR"
-
- expect="$(message "FILE: ./file-000: file not available." 2>&1)"
- result="$(opt_check_read "FILE" "./file-000" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
-opt_check_read_test2() { # UnitTest
- . ../shell-args
-
- if [ ! -f "$WORKDIR/file-200" ]; then
- > "$WORKDIR/file-200"
- chmod 200 "$WORKDIR/file-200"
- fi
- cd "$WORKDIR"
-
- expect="$(message "FILE: ./file-200: file not available." 2>&1)"
- result="$(opt_check_read "FILE" "./file-200" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
-
-opt_check_read_test3() { # UnitTest
- . ../shell-args
-
- if [ ! -f "$WORKDIR/file-644" ]; then
- > "$WORKDIR/file-644"
- chmod 644 "$WORKDIR/file-644"
- fi
- cd "$WORKDIR"
-
- expect="$(readlink -ev ./file-644)"
- result="$(opt_check_read "FILE" "./file-644" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
-
-opt_check_read_test4() { # UnitTest
- . ../shell-args
-
- if [ ! -e "$WORKDIR/broken-symlink" ]; then
- ln -s "$WORKDIR/broken-symlink" "$WORKDIR/broken-symlink"
- fi
- cd "$WORKDIR"
-
- expect="$(message "FILE: ./broken-symlink: file not available." 2>&1)"
- result="$(opt_check_read "FILE" "./broken-symlink" 2>&1)" ||:
-
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-quote_sed_regexp_test1() { # UnitTest
- . ../shell-quote
- local string='.*'
- local regexp="$(quote_sed_regexp "$string")"
- local result="$(printf '%s\n' "$string passed" |sed -e "s/^$regexp/test/")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-quote_sed_regexp_test2() { # UnitTest
- . ../shell-quote
- local string='[[:space:]]'
- local regexp="$(quote_sed_regexp "$string")"
- local result="$(printf '%s\n' "test $string" |sed -e "s/$regexp/passed/")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-quote_sed_regexp_test3() { # UnitTest
- . ../shell-quote
- local string='t{1,3}'
- local regexp="$(quote_sed_regexp "$string")"
- local result="$(printf '%s\n' "test$string passed" |sed -e "s/$regexp//")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-quote_sed_regexp_test4() { # UnitTest
- . ../shell-quote
- local string='&\1'
- local regexp="$(quote_sed_regexp "$string")"
- local result="$(printf '%s\n' "test not passed" |sed -e "s/\(not\)/$regexp/")" #"
- assertEquals "$string" "$result" 'test &\1 passed'
-}
+++ /dev/null
-#!/bin/ash -efu
-
-quote_sed_regexp_variable_test1() { # UnitTest
- . ../shell-quote
- local string='.*'
- local regexp
- quote_sed_regexp_variable regexp "$string"
- local result="$(printf '%s\n' "$string passed" |sed -e "s/^$regexp/test/")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-quote_sed_regexp_variable_test2() { # UnitTest
- . ../shell-quote
- local string='[[:space:]]'
- local regexp
- quote_sed_regexp_variable regexp "$string"
- local result="$(printf '%s\n' "test $string" |sed -e "s/$regexp/passed/")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-quote_sed_regexp_variable_test3() { # UnitTest
- . ../shell-quote
- local string='t{1,3}'
- local regexp
- quote_sed_regexp_variable regexp "$string"
- local result="$(printf '%s\n' "test$string passed" |sed -e "s/$regexp//")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-quote_sed_regexp_variable_test4() { # UnitTest
- . ../shell-quote
- local string='&\1'
- local regexp
- quote_sed_regexp_variable regexp "$string"
- local result="$(printf '%s\n' "test not passed" |sed -e "s/\(not\)/$regexp/")" #"
- assertEquals "$string" "$result" 'test &\1 passed'
-}
+++ /dev/null
-#!/bin/ash -efu
-
-quote_shell_test1() { # UnitTest
- . ../shell-quote
- local string='`true`'
- local result
- eval "result=\"$(quote_shell "$string")\""
- assertEquals "$string" "$result" "$string"
-}
-
-quote_shell_test2() { # UnitTest
- . ../shell-quote
- local string='$(true)'
- local result
- eval "result=\"$(quote_shell "$string")\""
- assertEquals "$string" "$result" "$string"
-}
-
-quote_shell_test3() { # UnitTest
- . ../shell-quote
- local string='\`true\`; echo zzz'
- local result
- eval "result=\"$(quote_shell "$string")\""
- assertEquals "$string" "$result" "$string"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-PROG='TEST'
-
-quote_process() {
- local opts=
- quote_shell_args opts "$1" &&
- eval "set -- $opts" ||:
-
- local a= result=
- for a; do
- result="$result[$a] "
- done
- printf '%s\n' "${result% }"
-}
-
-quote_shell_args_test_000() { # UnitTest
- local num=000
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_001() { # UnitTest
- local num=001
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_002() { # UnitTest
- local num=002
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_003() { # UnitTest
- local num=003
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_004() { # UnitTest
- local num=001
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_005() { # UnitTest
- local num=005
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_006() { # UnitTest
- local num=006
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_007() { # UnitTest
- local num=007
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_008() { # UnitTest
- local num=008
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_009() { # UnitTest
- local num=009
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_010() { # UnitTest
- local num=010
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_011() { # UnitTest
- local num=011
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_012() { # UnitTest
- local num=012
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_013() { # UnitTest
- local num=013
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_014() { # UnitTest
- local num=014
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_015() { # UnitTest
- local num=015
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_016() { # UnitTest
- local num=016
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_017() { # UnitTest
- local num=017
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_018() { # UnitTest
- local num=018
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_019() { # UnitTest
- local num=019
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_020() { # UnitTest
- local num=020
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1 |tr '\n' ' ')"
-
- assertEquals "$result" 'TEST: unmatched character (\) found [a\] ' "$result"
-}
-
-quote_shell_args_test_021() { # UnitTest
- local num=021
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1 |tr '\n' ' ')"
-
- assertEquals "$result" 'TEST: unmatched character (") found [1"22"333"4444] ' "$result"
-}
-
-quote_shell_args_test_022() { # UnitTest
- local num=022
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1 |tr '\n' ' ')"
-
- assertEquals "$result" "TEST: unmatched character (') found [1'22'333'4444] " "$result"
-}
-
-quote_shell_args_test_023() { # UnitTest
- local num=023
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1 |tr '\n' ' ')"
-
- assertEquals "$result" 'TEST: unmatched character (\") found ["\] ' "$result"
-}
-
-quote_shell_args_test_024() { # UnitTest
- local num=024
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_025() { # UnitTest
- local num=025
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_026() { # UnitTest
- local num=026
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
-
-quote_shell_args_test_027() { # UnitTest
- local num=027
-
- . ../shell-error
- . ../shell-quote
-
- local input="$(cat ./data/$num-quote_shell_args-pattern)"
- local expect="$(cat ./data/$num-quote_shell_args-result)"
- local result="$(quote_process "$input" 2>&1)"
-
- assertEquals "$result" "$expect" "$result"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-quote_shell_variable_test1() { # UnitTest
- . ../shell-quote
- local string='`true`' expect='\`true\`'
- local result
- quote_shell_variable result "$string"
- assertEquals "$string" "$result" "$expect"
-}
-
-quote_shell_variable_test2() { # UnitTest
- . ../shell-quote
- local string='$(true)' expect='\$(true)'
- local result
- quote_shell_variable result "$string"
- assertEquals "$string" "$result" "$expect"
-}
-
-quote_shell_variable_test3() { # UnitTest
- . ../shell-quote
- local string='\`true\`; echo zzz' expect='\\\`true\\\`; echo zzz'
- local result
- quote_shell_variable result "$string"
- assertEquals "$string" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/sh -efu
-
-srcdir="$(readlink -ev ..)"
-export PATH="$srcdir:$PATH"
-
-. ../shell-unittest
-
-WORKDIR=
-setUpTests() {
- WORKDIR="$(mktemp -d "$PROG.XXXXXXXXX")"
-}
-
-tearDownTests() {
- rm -rf -- "$WORKDIR"
-}
-
-for s in \
- quote_sed_regexp quote_shell string_quote_remove \
- opt_check_dir opt_check_number opt_check_read \
- quote_sed_regexp_variable quote_shell_variable \
- getopt signal \
- fatal message verbose \
- quote_shell_args \
- ini_config_get ini_config_set \
- shell_var_unquote shell_var_trim \
- fill_mask \
- cmdline_get \
- ;
-do
- . "./$s"
- registerTests "./$s"
-done
-
-runUnitTests
+++ /dev/null
-#!/bin/sh
-
-shell_var_trim_test1() { # UnitTest
- . ../shell-var
-
- local result string='test'
- shell_var_trim result "$string"
- assertEquals "$string" "$result" 'test'
-}
-
-shell_var_trim_test2() { # UnitTest
- . ../shell-var
-
- local result string='test '
- shell_var_trim result "$string"
- assertEquals "$string" "$result" 'test'
-}
-
-shell_var_trim_test3() { # UnitTest
- . ../shell-var
-
- local result string='test
- '
- shell_var_trim result "$string"
- assertEquals "$string" "$result" 'test'
-}
-
-shell_var_trim_test4() { # UnitTest
- . ../shell-var
-
- local result string=' test test
- '
- shell_var_trim result "$string"
- assertEquals "$string" "$result" 'test test'
-}
-
-shell_var_trim_test5() { # UnitTest
- . ../shell-var
-
- local result string=' " test " '
- shell_var_trim result "$string"
- assertEquals "$string" "$result" '" test "'
-}
+++ /dev/null
-#!/bin/sh
-
-shell_var_unquote_test1() { # UnitTest
- . ../shell-var
-
- local result string='"test passed"'
- shell_var_unquote result "$string"
- assertEquals "$string" "$result" 'test passed'
-}
-
-shell_var_unquote_test2() { # UnitTest
- . ../shell-var
-
- local result string="'test passed'"
- shell_var_unquote result "$string"
- assertEquals "$string" "$result" 'test passed'
-}
-
-shell_var_unquote_test3() { # UnitTest
- . ../shell-var
-
- local result string="'test passed\""
- shell_var_unquote result "$string"
- assertEquals "$string" "$result" "'test passed\""
-}
-
-shell_var_unquote_test4() { # UnitTest
- . ../shell-var
-
- local result string="test ' passed"
- shell_var_unquote result "$string"
- assertEquals "$string" "$result" "test ' passed"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-PROG='TEST'
-__libshell_experimental=1
-
-signal_test_handler() {
- printf '%s\n' "$PROG: signal_test_handler() called"
-}
-
-signal_test1() { # UnitTest
- expect="EXIT-0"
- result=$(./signal-data/001-signal)
- assertEquals "$result" "$result" "$expect"
-}
-
-signal_test2() { # UnitTest
- expect="INT-2"
- result=$(./signal-data/002-signal)
- assertEquals "$result" "$result" "$expect"
-}
-
-signal_test3() { # UnitTest
- expect="EXIT-0
-EXIT-0"
- result=$(./signal-data/003-signal)
- assertEquals "$result" "$result" "$expect"
-}
-
-signal_test4() { # UnitTest
- expect="BAR1
-BAR2"
- result=$(./signal-data/004-signal)
- assertEquals "$result" "$result" "$expect"
-}
-
-signal_test5() { # UnitTest
- expect="EXIT-5"
- result=$(./signal-data/005-signal) ||:
- assertEquals "$result" "$result" "$expect"
-}
-
-signal_test6() { # UnitTest
- expect="Got 5"
- result=$(./signal-data/006-signal) ||:
- assertEquals "$result" "$result" "$expect"
-}
-
-signal_test7() { # UnitTest
- expect=""
- result=$(./signal-data/007-signal) ||:
- assertEquals "$result" "$result" "$expect"
-}
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-signal_handler 'echo EXIT-$?' EXIT HUP;
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-signal_handler 'echo INT-2' INT
-/bin/kill -INT $$
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-signal_handler 'echo EXIT-$?' TERM EXIT HUP;
-signal_handler 'echo EXIT-$?' TERM EXIT HUP;
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-signal_handler 'echo FOO1' USR2;
-signal_handler 'echo FOO2' USR2;
-signal_handler 'echo BAR1' USR1;
-signal_handler 'echo BAR2' USR1;
-signal_handler 'echo BAZ1' TERM;
-signal_handler 'echo BAZ2' TERM;
-/bin/kill -USR1 $$
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-signal_handler 'echo EXIT-$?' EXIT;
-exit 5
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-
-myhand() {
- echo "Got $1"
-}
-
-set_cleanup_handler myhand;
-exit 5
-
+++ /dev/null
-#!/bin/sh -efu
-. ../shell-signal
-
-myhand() {
- echo "Got $1"
-}
-
-set_cleanup_handler myhand;
-unset_cleanup_handler;
-exit 5
-
+++ /dev/null
-#!/bin/sh
-
-string_quote_remove_test1() { # UnitTest
- . ../shell-quote
-
- local string='"test passed"'
- local result="$(string_quote_remove "$string")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-string_quote_remove_test2() { # UnitTest
- . ../shell-quote
-
- local string="'test passed'"
- local result="$(string_quote_remove "$string")"
- assertEquals "$string" "$result" 'test passed'
-}
-
-string_quote_remove_test3() { # UnitTest
- . ../shell-quote
-
- local string="'test passed\""
- local result="$(string_quote_remove "$string")"
- assertEquals "$string" "$result" "'test passed\""
-}
-
-string_quote_remove_test4() { # UnitTest
- . ../shell-quote
-
- local string="test ' passed"
- local result="$(string_quote_remove "$string")"
- assertEquals "$string" "$result" "test ' passed"
-}
+++ /dev/null
-#!/bin/ash -efu
-
-PROG='TEST'
-
-verbose_test1() { # UnitTest
- . ../shell-error
- verbose=1
- expect="$PROG: message message;"
- result=`verbose "message message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}
-
-verbose_test2() { # UnitTest
- . ../shell-error
- verbose=
- expect=
- result=`verbose "message message" 2>&1 |tr '\n' ';'`
- assertEquals "$result" "$result" "$expect"
-}