Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
evz
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
Тимофей Смирнов
evz
Commits
c8c8a6dc
Commit
c8c8a6dc
authored
Nov 17, 2017
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sh-functions
parent
0033219f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
206 additions
and
4 deletions
+206
-4
evz
bin/evz
+10
-4
evz-sh-functions
bin/evz-sh-functions
+196
-0
No files found.
bin/evz
View file @
c8c8a6dc
...
@@ -20,13 +20,19 @@
...
@@ -20,13 +20,19 @@
PROGDIR
=
$(
dirname
$0
)
PROGDIR
=
$(
dirname
$0
)
[
"
$PROGDIR
"
=
"."
]
&&
PROGDIR
=
$(
pwd
)
[
"
$PROGDIR
"
=
"."
]
&&
PROGDIR
=
$(
pwd
)
fatal
()
# will replaced to /usr/share/evz during install
SHAREDIR
=
$PROGDIR
load_helper
()
{
{
echo
"
$*
"
>
&2
local
CMD
=
"
$SHAREDIR
/
$1
"
exit
1
[
-r
"
$CMD
"
]
||
{
echo
"Have no
$CMD
helper file"
>
&2
;
exit
1
;
}
.
$CMD
}
}
info
()
load_helper evz-sh-functions
check_tty
{
{
echo
"
$*
"
echo
"
$*
"
}
}
...
...
bin/evz-sh-functions
0 → 100644
View file @
c8c8a6dc
#!/bin/bash
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 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/>.
#
# 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
}
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
"
$@
"
"
$@
"
}
# Run every arg with docmd
docmd_foreach
()
{
local
cmd
cmd
=
"
$1
"
#showcmd "$@"
shift
for
pkg
in
"
$@
"
;
do
docmd
$cmd
$pkg
done
}
# Print command line and run command line with SUDO
sudocmd
()
{
showcmd
"
$SUDO
$@
"
$SUDO
"
$@
"
}
# Run every arg with sudocmd
sudocmd_foreach
()
{
local
cmd
cmd
=
"
$1
"
#showcmd "$@"
shift
for
pkg
in
"
$@
"
;
do
sudocmd
$cmd
$pkg
done
}
filter_strip_spaces
()
{
# possible use just
#xargs echo
sed
-e
"s|
\+
| |g"
|
\
sed
-e
"s|^ ||"
|
sed
-e
"s|
\$
||"
}
strip_spaces
()
{
echo
"
$*
"
| filter_strip_spaces
}
# param true false
subst_option
()
{
eval
"[ -n
\"\$
$1
\"
]"
&&
echo
"
$2
"
||
echo
"
$3
"
}
store_output
()
{
# use make_temp_file from etersoft-build-utils
RC_STDOUT
=
$(
mktemp
)
#RC_STDERR=$(mktemp)
"
$@
"
2>&1 |
tee
$RC_STDOUT
# http://tldp.org/LDP/abs/html/bashver3.html#PIPEFAILREF
return
$PIPESTATUS
}
clean_store_output
()
{
rm
-f
$RC_STDOUT
}
# Print error message and stop the program
fatal
()
{
if
[
-z
"
$TEXTDOMAIN
"
]
;
then
echo
"Error:
$@
"
>
&2
# else
# echog "Error in $0: $@" >&2
fi
exit
1
}
# Print warning message
warning
()
{
if
[
-z
"
$TEXTDOMAIN
"
]
;
then
echo
"Warning:
$@
"
>
&2
# else
# echog "Error in $0: $@" >&2
fi
}
info
()
{
[
-n
"
$quiet
"
]
&&
return
# print message to stderr if stderr forwarded to (a file)
if
isatty2
;
then
isatty
||
return
0
echo
"
$*
"
else
echo
"
$*
"
>
&2
fi
}
# print options description from HELPCMD/HELPOPT lines in the code
get_help
()
{
grep
-v
--
"^#"
$0
|
grep
--
"#
$1
"
|
while
read
n
;
do
opt
=
$(
echo
$n
|
sed
-e
"s|) #
$1
:.*||g"
)
desc
=
$(
echo
$n
|
sed
-e
"s|.*) #
$1
:||g"
)
printf
" %-20s %s
\n
"
$opt
"
$desc
"
done
}
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