Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nurlan
eepm
Commits
d4208c6b
Commit
d4208c6b
authored
Jun 30, 2022
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update packed
parent
e5d53dbd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
923 deletions
+8
-923
epm.sh
packed/epm.sh
+5
-0
serv.sh
packed/serv.sh
+3
-923
No files found.
packed/epm.sh
View file @
d4208c6b
...
...
@@ -10738,6 +10738,9 @@ fi
################# end of incorporated bin/tools_json #################
epm_main
()
{
#PATH=$PATH:/sbin:/usr/sbin
set_pm_type
...
...
@@ -11253,3 +11256,5 @@ esac
# Run helper for command with natural args
eval
epm_
$epm_cmd
$quoted_args
# return last error code (from subroutine)
}
epm_main
"
$@
"
packed/serv.sh
View file @
d4208c6b
...
...
@@ -2140,930 +2140,8 @@ esac
################# end of incorporated bin/distr_info #################
################# incorporate bin/tools_eget #################
internal_tools_eget
()
serv_main
()
{
# eget - simply shell on wget for loading directories over http (wget does not support wildcard for http)
# Use:
# eget http://ftp.altlinux.ru/pub/security/ssl/*
#
# Copyright (C) 2014-2014, 2016, 2020, 2022 Etersoft
# Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016-2017, 2020, 2022 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
fatal
()
{
echo
"FATAL:
$*
"
>
&2
exit
1
}
# TODO:
arch
=
"
$(
uname
-m
)
"
# copied from eepm project
# copied from /etc/init.d/outformat (ALT Linux)
isatty
()
{
# Set a sane TERM required for tput
[
-n
"
$TERM
"
]
||
TERM
=
dumb
export
TERM
test
-t
1
}
isatty2
()
{
# check stderr
test
-t
2
}
check_tty
()
{
isatty
||
return
which tput
>
/dev/null 2>/dev/null
||
return
# FreeBSD does not support tput -S
echo
| tput
-S
>
/dev/null 2>/dev/null
||
return
[
-z
"
$USETTY
"
]
||
return
export
USETTY
=
1
}
:
${
BLACK
:
=0
}
${
RED
:
=1
}
${
GREEN
:
=2
}
${
YELLOW
:
=3
}
${
BLUE
:
=4
}
${
MAGENTA
:
=5
}
${
CYAN
:
=6
}
${
WHITE
:
=7
}
set_boldcolor
()
{
[
"
$USETTY
"
=
"1"
]
||
return
{
echo
bold
echo
setaf
$1
}
|tput
-S
}
restore_color
()
{
[
"
$USETTY
"
=
"1"
]
||
return
{
echo
op
;
# set Original color Pair.
echo
sgr0
;
# turn off all special graphics mode (bold in our case).
}
|tput
-S
}
echover
()
{
[
-n
"
$verbose
"
]
||
return
echo
"
$*
"
>
&2
}
# Print command line and run command line
showcmd
()
{
if
[
-z
"
$quiet
"
]
;
then
set_boldcolor
$GREEN
local
PROMTSIG
=
"
\$
"
[
"
$UID
"
=
0
]
&&
PROMTSIG
=
"#"
echo
"
$PROMTSIG
$@
"
restore_color
fi
>
&2
}
# Print command line and run command line
docmd
()
{
showcmd
"
$@
"
"
$@
"
}
check_tty
WGETNOSSLCHECK
=
''
CURLNOSSLCHECK
=
''
WGETUSERAGENT
=
''
CURLUSERAGENT
=
''
WGETQ
=
''
#-q
CURLQ
=
''
#-s
WGETNAMEOPTIONS
=
'--content-disposition'
CURLNAMEOPTIONS
=
'--remote-name --remote-header-name'
set_quiet
()
{
WGETQ
=
'-q'
CURLQ
=
'-s'
}
# TODO: parse options in a good way
# TODO: passthrou all wget options
if
[
"
$1
"
=
"-q"
]
;
then
set_quiet
shift
fi
if
[
"
$1
"
=
"-k"
]
||
[
"
$1
"
=
"--no-check-certificate"
]
;
then
WGETNOSSLCHECK
=
'--no-check-certificate'
CURLNOSSLCHECK
=
'-k'
shift
fi
if
[
"
$1
"
=
"-U"
]
||
[
"
$1
"
=
"-A"
]
||
[
"
$1
"
=
"--user-agent"
]
;
then
user_agent
=
"Mozilla/5.0 (X11; Linux
$arch
)"
WGETUSERAGENT
=
"-U '
$user_agent
'"
CURLUSERAGENT
=
"-A '
$user_agent
'"
shift
fi
WGET
=
"
$(
which wget 2>/dev/null
)
"
if
[
-n
"
$WGET
"
]
;
then
__wget
()
{
if
[
-n
"
$WGETUSERAGENT
"
]
;
then
docmd
$WGET
$WGETQ
$WGETNOSSLCHECK
"
$WGETUSERAGENT
"
"
$@
"
else
docmd
$WGET
$WGETQ
$WGETNOSSLCHECK
"
$@
"
fi
}
# put remote content to stdout
scat
()
{
__wget
-O-
"
$1
"
}
# download to default name of to $2
sget
()
{
if
[
"
$2
"
=
"/dev/stdout"
]
||
[
"
$2
"
=
"-"
]
;
then
scat
"
$1
"
elif
[
-n
"
$2
"
]
;
then
docmd __wget
-O
"
$2
"
"
$1
"
else
# TODO: поддержка rsync для известных хостов?
# Не качать, если одинаковый размер и дата
# -nc
# TODO: overwrite always
docmd __wget
$WGETNAMEOPTIONS
"
$1
"
fi
}
else
CURL
=
"
$(
which curl 2>/dev/null
)
"
[
-n
"
$CURL
"
]
||
fatal
"There are no wget nor curl in the system. Install it with
$
epm install curl"
__curl
()
{
if
[
-n
"
$CURLUSERAGENT
"
]
;
then
docmd
$CURL
-L
$CURLQ
"
$CURLUSERAGENT
"
$CURLNOSSLCHECK
"
$@
"
else
docmd
$CURL
-L
$CURLQ
$CURLNOSSLCHECK
"
$@
"
fi
}
# put remote content to stdout
scat
()
{
__curl
"
$1
"
}
# download to default name of to $2
sget
()
{
if
[
"
$2
"
=
"/dev/stdout"
]
||
[
"
$2
"
=
"-"
]
;
then
scat
"
$1
"
elif
[
-n
"
$2
"
]
;
then
__curl
--output
"
$2
"
"
$1
"
else
__curl
$CURLNAMEOPTIONS
"
$1
"
fi
}
fi
LISTONLY
=
''
if
[
"
$1
"
=
"--list"
]
;
then
LISTONLY
=
"
$1
"
set_quiet
shift
fi
LATEST
=
''
if
[
"
$1
"
=
"--latest"
]
;
then
LATEST
=
"
$1
"
shift
fi
fatal
()
{
echo
"
$*
"
>
&2
exit
1
}
# check man glob
filter_glob
()
{
[
-z
"
$1
"
]
&&
cat
&&
return
# translate glob to regexp
grep
"
$(
echo
"
$1
"
|
sed
-e
"s|
\*
|.*|g"
-e
"s|?|.|g"
)
$"
}
filter_order
()
{
[
-z
"
$LATEST
"
]
&&
cat
&&
return
sort
-V
|
tail
-n1
}
# download to this file
TARGETFILE
=
''
if
[
"
$1
"
=
"-O"
]
;
then
TARGETFILE
=
"
$2
"
shift
2
elif
[
"
$1
"
=
"-O-"
]
;
then
TARGETFILE
=
"-"
shift
1
fi
# TODO:
# -P support
if
[
-z
"
$1
"
]
;
then
echo
"eget - wget like downloader wrapper with wildcard support"
>
&2
fatal
"Run
$0
--help to get help"
fi
if
[
"
$1
"
=
"-h"
]
||
[
"
$1
"
=
"--help"
]
;
then
echo
"eget - wget like downloader wrapper with wildcard support in filename part of URL"
echo
"Usage: eget [-q] [-k] [-U] [-O target file] [--list] http://somesite.ru/dir/na*.log"
echo
echo
"Options:"
echo
" -q - quiet mode"
echo
" -k|--no-check-certificate - skip SSL certificate chain support"
echo
" -U|-A|--user-agent - send browser like UserAgent"
echo
" -O file - download to this file (use filename from server if missed)"
echo
" --list - print files from url with mask"
echo
" --latest - print only latest version of a file"
echo
echo
"eget supports --list and download for https://github.com/owner/project urls"
echo
echo
"Examples:"
echo
"
$
eget --list http://ftp.somesite.ru/package-*.tar"
echo
"
$
eget http://ftp.somesite.ru/package-*.x64.tar"
echo
"
$
eget --list http://download.somesite.ru 'package-*.tar.xz'"
echo
"
$
eget --list --latest https://github.com/telegramdesktop/tdesktop/releases 'tsetup.*.tar.xz'"
# echo "See $ wget --help for wget options you can use here"
return
fi
get_github_urls
()
{
# https://github.com/OWNER/PROJECT
local
owner
=
"
$(
echo
"
$1
"
|
sed
-e
"s|^https://github.com/||"
-e
"s|/.*||"
)
"
#"
local
project
=
"
$(
echo
"
$1
"
|
sed
-e
"s|^https://github.com/
$owner
/||"
-e
"s|/.*||"
)
"
#"
[
-n
"
$owner
"
]
||
fatal
"Can't get owner from
$1
"
[
-n
"
$project
"
]
||
fatal
"Can't get project from
$1
"
local
URL
=
"https://api.github.com/repos/
$owner
/
$project
/releases"
scat
$URL
|
\
grep
-i
-o
-E
'"browser_download_url": "https://.*"'
|
cut
-d
'"'
-f4
}
if
echo
"
$1
"
|
grep
-q
"^https://github.com/"
&&
\
echo
"
$1
"
|
grep
-q
-v
"/download/"
&&
[
-n
"
$2
"
]
;
then
MASK
=
"
$2
"
if
[
-n
"
$LISTONLY
"
]
;
then
get_github_urls
"
$1
"
| filter_glob
"
$MASK
"
| filter_order
return
fi
for
fn
in
$(
get_github_urls
"
$1
"
| filter_glob
"
$MASK
"
| filter_order
)
;
do
sget
"
$fn
"
||
ERROR
=
1
done
return
fi
# do not support /
if
echo
"
$1
"
|
grep
-q
"/$"
&&
[
-z
"
$2
"
]
;
then
fatal
"Use http://example.com/e/* to download all files in dir"
fi
# TODO: curl?
# If ftp protocol, just download
if
echo
"
$1
"
|
grep
-q
"^ftp://"
;
then
[
-n
"
$LISTONLY
"
]
&&
fatal
"TODO: list files for ftp:// do not supported yet"
sget
"
$1
"
"
$TARGETFILE
"
return
fi
# mask allowed only in the last part of path
MASK
=
$(
basename
"
$1
"
)
# if mask are second arg
if
[
-n
"
$2
"
]
;
then
URL
=
"
$1
"
MASK
=
"
$2
"
else
# drop mask part
URL
=
"
$(
dirname
"
$1
"
)
"
fi
if
echo
"
$URL
"
|
grep
-q
"[*?]"
;
then
fatal
"Error: there are globbing symbols (*?) in
$URL
"
fi
# If have no wildcard symbol like asterisk, just download
if
echo
"
$MASK
"
|
grep
-qv
"[*?]"
||
echo
"
$MASK
"
|
grep
-q
"[?].*="
;
then
sget
"
$1
"
"
$TARGETFILE
"
return
fi
is_url
()
{
echo
"
$1
"
|
grep
-q
"://"
}
get_urls
()
{
# cat html, divide to lines by tags and cut off hrefs only
scat
$URL
|
sed
-e
's|<|<\n|g'
|
\
grep
-i
-o
-E
'href="(.+)"'
|
cut
-d
'"'
-f2
}
if
[
-n
"
$LISTONLY
"
]
;
then
for
fn
in
$(
get_urls | filter_glob
"
$MASK
"
| filter_order
)
;
do
is_url
"
$fn
"
&&
echo
$fn
&&
continue
fn
=
"
$(
echo
"
$fn
"
|
sed
-e
's|^./||'
-e
's|^/+||'
)
"
echo
"
$URL
/
$fn
"
done
return
fi
ERROR
=
0
for
fn
in
$(
get_urls | filter_glob
"
$MASK
"
| filter_order
)
;
do
is_url
"
$fn
"
||
fn
=
"
$URL
/
$(
basename
"
$fn
"
)
"
sget
"
$fn
"
||
ERROR
=
1
done
return
$ERROR
}
################# end of incorporated bin/tools_eget #################
################# incorporate bin/tools_estrlist #################
internal_tools_estrlist
()
{
#!/bin/bash
# 2009-2010, 2012, 2017, 2020 Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# TODO: rewrite with shell commands, perl or C
# Python - http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch16s03.html
# Shell - http://linux.byexamples.com/archives/127/uniq-and-basic-set-theory/
# - http://maiaco.com/articles/shellSetOperations.php
# Perl - http://docstore.mik.ua/orelly/perl/cookbook/ch04_09.htm
# - http://blogs.perl.org/users/polettix/2012/03/sets-operations.html
# http://rosettacode.org/wiki/Symmetric_difference
# TODO: add unit tests
# http://ru.wikipedia.org/wiki/Операции_над_множествами
# Base set operations:
# * union
# "1 2 3" "3 4 5" -> "1 2 3 4 5"
# * intersection
# "1 2 3" "3 4 5" -> "3"
# * relative complement (substracted, difference) ( A ? B – members in A but not in B )
# http://en.wikipedia.org/wiki/Complement_%28set_theory%29
# "1 3" "1 2 3 4" -> "2 4"
# * symmetric difference (симметричная разность) ( A ^ B – members in A or B but not both )
# http://en.wikipedia.org/wiki/Symmetric_difference
# "1 2 3" "3 4 5" -> "1 2 4 5"
fatal
()
{
echo
"FATAL:
$*
"
>
&2
exit
1
}
filter_strip_spaces
()
{
# possible use just
#xargs echo
sed
-e
"s|
\+
| |g"
-e
"s|^ ||"
-e
"s|
\$
||"
}
strip_spaces
()
{
echo
"
$*
"
| filter_strip_spaces
}
is_empty
()
{
[
"
$(
strip_spaces
"
$*
"
)
"
=
""
]
}
isempty
()
{
is_empty
"
$@
"
}
has_space
()
{
# not for dash:
# [ "$1" != "${1/ //}" ]
[
"
$(
echo
"
$*
"
|
sed
-e
"s| ||"
)
"
!=
"
$*
"
]
}
list
()
{
local
i
set
-f
for
i
in
$@
;
do
echo
"
$i
"
done
set
+f
}
count
()
{
set
-f
list
$@
|
wc
-l
set
+f
}
union
()
{
set
-f
strip_spaces
$(
list
$@
|
sort
-u
)
set
+f
}
intersection
()
{
local
RES
=
""
local
i j
for
i
in
$2
;
do
for
j
in
$1
;
do
[
"
$i
"
=
"
$j
"
]
&&
RES
=
"
$RES
$i
"
done
done
strip_spaces
"
$RES
"
}
uniq
()
{
union
$@
}
has
()
{
local
wd
=
"
$1
"
shift
echo
"
$*
"
|
grep
-q
--
"
$wd
"
}
# Note: used egrep! write '[0-9]+(first|two)', not '[0-9]\+...'
match
()
{
local
wd
=
"
$1
"
shift
echo
"
$*
"
|
grep
-E
-q
--
"
$wd
"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_remove
()
{
local
i
local
RES
=
set
-f
for
i
in
$2
;
do
echo
"
$i
"
|
grep
-q
"^
$1
$"
||
RES
=
"
$RES
$i
"
done
set
+f
strip_spaces
"
$RES
"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_wordremove
()
{
local
i
local
RES
=
""
set
-f
for
i
in
$2
;
do
echo
"
$i
"
|
grep
-q
-w
"
$1
"
||
RES
=
"
$RES
$i
"
done
set
+f
strip_spaces
"
$RES
"
}
reg_rqremove
()
{
local
i
local
RES
=
""
for
i
in
$2
;
do
[
"
$i
"
=
"
$1
"
]
||
RES
=
"
$RES
$i
"
done
strip_spaces
"
$RES
"
}
# Args: LIST1 LIST2
# do_exclude_list print LIST2 list exclude fields contains also in LIST1
# Example: exclude "1 3" "1 2 3 4" -> "2 4"
exclude
()
{
local
i
local
RES
=
"
$2
"
set
-f
for
i
in
$1
;
do
RES
=
"
$(
reg_rqremove
"
$i
"
"
$RES
"
)
"
done
set
+f
strip_spaces
"
$RES
"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_exclude
()
{
local
i
local
RES
=
"
$2
"
set
-f
for
i
in
$1
;
do
RES
=
"
$(
reg_remove
"
$i
"
"
$RES
"
)
"
done
set
+f
strip_spaces
"
$RES
"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_wordexclude
()
{
local
i
local
RES
=
"
$2
"
set
-f
for
i
in
$1
;
do
RES
=
$(
reg_wordremove
"
$i
"
"
$RES
"
)
done
set
+f
strip_spaces
"
$RES
"
}
if_contain
()
{
local
i
set
-f
for
i
in
$2
;
do
[
"
$i
"
=
"
$1
"
]
&&
return
done
set
+f
return
1
}
difference
()
{
local
RES
=
""
local
i
set
-f
for
i
in
$1
;
do
if_contain
$i
"
$2
"
||
RES
=
"
$RES
$i
"
done
for
i
in
$2
;
do
if_contain
$i
"
$1
"
||
RES
=
"
$RES
$i
"
done
set
+f
strip_spaces
"
$RES
"
}
# FIXME:
# reg_include "1." "11 12 21 22" -> "11 12"
reg_include
()
{
local
i
local
RES
=
""
set
-f
for
i
in
$2
;
do
echo
"
$i
"
|
grep
-q
-w
"
$1
"
&&
RES
=
"
$RES
$i
"
done
set
+f
strip_spaces
"
$RES
"
}
example
()
{
local
CMD
=
"
$1
"
local
ARG1
=
"
$2
"
shift
2
echo
"
\$
$0
$CMD
\"
$ARG1
\"
\"
$@
\"
"
$0
$CMD
"
$ARG1
"
"
$@
"
}
example_res
()
{
example
"
$@
"
&&
echo
TRUE
||
echo
FALSE
}
help
()
{
echo
"estrlist developed for string list operations. See also cut, join, paste..."
echo
"Usage:
$0
<command> [args]"
echo
"Commands:"
echo
" strip_spaces [args] - remove extra spaces"
# TODO: add filter
# echo " filter_strip_spaces - remove extra spaces from words from standart input"
# echo " reg_remove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep notation)"
# echo " reg_wordremove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep -w notation)"
echo
" exclude <list1> <list2> - print list2 items exclude list1 items"
echo
" reg_exclude <list PATTERN> [word list] - print only words that do not match PATTERN"
# echo " reg_wordexclude <list PATTERN> [word list] - print only words do not match PATTERN"
echo
" has <PATTERN> string - check the string for a match to the regular expression given in PATTERN (grep notation)"
echo
" match <PATTERN> string - check the string for a match to the regular expression given in PATTERN (egrep notation)"
echo
" isempty [string] (is_empty) - true if string has no any symbols (only zero or more spaces)"
echo
" has_space [string] - true if string has no spaces"
echo
" union [word list] - sort and remove duplicates"
echo
" intersection <list1> <list2> - print only intersected items (the same in both lists)"
echo
" difference <list1> <list2> - symmetric difference between lists items (not in both lists)"
echo
" uniq [word list] - alias for union"
echo
" list [word list] - just list words line by line"
echo
" count [word list] - print word count"
echo
echo
"Examples:"
# example reg_remove "1." "11 12 21 22"
# example reg_wordremove "1." "11 12 21 22"
example exclude
"1 3"
"1 2 3 4"
example reg_exclude
"22 1."
"11 12 21 22"
example reg_wordexclude
"wo.* er"
"work were more else"
example union
"1 2 2 3 3"
example count
"1 2 3 4 10"
example_res isempty
" "
#example_res isempty " 1 "
example_res has ex
"exactly"
example_res has exo
"exactly"
example_res match
"M[0-9]+"
"M250"
example_res match
"M[0-9]+"
"MI"
}
COMMAND
=
"
$1
"
if
[
-z
"
$COMMAND
"
]
;
then
echo
"Run with --help for get command description."
exit
1
fi
if
[
"
$COMMAND
"
=
"-h"
]
||
[
"
$COMMAND
"
=
"--help"
]
;
then
COMMAND
=
"help"
fi
#
case
"
$COMMAND
"
in
reg_remove|reg_wordremove
)
fatal
"obsoleted command
$COMMAND
"
;;
esac
shift
# FIXME: do to call function directly, use case instead?
if
[
"
$COMMAND
"
=
"--"
]
;
then
# ignore all options (-)
COMMAND
=
"
$1
"
shift
"
$COMMAND
"
"
$@
"
elif
[
"
$1
"
=
"-"
]
;
then
shift
"
$COMMAND
"
"
$(
cat
)
$@
"
elif
[
"
$2
"
=
"-"
]
;
then
"
$COMMAND
"
"
$1
"
"
$(
cat
)
"
else
"
$COMMAND
"
"
$@
"
fi
}
################# end of incorporated bin/tools_estrlist #################
################# incorporate bin/tools_json #################
internal_tools_json
()
{
# License: MIT or Apache
# Homepage: http://github.com/dominictarr/JSON.sh
throw
()
{
echo
"
$*
"
>
&2
exit
1
}
BRIEF
=
0
LEAFONLY
=
0
PRUNE
=
0
NO_HEAD
=
0
NORMALIZE_SOLIDUS
=
0
usage
()
{
echo
echo
"Usage: JSON.sh [-b] [-l] [-p] [-s] [-h]"
echo
echo
"-p - Prune empty. Exclude fields with empty values."
echo
"-l - Leaf only. Only show leaf nodes, which stops data duplication."
echo
"-b - Brief. Combines 'Leaf only' and 'Prune empty' options."
echo
"-n - No-head. Do not show nodes that have no path (lines that start with [])."
echo
"-s - Remove escaping of the solidus symbol (straight slash)."
echo
"-h - This help text."
echo
}
parse_options
()
{
set
--
"
$@
"
local
ARGN
=
$#
while
[
"
$ARGN
"
-ne
0
]
do
case
$1
in
-h
)
usage
exit
0
;;
-b
)
BRIEF
=
1
LEAFONLY
=
1
PRUNE
=
1
;;
-l
)
LEAFONLY
=
1
;;
-p
)
PRUNE
=
1
;;
-n
)
NO_HEAD
=
1
;;
-s
)
NORMALIZE_SOLIDUS
=
1
;;
?
*
)
echo
"ERROR: Unknown option."
usage
exit
0
;;
esac
shift
1
ARGN
=
$((
ARGN-1
))
done
}
# compatibility
awk_egrep
()
{
local
pattern_string
=
$1
a
=
''
gawk
'{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
print token;
$0=substr($0, start+RLENGTH);
}
}'
pattern
=
"
$pattern_string
"
}
tokenize
()
{
local
GREP
local
ESCAPE
local
CHAR
if
echo
"test string"
| egrep
-ao
--color
=
never
"test"
>
/dev/null 2>&1
then
GREP
=
'egrep -ao --color=never'
else
GREP
=
'egrep -ao'
fi
if
echo
"test string"
| egrep
-o
"test"
>
/dev/null 2>&1
then
ESCAPE
=
'(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR
=
'[^[:cntrl:]"\\]'
else
GREP
=
awk_egrep
ESCAPE
=
'(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR
=
'[^[:cntrl:]"\\\\]'
fi
local
STRING
=
"
\"
$CHAR
*(
$ESCAPE$CHAR
*)*
\"
"
local
NUMBER
=
'-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local
KEYWORD
=
'null|false|true'
local
SPACE
=
'[[:space:]]+'
# Force zsh to expand $A into multiple words
local
is_wordsplit_disabled
=
$(
unsetopt 2>/dev/null |
grep
-c
'^shwordsplit$'
)
if
[
$is_wordsplit_disabled
!=
0
]
;
then
setopt shwordsplit
;
fi
$GREP
"
$STRING
|
$NUMBER
|
$KEYWORD
|
$SPACE
|."
| egrep
-v
"^
$SPACE
$"
if
[
$is_wordsplit_disabled
!=
0
]
;
then
unsetopt shwordsplit
;
fi
}
parse_array
()
{
local
index
=
0
local
ary
=
''
read
-r
token
case
"
$token
"
in
']'
)
;;
*
)
while
:
do
parse_value
"
$1
"
"
$index
"
index
=
$((
index+1
))
ary
=
"
$ary
""
$value
"
read
-r
token
case
"
$token
"
in
']'
)
break
;;
','
)
ary
=
"
$ary
,"
;;
*
)
throw
"EXPECTED , or ] GOT
${
token
:-
EOF
}
"
;;
esac
read
-r
token
done
;;
esac
[
"
$BRIEF
"
-eq
0
]
&&
value
=
$(
printf
'[%s]'
"
$ary
"
)
||
value
=
:
}
parse_object
()
{
local
key
local
obj
=
''
read
-r
token
case
"
$token
"
in
'}'
)
;;
*
)
while
:
do
case
"
$token
"
in
'"'
*
'"'
)
key
=
$token
;;
*
)
throw
"EXPECTED string GOT
${
token
:-
EOF
}
"
;;
esac
read
-r
token
case
"
$token
"
in
':'
)
;;
*
)
throw
"EXPECTED : GOT
${
token
:-
EOF
}
"
;;
esac
read
-r
token
parse_value
"
$1
"
"
$key
"
obj
=
"
$obj$key
:
$value
"
read
-r
token
case
"
$token
"
in
'}'
)
break
;;
','
)
obj
=
"
$obj
,"
;;
*
)
throw
"EXPECTED , or } GOT
${
token
:-
EOF
}
"
;;
esac
read
-r
token
done
;;
esac
[
"
$BRIEF
"
-eq
0
]
&&
value
=
$(
printf
'{%s}'
"
$obj
"
)
||
value
=
:
}
parse_value
()
{
local
jpath
=
"
${
1
:+
$1
,
}
$2
"
isleaf
=
0
isempty
=
0
print
=
0
case
"
$token
"
in
'{'
)
parse_object
"
$jpath
"
;;
'['
)
parse_array
"
$jpath
"
;;
# At this point, the only valid single-character tokens are digits.
''
|
[!
0-9]
)
throw
"EXPECTED value GOT
${
token
:-
EOF
}
"
;;
*
)
value
=
$token
# if asked, replace solidus ("\/") in json strings with normalized value: "/"
[
"
$NORMALIZE_SOLIDUS
"
-eq
1
]
&&
value
=
$(
echo
"
$value
"
|
sed
's#\\/#/#g'
)
isleaf
=
1
[
"
$value
"
=
'""'
]
&&
isempty
=
1
;;
esac
[
"
$value
"
=
''
]
&&
return
[
"
$NO_HEAD
"
-eq
1
]
&&
[
-z
"
$jpath
"
]
&&
return
[
"
$LEAFONLY
"
-eq
0
]
&&
[
"
$PRUNE
"
-eq
0
]
&&
print
=
1
[
"
$LEAFONLY
"
-eq
1
]
&&
[
"
$isleaf
"
-eq
1
]
&&
[
$PRUNE
-eq
0
]
&&
print
=
1
[
"
$LEAFONLY
"
-eq
0
]
&&
[
"
$PRUNE
"
-eq
1
]
&&
[
"
$isempty
"
-eq
0
]
&&
print
=
1
[
"
$LEAFONLY
"
-eq
1
]
&&
[
"
$isleaf
"
-eq
1
]
&&
\
[
$PRUNE
-eq
1
]
&&
[
$isempty
-eq
0
]
&&
print
=
1
[
"
$print
"
-eq
1
]
&&
printf
"[%s]
\t
%s
\n
"
"
$jpath
"
"
$value
"
:
}
parse
()
{
read
-r
token
parse_value
read
-r
token
case
"
$token
"
in
''
)
;;
*
)
throw
"EXPECTED EOF GOT
$token
"
;;
esac
}
if
([
"
$0
"
=
"
$BASH_SOURCE
"
]
||
!
[
-n
"
$BASH_SOURCE
"
])
;
then
parse_options
"
$@
"
tokenize | parse
fi
# vi: expandtab sw=2 ts=2
}
################# end of incorporated bin/tools_json #################
INITDIR
=
/etc/init.d
...
...
@@ -3329,3 +2407,5 @@ fi
# Run helper for command
serv_
$serv_cmd
$service_name
$params
# return last error code (from subroutine)
}
serv_main
"
$@
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment