maj des inclusions
This commit is contained in:
parent
f573fe6824
commit
c6a529b6ff
372
ucrontab
372
ucrontab
|
@ -94,14 +94,16 @@ DEFAULT_GDELAY=15
|
|||
##@inc[base
|
||||
## Fonctions de base
|
||||
|
||||
if [ "$0" == "-bash" ]; then
|
||||
if [ -n "$UTOOLS_HAVE_SCRIPTVARS" ]; then
|
||||
:
|
||||
elif [ "$0" == "-bash" ]; then
|
||||
scriptname=
|
||||
scriptdir=
|
||||
script=
|
||||
else
|
||||
scriptname=`basename -- "$0"`
|
||||
scriptdir=`dirname -- "$0"`
|
||||
scriptdir=`cd "$scriptdir"; pwd`
|
||||
scriptname="$(basename -- "$0")"
|
||||
scriptdir="$(dirname -- "$0")"
|
||||
scriptdir="$(cd "$scriptdir"; pwd)"
|
||||
script="$scriptdir/$scriptname"
|
||||
fi
|
||||
: "${ULIBDIR:=$scriptdir}"
|
||||
|
@ -845,6 +847,40 @@ function relpath() {
|
|||
echo "${rp%//}"
|
||||
fi
|
||||
}
|
||||
function withinpath() {
|
||||
local b="$1" p="$2" strict="${3:-N}"
|
||||
b="$(abspath "$b")"
|
||||
p="$(abspath "$p")"
|
||||
if is_yes "$strict"; then
|
||||
[ "${p#$b/}" != "$p" ]
|
||||
else
|
||||
[ "$p" == "$b" -o "${p#$b/}" != "$p" ]
|
||||
fi
|
||||
}
|
||||
function safe_abspath() {
|
||||
local p="$1" ba="$2" br="$3"
|
||||
if [ -n "$ba" ]; then
|
||||
ba="$(abspath "$ba")"
|
||||
else
|
||||
ba="$(pwd)"
|
||||
fi
|
||||
[ -n "$br" ] || br="$ba"
|
||||
br="$(abspath "$br" "$ba")"
|
||||
p="$(abspath "$p" "$ba")"
|
||||
if [ "$p" == "$br" -o "${p#$br/}" != "$p" ]; then
|
||||
echo "$p"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
function safe_relpath() {
|
||||
local p
|
||||
if p="$(safe_abspath "$1" "$2" "$3")"; then
|
||||
relpath "$p" "$2" "$(pwd)"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
function splitwcs() {
|
||||
local __sw_p="$1"
|
||||
local __sw_dd="${2:-basedir}" __sw_df="${3:-filespec}" __sw_part __sw_d __sw_f
|
||||
|
@ -1216,6 +1252,18 @@ function array_lsdirs() {
|
|||
function array_lsfiles() {
|
||||
__array_ls files "$@"
|
||||
}
|
||||
function filter_vcspath() {
|
||||
sed '
|
||||
/^.git$/d
|
||||
/^.git\//d
|
||||
/\/.git$/d
|
||||
/\/.git\//d
|
||||
/^.svn$/d
|
||||
/^.svn\//d
|
||||
/\/.svn$/d
|
||||
/\/.svn\//d
|
||||
'
|
||||
}
|
||||
function merge_contlines() {
|
||||
awk 'substr($0, length($0)) == "\\" {
|
||||
while (getline nextline) {
|
||||
|
@ -1264,7 +1312,11 @@ function extract_archive() {
|
|||
elif endswith "$arch" .tar; then
|
||||
tar xf "$arch" -C "$destdir" "$@" || return
|
||||
elif endswith "$arch" .jar || endswith "$arch" .war || endswith "$arch" .ear; then
|
||||
jar xf "$arch" -C "$destdir" "$@" || return
|
||||
(
|
||||
arch="$(abspath "$arch")"
|
||||
cd "$destdir"
|
||||
jar xf "$arch" "$@"
|
||||
) || return
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
@ -1274,9 +1326,9 @@ function get_archive_basename() {
|
|||
basename="${basename%.zip}"
|
||||
basename="${basename%.tgz}"
|
||||
basename="${basename%.tbz2}"
|
||||
basename="${basename%.tar}"
|
||||
basename="${basename%.gz}"
|
||||
basename="${basename%.bz2}"
|
||||
basename="${basename%.tar}"
|
||||
basename="${basename%.jar}"
|
||||
basename="${basename%.war}"
|
||||
basename="${basename%.ear}"
|
||||
|
@ -1287,9 +1339,9 @@ function get_archive_appname() {
|
|||
appname="${appname%.zip}"
|
||||
appname="${appname%.tgz}"
|
||||
appname="${appname%.tbz2}"
|
||||
appname="${appname%.tar}"
|
||||
appname="${appname%.gz}"
|
||||
appname="${appname%.bz2}"
|
||||
appname="${appname%.tar}"
|
||||
appname="${appname%.jar}"
|
||||
appname="${appname%.war}"
|
||||
appname="${appname%.ear}"
|
||||
|
@ -1310,6 +1362,8 @@ function get_archive_version() {
|
|||
print vs["1"]
|
||||
} else if (match($0, /([0-9]+([-_.][0-9]+)*([a-zA-Z][0-9]*|[-_.][0-9]+[a-zA-Z][0-9]*)?)$/, vs)) {
|
||||
print vs["1"]
|
||||
} else if (match($0, /([0-9]+[a-z][a-z][a-z]?)$/, vs)) {
|
||||
print vs["1"]
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
@ -1383,6 +1437,107 @@ function run_as() {
|
|||
function run_as_root() {
|
||||
is_root || run_as root "$@"
|
||||
}
|
||||
function check_user() {
|
||||
local user
|
||||
for user in "$@"; do
|
||||
[ "$USER" == "$user" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function ensure_user() {
|
||||
local -a users
|
||||
while [ $# -gt 0 -a "$1" != "--" ]; do
|
||||
array_add users "$1"
|
||||
shift
|
||||
done
|
||||
[ "$1" == "--" ] && shift
|
||||
|
||||
if ! check_user "${users[@]}"; then
|
||||
if [ ${#users[*]} -gt 1 ]; then
|
||||
ewarn "Cette commande doit être lancée avec l'un des users ${users[*]}"
|
||||
else
|
||||
ewarn "Cette commande doit être lancée avec le user ${users[0]}"
|
||||
fi
|
||||
if ask_yesno "Voulez-vous tenter de relancer la commande avec le bon user?" O; then
|
||||
estep "Lancement du script avec le user ${users[0]}"
|
||||
run_as "${users[0]}" "$@"
|
||||
return 1
|
||||
elif is_root; then
|
||||
return 11
|
||||
else
|
||||
return 10
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
function check_hostname() {
|
||||
local userhost user host path
|
||||
for userhost in "$@"; do
|
||||
splitfsep "$userhost" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
[ "$MYHOSTNAME" == "${host%%.*}" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function check_userhostname() {
|
||||
local userhost path user host
|
||||
for userhost in "$@"; do
|
||||
if check_hostname "$userhost"; then
|
||||
[[ "$userhost" == *@* ]] || return 0
|
||||
splitfsep "$userhost" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
check_user "$user" && return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
UTOOLS_ENSURE_HOSTNAME_SSH_OPTS=()
|
||||
function ensure_hostname() {
|
||||
local -a userhosts
|
||||
while [ $# -gt 0 -a "$1" != "--" ]; do
|
||||
array_add userhosts "$1"
|
||||
shift
|
||||
done
|
||||
[ "$1" == "--" ] && shift
|
||||
|
||||
local userhost user host path
|
||||
if ! check_hostname "${userhosts[@]}"; then
|
||||
if [ ${#userhosts[*]} -gt 1 ]; then
|
||||
ewarn "Cette commande n'est valide que sur l'un des hôtes ${userhosts[*]}"
|
||||
else
|
||||
ewarn "Cette commande n'est valide que sur l'hôte ${userhosts[0]}"
|
||||
fi
|
||||
|
||||
enote "Vous pouvez tenter de relancer le script sur ${userhosts[0]}, mais cela requière que ce script ET les données dont il a besoin soient installés dans la même version et dans le même répertoire sur l'hôte distant"
|
||||
if ask_yesno "Voulez-vous tenter de relancer le script sur l'hôte distant?" N; then
|
||||
splitfsep "${userhosts[0]}" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
[ -n "$user" ] || user=root
|
||||
|
||||
estep "Lancement de la commande sur l'hôte distant $user@$host"
|
||||
local cmd
|
||||
[ -n "$path" ] && cmd="$(quoted_args cd "$path"); "
|
||||
cmd="$cmd$(quoted_args "$script" "$@")"
|
||||
ssh -qt "${UTOOLS_ENSURE_HOSTNAME_SSH_OPTS[@]}" "$user@$host" "$cmd"
|
||||
[ $? -eq 255 ] && return 12
|
||||
return 1
|
||||
else
|
||||
return 11
|
||||
fi
|
||||
fi
|
||||
local userhost user host
|
||||
for userhost in "${userhosts[@]}"; do
|
||||
[[ "$userhost" == *@* ]] || continue
|
||||
if check_hostname "$userhost"; then
|
||||
splitfsep "$userhost" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
[ -n "$path" ] && cd "$path"
|
||||
ensure_user "$user" -- "$@"
|
||||
return $?
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
__AWKDEF_FUNCTIONS='
|
||||
function quote_html(s) {
|
||||
|
@ -1602,26 +1757,47 @@ function merge_line(input, field, key, line) {
|
|||
line = find_line(input, field, $key)
|
||||
if (line != "") $0 = $0 FS line
|
||||
}
|
||||
function __csv_parse_quoted(line, destl, pos, tmpl, nextc, resl) {
|
||||
function __csv_parse_quoted(line, destl, colsep, qchar, echar, pos, tmpl, nextc, resl) {
|
||||
line = substr(line, 2)
|
||||
resl = ""
|
||||
while (1) {
|
||||
pos = index(line, "\"")
|
||||
pos = index(line, qchar)
|
||||
if (pos == 0) {
|
||||
resl = resl line
|
||||
destl[0] = ""
|
||||
destl[1] = 0
|
||||
return resl
|
||||
}
|
||||
if (echar != "" && pos > 1) {
|
||||
prevc = substr(line, pos - 1, 1)
|
||||
quotec = substr(line, pos, 1)
|
||||
nextc = substr(line, pos + 1, 1)
|
||||
if (prevc == echar) {
|
||||
tmpl = substr(line, 1, pos - 2)
|
||||
resl = resl tmpl quotec
|
||||
line = substr(line, pos + 1)
|
||||
continue
|
||||
}
|
||||
tmpl = substr(line, 1, pos - 1)
|
||||
if (nextc == colsep || nextc == "") {
|
||||
resl = resl tmpl
|
||||
destl[0] = substr(line, pos + 2)
|
||||
destl[1] = nextc == colsep
|
||||
return resl
|
||||
} else {
|
||||
resl = resl tmpl quotec
|
||||
line = substr(line, pos + 1)
|
||||
}
|
||||
} else {
|
||||
tmpl = substr(line, 1, pos - 1)
|
||||
quotec = substr(line, pos, 1)
|
||||
nextc = substr(line, pos + 1, 1)
|
||||
if (nextc == "," || nextc == "") {
|
||||
if (nextc == colsep || nextc == "") {
|
||||
resl = resl tmpl
|
||||
destl[0] = substr(line, pos + 2)
|
||||
destl[1] = nextc == ","
|
||||
destl[1] = nextc == colsep
|
||||
return resl
|
||||
} else if (nextc == "\"") {
|
||||
} else if (nextc == qchar) {
|
||||
resl = resl tmpl quotec
|
||||
line = substr(line, pos + 2)
|
||||
} else {
|
||||
|
@ -1629,9 +1805,10 @@ function __csv_parse_quoted(line, destl, pos, tmpl, nextc, resl) {
|
|||
line = substr(line, pos + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function __csv_parse_unquoted(line, destl, pos) {
|
||||
pos = index(line, ",")
|
||||
function __csv_parse_unquoted(line, destl, colsep, qchar, echar, pos) {
|
||||
pos = index(line, colsep)
|
||||
if (pos == 0) {
|
||||
destl[0] = ""
|
||||
destl[1] = 0
|
||||
|
@ -1642,18 +1819,18 @@ function __csv_parse_unquoted(line, destl, pos) {
|
|||
return substr(line, 1, pos - 1)
|
||||
}
|
||||
}
|
||||
function array_parsecsv(fields, line, nbfields, shouldparse, destl, i) {
|
||||
function __array_parsecsv(fields, line, nbfields, colsep, qchar, echar, shouldparse, destl, i) {
|
||||
array_new(fields)
|
||||
array_new(destl)
|
||||
i = 1
|
||||
shouldparse = 0
|
||||
while (shouldparse || line != "") {
|
||||
if (line ~ /^"/) {
|
||||
value = __csv_parse_quoted(line, destl)
|
||||
if (index(line, qchar) == 1) {
|
||||
value = __csv_parse_quoted(line, destl, colsep, qchar, echar)
|
||||
line = destl[0]
|
||||
shouldparse = destl[1]
|
||||
} else {
|
||||
value = __csv_parse_unquoted(line, destl)
|
||||
value = __csv_parse_unquoted(line, destl, colsep, qchar, echar)
|
||||
line = destl[0]
|
||||
shouldparse = destl[1]
|
||||
}
|
||||
|
@ -1667,6 +1844,20 @@ function array_parsecsv(fields, line, nbfields, shouldparse, destl, i) {
|
|||
}
|
||||
return length(fields)
|
||||
}
|
||||
BEGIN {
|
||||
DEFAULT_COLSEP = ","
|
||||
DEFAULT_QCHAR = "\""
|
||||
DEFAULT_ECHAR = ""
|
||||
}
|
||||
function array_parsecsv2(fields, line, nbfields, colsep, qchar, echar) {
|
||||
return __array_parsecsv(fields, line, nbfields, colsep, qchar, echar)
|
||||
}
|
||||
function array_parsecsv(fields, line, nbfields, colsep, qchar, echar) {
|
||||
if (colsep == "") colsep = DEFAULT_COLSEP
|
||||
if (qchar == "") qchar = DEFAULT_QCHAR
|
||||
if (echar == "") echar = DEFAULT_ECHAR
|
||||
return __array_parsecsv(fields, line, nbfields, colsep, qchar, echar)
|
||||
}
|
||||
function parsecsv(line, fields) {
|
||||
array_parsecsv(fields, line)
|
||||
array_getline(fields)
|
||||
|
@ -1685,18 +1876,18 @@ function __csv_should_quote(s) {
|
|||
if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1
|
||||
return 0
|
||||
}
|
||||
function array_formatcsv2(fields, asep, vsep, qsep, escape, count, indices, line, i, value) {
|
||||
function array_formatcsv2(fields, colsep, mvsep, qchar, echar, count, indices, line, i, value) {
|
||||
line = ""
|
||||
count = mkindices(fields, indices)
|
||||
for (i = 1; i <= count; i++) {
|
||||
value = fields[indices[i]]
|
||||
if (i > 1) line = line asep
|
||||
if (qsep != "" && index(value, qsep) != 0) {
|
||||
if (escape) gsub(qsep, quote_subrepl(escape) "&", value);
|
||||
else gsub(qsep, "&&", value);
|
||||
if (i > 1) line = line colsep
|
||||
if (qchar != "" && index(value, qchar) != 0) {
|
||||
if (echar != "") gsub(qchar, quote_subrepl(echar) "&", value);
|
||||
else gsub(qchar, "&&", value);
|
||||
}
|
||||
if (qsep != "" && (index(value, qsep) != 0 || index(value, asep) != 0 || __csv_should_quote(value))) {
|
||||
line = line qsep value qsep
|
||||
if (qchar != "" && (index(value, mvsep) != 0 || index(value, colsep) != 0 || __csv_should_quote(value))) {
|
||||
line = line qchar value qchar
|
||||
} else {
|
||||
line = line value
|
||||
}
|
||||
|
@ -2057,6 +2248,64 @@ function __po_process_options() {
|
|||
set_array "$destargs_" @ "$@"
|
||||
return 0
|
||||
}
|
||||
function __genparse_shortopt() {
|
||||
local LC_COLLATE=C
|
||||
local shortopt="${1//[^A-Z]}"
|
||||
shortopt="${shortopt:0:1}"
|
||||
shortopt="${shortopt,,}"
|
||||
[ -n "$shortopt" ] && echo "$shortopt"
|
||||
}
|
||||
function genparse() {
|
||||
|
||||
local -a descs vars options
|
||||
local desc var option name value shortopt
|
||||
|
||||
for var in "$@"; do
|
||||
if [[ "$var" == *=* ]]; then
|
||||
splitvar "$var" name value
|
||||
shortopt="$(__genparse_shortopt "$name")"
|
||||
option="${name,,}"
|
||||
name="${option//-/_}"
|
||||
array_add descs "${shortopt:+-$shortopt, }--$option VALUE"
|
||||
array_add vars "$(set_var_cmd "$name" "$value")"
|
||||
array_add options "${shortopt:+-$shortopt:,}--$option: $name="
|
||||
else
|
||||
name="$var"
|
||||
shortopt="$(__genparse_shortopt "$name")"
|
||||
option="${name,,}"
|
||||
name="${option//-/_}"
|
||||
array_add descs "${shortopt:+-$shortopt, }--$option"
|
||||
array_add vars "$name="
|
||||
array_add options "${shortopt:+-$shortopt,}--$option $name=1"
|
||||
fi
|
||||
done
|
||||
|
||||
echo -n 'function display_help() {
|
||||
uecho "\
|
||||
USAGE
|
||||
$scriptname'
|
||||
if [ -n "$descs" ]; then
|
||||
echo -n ' [options]
|
||||
|
||||
OPTIONS'
|
||||
for desc in "${descs[@]}"; do
|
||||
echo -n "
|
||||
$desc"
|
||||
done
|
||||
fi
|
||||
echo '"
|
||||
}
|
||||
'
|
||||
for var in "${vars[@]}"; do
|
||||
echo "$var"
|
||||
done
|
||||
echo 'parse_opts "${PRETTYOPTS[@]}" \'
|
||||
echo ' --help '\''$exit_with display_help'\'' \'
|
||||
for option in "${options[@]}"; do
|
||||
echo " $option \\"
|
||||
done
|
||||
echo ' @ args -- "$@" && set -- "${args[@]}" || die "$args"'
|
||||
}
|
||||
|
||||
function __lf_get_age() {
|
||||
local y=$(date "+%Y")
|
||||
|
@ -2773,13 +3022,14 @@ function simple_menu() {
|
|||
}
|
||||
|
||||
|
||||
__ac_files=()
|
||||
function __ac_forgetall() { __ac_files=(); }
|
||||
__ac_forgetall
|
||||
function __ac_trap() {
|
||||
local file
|
||||
for file in "${__ac_files[@]}"; do
|
||||
[ -e "$file" ] && rm -rf "$file" 2>/dev/null
|
||||
done
|
||||
__ac_files=()
|
||||
__ac_forgetall
|
||||
}
|
||||
trap __ac_trap 1 3 15 EXIT
|
||||
function autoclean() {
|
||||
|
@ -2836,6 +3086,13 @@ function ac_set_tmpdir() {
|
|||
set_var "$1" "$__acst_t"
|
||||
fi
|
||||
}
|
||||
function debug_tee() {
|
||||
if show_debug; then
|
||||
tee "$@"
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function get_defaults_files() {
|
||||
|
@ -2889,24 +3146,6 @@ if [ -n "$UTOOLS_CHROOT" ]; then
|
|||
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
|
||||
fi
|
||||
|
||||
function check_user() {
|
||||
local user
|
||||
for user in "$@"; do
|
||||
[ "$user" == "$USER" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function ensure_user() {
|
||||
check_user "$@" && return 0
|
||||
if [ $# -eq 1 ]; then
|
||||
eerror "Pour cette commande, il faut être l'utilisateur $1"
|
||||
else
|
||||
eerror "Pour cette commande, il faut être l'un des utilisateurs suivants: $*"
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [ -z "$ULIBDIR" -o "$ULIBDIR" != "$ULIBINIT" ]; then
|
||||
ULIBPROVIDED=()
|
||||
|
@ -3113,6 +3352,7 @@ function is_interaction() {
|
|||
-y|--automatic) [ -n "$__interaction" -a "$__interaction" -eq 1 ];;
|
||||
-c|--default) [ -n "$__interaction" -a "$__interaction" -eq 2 ];;
|
||||
-i|--interactive) [ -n "$__interaction" -a "$__interaction" -eq 3 ];;
|
||||
-C) [ -n "$__interaction" -a "$__interaction" -ge 2 ];;
|
||||
*) return 1;;
|
||||
esac
|
||||
}
|
||||
|
@ -3909,16 +4149,41 @@ BEGIN {
|
|||
refM = ctnow[1]; refH = ctnow[2]; refdom = ctnow[3]; refmon = ctnow[4]; refdow = ctnow[5]
|
||||
ctref = refM " " refH " " refdom " " refmon " " refdow
|
||||
print "##now: " ctref
|
||||
|
||||
match_ctline = 0
|
||||
match_indented = 0
|
||||
}
|
||||
|
||||
/^[a-zA-Z_][a-zA-Z0-9_]*=/ {
|
||||
/^(export[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[-+%#]=/ {
|
||||
match($0, /^(export[ \t]+)?([a-zA-Z_][a-zA-Z0-9_]*)([-+%#])=(.*)$/, parts)
|
||||
name = parts[2]
|
||||
type = parts[3]
|
||||
value = parts[4]
|
||||
if (type == "+" || type == "%") {
|
||||
print "uaddpath " value " " name
|
||||
} else if (type == "#") {
|
||||
print "uinspath " value " " name
|
||||
} else if (type == "-") {
|
||||
print "udelpath " value " " name
|
||||
}
|
||||
print "export " name
|
||||
next
|
||||
}
|
||||
/^(export[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*=/ {
|
||||
sub(/^export[ \t]+/, "", $0)
|
||||
print "export " $0
|
||||
next
|
||||
}
|
||||
/^[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ {
|
||||
/^\$.+/ {
|
||||
sub(/^\$/, "", $0)
|
||||
print
|
||||
next
|
||||
}
|
||||
/^[ \t]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ {
|
||||
M = $1; H = $2; dom = $3; mon = $4; dow = $5
|
||||
sub(/^[ ]*[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]*/, "", $0)
|
||||
|
||||
if (!match_ctline) match_indented = 0
|
||||
ctline = M " " H " " dom " " mon " " dow
|
||||
|
||||
gsub(/\*/, "0-59", M)
|
||||
|
@ -3938,6 +4203,19 @@ BEGIN {
|
|||
|
||||
if (Mok && Hok && monok && (domok || dowok)) {
|
||||
print "##matches: " ctline
|
||||
match_ctline = 1
|
||||
match_indented = 1
|
||||
}
|
||||
|
||||
if (match_ctline && $0 != "") {
|
||||
print "__ctexec " quote_value($0)
|
||||
match_ctline = 0
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[ \t]+/ {
|
||||
if (match_indented) {
|
||||
sub(/^[ \t]+/, "", $0)
|
||||
print "__ctexec " quote_value($0)
|
||||
}
|
||||
next
|
||||
|
|
|
@ -7,14 +7,16 @@ PUBKEYS="@@PUBKEYS@@"
|
|||
##@inc[../base
|
||||
## Fonctions de base
|
||||
|
||||
if [ "$0" == "-bash" ]; then
|
||||
if [ -n "$UTOOLS_HAVE_SCRIPTVARS" ]; then
|
||||
:
|
||||
elif [ "$0" == "-bash" ]; then
|
||||
scriptname=
|
||||
scriptdir=
|
||||
script=
|
||||
else
|
||||
scriptname=`basename -- "$0"`
|
||||
scriptdir=`dirname -- "$0"`
|
||||
scriptdir=`cd "$scriptdir"; pwd`
|
||||
scriptname="$(basename -- "$0")"
|
||||
scriptdir="$(dirname -- "$0")"
|
||||
scriptdir="$(cd "$scriptdir"; pwd)"
|
||||
script="$scriptdir/$scriptname"
|
||||
fi
|
||||
: "${ULIBDIR:=$scriptdir}"
|
||||
|
@ -758,6 +760,40 @@ function relpath() {
|
|||
echo "${rp%//}"
|
||||
fi
|
||||
}
|
||||
function withinpath() {
|
||||
local b="$1" p="$2" strict="${3:-N}"
|
||||
b="$(abspath "$b")"
|
||||
p="$(abspath "$p")"
|
||||
if is_yes "$strict"; then
|
||||
[ "${p#$b/}" != "$p" ]
|
||||
else
|
||||
[ "$p" == "$b" -o "${p#$b/}" != "$p" ]
|
||||
fi
|
||||
}
|
||||
function safe_abspath() {
|
||||
local p="$1" ba="$2" br="$3"
|
||||
if [ -n "$ba" ]; then
|
||||
ba="$(abspath "$ba")"
|
||||
else
|
||||
ba="$(pwd)"
|
||||
fi
|
||||
[ -n "$br" ] || br="$ba"
|
||||
br="$(abspath "$br" "$ba")"
|
||||
p="$(abspath "$p" "$ba")"
|
||||
if [ "$p" == "$br" -o "${p#$br/}" != "$p" ]; then
|
||||
echo "$p"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
function safe_relpath() {
|
||||
local p
|
||||
if p="$(safe_abspath "$1" "$2" "$3")"; then
|
||||
relpath "$p" "$2" "$(pwd)"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
function splitwcs() {
|
||||
local __sw_p="$1"
|
||||
local __sw_dd="${2:-basedir}" __sw_df="${3:-filespec}" __sw_part __sw_d __sw_f
|
||||
|
@ -1129,6 +1165,18 @@ function array_lsdirs() {
|
|||
function array_lsfiles() {
|
||||
__array_ls files "$@"
|
||||
}
|
||||
function filter_vcspath() {
|
||||
sed '
|
||||
/^.git$/d
|
||||
/^.git\//d
|
||||
/\/.git$/d
|
||||
/\/.git\//d
|
||||
/^.svn$/d
|
||||
/^.svn\//d
|
||||
/\/.svn$/d
|
||||
/\/.svn\//d
|
||||
'
|
||||
}
|
||||
function merge_contlines() {
|
||||
awk 'substr($0, length($0)) == "\\" {
|
||||
while (getline nextline) {
|
||||
|
@ -1177,7 +1225,11 @@ function extract_archive() {
|
|||
elif endswith "$arch" .tar; then
|
||||
tar xf "$arch" -C "$destdir" "$@" || return
|
||||
elif endswith "$arch" .jar || endswith "$arch" .war || endswith "$arch" .ear; then
|
||||
jar xf "$arch" -C "$destdir" "$@" || return
|
||||
(
|
||||
arch="$(abspath "$arch")"
|
||||
cd "$destdir"
|
||||
jar xf "$arch" "$@"
|
||||
) || return
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
@ -1187,9 +1239,9 @@ function get_archive_basename() {
|
|||
basename="${basename%.zip}"
|
||||
basename="${basename%.tgz}"
|
||||
basename="${basename%.tbz2}"
|
||||
basename="${basename%.tar}"
|
||||
basename="${basename%.gz}"
|
||||
basename="${basename%.bz2}"
|
||||
basename="${basename%.tar}"
|
||||
basename="${basename%.jar}"
|
||||
basename="${basename%.war}"
|
||||
basename="${basename%.ear}"
|
||||
|
@ -1200,9 +1252,9 @@ function get_archive_appname() {
|
|||
appname="${appname%.zip}"
|
||||
appname="${appname%.tgz}"
|
||||
appname="${appname%.tbz2}"
|
||||
appname="${appname%.tar}"
|
||||
appname="${appname%.gz}"
|
||||
appname="${appname%.bz2}"
|
||||
appname="${appname%.tar}"
|
||||
appname="${appname%.jar}"
|
||||
appname="${appname%.war}"
|
||||
appname="${appname%.ear}"
|
||||
|
@ -1223,6 +1275,8 @@ function get_archive_version() {
|
|||
print vs["1"]
|
||||
} else if (match($0, /([0-9]+([-_.][0-9]+)*([a-zA-Z][0-9]*|[-_.][0-9]+[a-zA-Z][0-9]*)?)$/, vs)) {
|
||||
print vs["1"]
|
||||
} else if (match($0, /([0-9]+[a-z][a-z][a-z]?)$/, vs)) {
|
||||
print vs["1"]
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
@ -1296,6 +1350,107 @@ function run_as() {
|
|||
function run_as_root() {
|
||||
is_root || run_as root "$@"
|
||||
}
|
||||
function check_user() {
|
||||
local user
|
||||
for user in "$@"; do
|
||||
[ "$USER" == "$user" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function ensure_user() {
|
||||
local -a users
|
||||
while [ $# -gt 0 -a "$1" != "--" ]; do
|
||||
array_add users "$1"
|
||||
shift
|
||||
done
|
||||
[ "$1" == "--" ] && shift
|
||||
|
||||
if ! check_user "${users[@]}"; then
|
||||
if [ ${#users[*]} -gt 1 ]; then
|
||||
ewarn "Cette commande doit être lancée avec l'un des users ${users[*]}"
|
||||
else
|
||||
ewarn "Cette commande doit être lancée avec le user ${users[0]}"
|
||||
fi
|
||||
if ask_yesno "Voulez-vous tenter de relancer la commande avec le bon user?" O; then
|
||||
estep "Lancement du script avec le user ${users[0]}"
|
||||
run_as "${users[0]}" "$@"
|
||||
return 1
|
||||
elif is_root; then
|
||||
return 11
|
||||
else
|
||||
return 10
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
function check_hostname() {
|
||||
local userhost user host path
|
||||
for userhost in "$@"; do
|
||||
splitfsep "$userhost" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
[ "$MYHOSTNAME" == "${host%%.*}" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function check_userhostname() {
|
||||
local userhost path user host
|
||||
for userhost in "$@"; do
|
||||
if check_hostname "$userhost"; then
|
||||
[[ "$userhost" == *@* ]] || return 0
|
||||
splitfsep "$userhost" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
check_user "$user" && return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
UTOOLS_ENSURE_HOSTNAME_SSH_OPTS=()
|
||||
function ensure_hostname() {
|
||||
local -a userhosts
|
||||
while [ $# -gt 0 -a "$1" != "--" ]; do
|
||||
array_add userhosts "$1"
|
||||
shift
|
||||
done
|
||||
[ "$1" == "--" ] && shift
|
||||
|
||||
local userhost user host path
|
||||
if ! check_hostname "${userhosts[@]}"; then
|
||||
if [ ${#userhosts[*]} -gt 1 ]; then
|
||||
ewarn "Cette commande n'est valide que sur l'un des hôtes ${userhosts[*]}"
|
||||
else
|
||||
ewarn "Cette commande n'est valide que sur l'hôte ${userhosts[0]}"
|
||||
fi
|
||||
|
||||
enote "Vous pouvez tenter de relancer le script sur ${userhosts[0]}, mais cela requière que ce script ET les données dont il a besoin soient installés dans la même version et dans le même répertoire sur l'hôte distant"
|
||||
if ask_yesno "Voulez-vous tenter de relancer le script sur l'hôte distant?" N; then
|
||||
splitfsep "${userhosts[0]}" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
[ -n "$user" ] || user=root
|
||||
|
||||
estep "Lancement de la commande sur l'hôte distant $user@$host"
|
||||
local cmd
|
||||
[ -n "$path" ] && cmd="$(quoted_args cd "$path"); "
|
||||
cmd="$cmd$(quoted_args "$script" "$@")"
|
||||
ssh -qt "${UTOOLS_ENSURE_HOSTNAME_SSH_OPTS[@]}" "$user@$host" "$cmd"
|
||||
[ $? -eq 255 ] && return 12
|
||||
return 1
|
||||
else
|
||||
return 11
|
||||
fi
|
||||
fi
|
||||
local userhost user host
|
||||
for userhost in "${userhosts[@]}"; do
|
||||
[[ "$userhost" == *@* ]] || continue
|
||||
if check_hostname "$userhost"; then
|
||||
splitfsep "$userhost" : userhost path
|
||||
splituserhost "$userhost" user host
|
||||
[ -n "$path" ] && cd "$path"
|
||||
ensure_user "$user" -- "$@"
|
||||
return $?
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
__AWKDEF_FUNCTIONS='
|
||||
function quote_html(s) {
|
||||
|
@ -1515,26 +1670,47 @@ function merge_line(input, field, key, line) {
|
|||
line = find_line(input, field, $key)
|
||||
if (line != "") $0 = $0 FS line
|
||||
}
|
||||
function __csv_parse_quoted(line, destl, pos, tmpl, nextc, resl) {
|
||||
function __csv_parse_quoted(line, destl, colsep, qchar, echar, pos, tmpl, nextc, resl) {
|
||||
line = substr(line, 2)
|
||||
resl = ""
|
||||
while (1) {
|
||||
pos = index(line, "\"")
|
||||
pos = index(line, qchar)
|
||||
if (pos == 0) {
|
||||
resl = resl line
|
||||
destl[0] = ""
|
||||
destl[1] = 0
|
||||
return resl
|
||||
}
|
||||
if (echar != "" && pos > 1) {
|
||||
prevc = substr(line, pos - 1, 1)
|
||||
quotec = substr(line, pos, 1)
|
||||
nextc = substr(line, pos + 1, 1)
|
||||
if (prevc == echar) {
|
||||
tmpl = substr(line, 1, pos - 2)
|
||||
resl = resl tmpl quotec
|
||||
line = substr(line, pos + 1)
|
||||
continue
|
||||
}
|
||||
tmpl = substr(line, 1, pos - 1)
|
||||
if (nextc == colsep || nextc == "") {
|
||||
resl = resl tmpl
|
||||
destl[0] = substr(line, pos + 2)
|
||||
destl[1] = nextc == colsep
|
||||
return resl
|
||||
} else {
|
||||
resl = resl tmpl quotec
|
||||
line = substr(line, pos + 1)
|
||||
}
|
||||
} else {
|
||||
tmpl = substr(line, 1, pos - 1)
|
||||
quotec = substr(line, pos, 1)
|
||||
nextc = substr(line, pos + 1, 1)
|
||||
if (nextc == "," || nextc == "") {
|
||||
if (nextc == colsep || nextc == "") {
|
||||
resl = resl tmpl
|
||||
destl[0] = substr(line, pos + 2)
|
||||
destl[1] = nextc == ","
|
||||
destl[1] = nextc == colsep
|
||||
return resl
|
||||
} else if (nextc == "\"") {
|
||||
} else if (nextc == qchar) {
|
||||
resl = resl tmpl quotec
|
||||
line = substr(line, pos + 2)
|
||||
} else {
|
||||
|
@ -1542,9 +1718,10 @@ function __csv_parse_quoted(line, destl, pos, tmpl, nextc, resl) {
|
|||
line = substr(line, pos + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function __csv_parse_unquoted(line, destl, pos) {
|
||||
pos = index(line, ",")
|
||||
function __csv_parse_unquoted(line, destl, colsep, qchar, echar, pos) {
|
||||
pos = index(line, colsep)
|
||||
if (pos == 0) {
|
||||
destl[0] = ""
|
||||
destl[1] = 0
|
||||
|
@ -1555,18 +1732,18 @@ function __csv_parse_unquoted(line, destl, pos) {
|
|||
return substr(line, 1, pos - 1)
|
||||
}
|
||||
}
|
||||
function array_parsecsv(fields, line, nbfields, shouldparse, destl, i) {
|
||||
function __array_parsecsv(fields, line, nbfields, colsep, qchar, echar, shouldparse, destl, i) {
|
||||
array_new(fields)
|
||||
array_new(destl)
|
||||
i = 1
|
||||
shouldparse = 0
|
||||
while (shouldparse || line != "") {
|
||||
if (line ~ /^"/) {
|
||||
value = __csv_parse_quoted(line, destl)
|
||||
if (index(line, qchar) == 1) {
|
||||
value = __csv_parse_quoted(line, destl, colsep, qchar, echar)
|
||||
line = destl[0]
|
||||
shouldparse = destl[1]
|
||||
} else {
|
||||
value = __csv_parse_unquoted(line, destl)
|
||||
value = __csv_parse_unquoted(line, destl, colsep, qchar, echar)
|
||||
line = destl[0]
|
||||
shouldparse = destl[1]
|
||||
}
|
||||
|
@ -1580,6 +1757,20 @@ function array_parsecsv(fields, line, nbfields, shouldparse, destl, i) {
|
|||
}
|
||||
return length(fields)
|
||||
}
|
||||
BEGIN {
|
||||
DEFAULT_COLSEP = ","
|
||||
DEFAULT_QCHAR = "\""
|
||||
DEFAULT_ECHAR = ""
|
||||
}
|
||||
function array_parsecsv2(fields, line, nbfields, colsep, qchar, echar) {
|
||||
return __array_parsecsv(fields, line, nbfields, colsep, qchar, echar)
|
||||
}
|
||||
function array_parsecsv(fields, line, nbfields, colsep, qchar, echar) {
|
||||
if (colsep == "") colsep = DEFAULT_COLSEP
|
||||
if (qchar == "") qchar = DEFAULT_QCHAR
|
||||
if (echar == "") echar = DEFAULT_ECHAR
|
||||
return __array_parsecsv(fields, line, nbfields, colsep, qchar, echar)
|
||||
}
|
||||
function parsecsv(line, fields) {
|
||||
array_parsecsv(fields, line)
|
||||
array_getline(fields)
|
||||
|
@ -1598,18 +1789,18 @@ function __csv_should_quote(s) {
|
|||
if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1
|
||||
return 0
|
||||
}
|
||||
function array_formatcsv2(fields, asep, vsep, qsep, escape, count, indices, line, i, value) {
|
||||
function array_formatcsv2(fields, colsep, mvsep, qchar, echar, count, indices, line, i, value) {
|
||||
line = ""
|
||||
count = mkindices(fields, indices)
|
||||
for (i = 1; i <= count; i++) {
|
||||
value = fields[indices[i]]
|
||||
if (i > 1) line = line asep
|
||||
if (qsep != "" && index(value, qsep) != 0) {
|
||||
if (escape) gsub(qsep, quote_subrepl(escape) "&", value);
|
||||
else gsub(qsep, "&&", value);
|
||||
if (i > 1) line = line colsep
|
||||
if (qchar != "" && index(value, qchar) != 0) {
|
||||
if (echar != "") gsub(qchar, quote_subrepl(echar) "&", value);
|
||||
else gsub(qchar, "&&", value);
|
||||
}
|
||||
if (qsep != "" && (index(value, qsep) != 0 || index(value, asep) != 0 || __csv_should_quote(value))) {
|
||||
line = line qsep value qsep
|
||||
if (qchar != "" && (index(value, mvsep) != 0 || index(value, colsep) != 0 || __csv_should_quote(value))) {
|
||||
line = line qchar value qchar
|
||||
} else {
|
||||
line = line value
|
||||
}
|
||||
|
@ -1970,6 +2161,64 @@ function __po_process_options() {
|
|||
set_array "$destargs_" @ "$@"
|
||||
return 0
|
||||
}
|
||||
function __genparse_shortopt() {
|
||||
local LC_COLLATE=C
|
||||
local shortopt="${1//[^A-Z]}"
|
||||
shortopt="${shortopt:0:1}"
|
||||
shortopt="${shortopt,,}"
|
||||
[ -n "$shortopt" ] && echo "$shortopt"
|
||||
}
|
||||
function genparse() {
|
||||
|
||||
local -a descs vars options
|
||||
local desc var option name value shortopt
|
||||
|
||||
for var in "$@"; do
|
||||
if [[ "$var" == *=* ]]; then
|
||||
splitvar "$var" name value
|
||||
shortopt="$(__genparse_shortopt "$name")"
|
||||
option="${name,,}"
|
||||
name="${option//-/_}"
|
||||
array_add descs "${shortopt:+-$shortopt, }--$option VALUE"
|
||||
array_add vars "$(set_var_cmd "$name" "$value")"
|
||||
array_add options "${shortopt:+-$shortopt:,}--$option: $name="
|
||||
else
|
||||
name="$var"
|
||||
shortopt="$(__genparse_shortopt "$name")"
|
||||
option="${name,,}"
|
||||
name="${option//-/_}"
|
||||
array_add descs "${shortopt:+-$shortopt, }--$option"
|
||||
array_add vars "$name="
|
||||
array_add options "${shortopt:+-$shortopt,}--$option $name=1"
|
||||
fi
|
||||
done
|
||||
|
||||
echo -n 'function display_help() {
|
||||
uecho "\
|
||||
USAGE
|
||||
$scriptname'
|
||||
if [ -n "$descs" ]; then
|
||||
echo -n ' [options]
|
||||
|
||||
OPTIONS'
|
||||
for desc in "${descs[@]}"; do
|
||||
echo -n "
|
||||
$desc"
|
||||
done
|
||||
fi
|
||||
echo '"
|
||||
}
|
||||
'
|
||||
for var in "${vars[@]}"; do
|
||||
echo "$var"
|
||||
done
|
||||
echo 'parse_opts "${PRETTYOPTS[@]}" \'
|
||||
echo ' --help '\''$exit_with display_help'\'' \'
|
||||
for option in "${options[@]}"; do
|
||||
echo " $option \\"
|
||||
done
|
||||
echo ' @ args -- "$@" && set -- "${args[@]}" || die "$args"'
|
||||
}
|
||||
|
||||
function __lf_get_age() {
|
||||
local y=$(date "+%Y")
|
||||
|
@ -2686,13 +2935,14 @@ function simple_menu() {
|
|||
}
|
||||
|
||||
|
||||
__ac_files=()
|
||||
function __ac_forgetall() { __ac_files=(); }
|
||||
__ac_forgetall
|
||||
function __ac_trap() {
|
||||
local file
|
||||
for file in "${__ac_files[@]}"; do
|
||||
[ -e "$file" ] && rm -rf "$file" 2>/dev/null
|
||||
done
|
||||
__ac_files=()
|
||||
__ac_forgetall
|
||||
}
|
||||
trap __ac_trap 1 3 15 EXIT
|
||||
function autoclean() {
|
||||
|
@ -2749,6 +2999,13 @@ function ac_set_tmpdir() {
|
|||
set_var "$1" "$__acst_t"
|
||||
fi
|
||||
}
|
||||
function debug_tee() {
|
||||
if show_debug; then
|
||||
tee "$@"
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function get_defaults_files() {
|
||||
|
@ -2802,24 +3059,6 @@ if [ -n "$UTOOLS_CHROOT" ]; then
|
|||
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
|
||||
fi
|
||||
|
||||
function check_user() {
|
||||
local user
|
||||
for user in "$@"; do
|
||||
[ "$user" == "$USER" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
function ensure_user() {
|
||||
check_user "$@" && return 0
|
||||
if [ $# -eq 1 ]; then
|
||||
eerror "Pour cette commande, il faut être l'utilisateur $1"
|
||||
else
|
||||
eerror "Pour cette commande, il faut être l'un des utilisateurs suivants: $*"
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [ -z "$ULIBDIR" -o "$ULIBDIR" != "$ULIBINIT" ]; then
|
||||
ULIBPROVIDED=()
|
||||
|
|
Loading…
Reference in New Issue