maj des inclusions

This commit is contained in:
Jephte CLAIN 2013-11-14 19:11:39 +04:00
parent f573fe6824
commit c6a529b6ff
2 changed files with 629 additions and 112 deletions

392
ucrontab
View File

@ -94,14 +94,16 @@ DEFAULT_GDELAY=15
##@inc[base ##@inc[base
## Fonctions de base ## Fonctions de base
if [ "$0" == "-bash" ]; then if [ -n "$UTOOLS_HAVE_SCRIPTVARS" ]; then
:
elif [ "$0" == "-bash" ]; then
scriptname= scriptname=
scriptdir= scriptdir=
script= script=
else else
scriptname=`basename -- "$0"` scriptname="$(basename -- "$0")"
scriptdir=`dirname -- "$0"` scriptdir="$(dirname -- "$0")"
scriptdir=`cd "$scriptdir"; pwd` scriptdir="$(cd "$scriptdir"; pwd)"
script="$scriptdir/$scriptname" script="$scriptdir/$scriptname"
fi fi
: "${ULIBDIR:=$scriptdir}" : "${ULIBDIR:=$scriptdir}"
@ -845,6 +847,40 @@ function relpath() {
echo "${rp%//}" echo "${rp%//}"
fi 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() { function splitwcs() {
local __sw_p="$1" local __sw_p="$1"
local __sw_dd="${2:-basedir}" __sw_df="${3:-filespec}" __sw_part __sw_d __sw_f 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() { function array_lsfiles() {
__array_ls files "$@" __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() { function merge_contlines() {
awk 'substr($0, length($0)) == "\\" { awk 'substr($0, length($0)) == "\\" {
while (getline nextline) { while (getline nextline) {
@ -1264,7 +1312,11 @@ function extract_archive() {
elif endswith "$arch" .tar; then elif endswith "$arch" .tar; then
tar xf "$arch" -C "$destdir" "$@" || return tar xf "$arch" -C "$destdir" "$@" || return
elif endswith "$arch" .jar || endswith "$arch" .war || endswith "$arch" .ear; then 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 else
return 1 return 1
fi fi
@ -1274,9 +1326,9 @@ function get_archive_basename() {
basename="${basename%.zip}" basename="${basename%.zip}"
basename="${basename%.tgz}" basename="${basename%.tgz}"
basename="${basename%.tbz2}" basename="${basename%.tbz2}"
basename="${basename%.tar}"
basename="${basename%.gz}" basename="${basename%.gz}"
basename="${basename%.bz2}" basename="${basename%.bz2}"
basename="${basename%.tar}"
basename="${basename%.jar}" basename="${basename%.jar}"
basename="${basename%.war}" basename="${basename%.war}"
basename="${basename%.ear}" basename="${basename%.ear}"
@ -1287,9 +1339,9 @@ function get_archive_appname() {
appname="${appname%.zip}" appname="${appname%.zip}"
appname="${appname%.tgz}" appname="${appname%.tgz}"
appname="${appname%.tbz2}" appname="${appname%.tbz2}"
appname="${appname%.tar}"
appname="${appname%.gz}" appname="${appname%.gz}"
appname="${appname%.bz2}" appname="${appname%.bz2}"
appname="${appname%.tar}"
appname="${appname%.jar}" appname="${appname%.jar}"
appname="${appname%.war}" appname="${appname%.war}"
appname="${appname%.ear}" appname="${appname%.ear}"
@ -1310,6 +1362,8 @@ function get_archive_version() {
print vs["1"] print vs["1"]
} else if (match($0, /([0-9]+([-_.][0-9]+)*([a-zA-Z][0-9]*|[-_.][0-9]+[a-zA-Z][0-9]*)?)$/, vs)) { } else if (match($0, /([0-9]+([-_.][0-9]+)*([a-zA-Z][0-9]*|[-_.][0-9]+[a-zA-Z][0-9]*)?)$/, vs)) {
print vs["1"] 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() { function run_as_root() {
is_root || 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=' __AWKDEF_FUNCTIONS='
function quote_html(s) { function quote_html(s) {
@ -1602,36 +1757,58 @@ function merge_line(input, field, key, line) {
line = find_line(input, field, $key) line = find_line(input, field, $key)
if (line != "") $0 = $0 FS line 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) line = substr(line, 2)
resl = "" resl = ""
while (1) { while (1) {
pos = index(line, "\"") pos = index(line, qchar)
if (pos == 0) { if (pos == 0) {
resl = resl line resl = resl line
destl[0] = "" destl[0] = ""
destl[1] = 0 destl[1] = 0
return resl return resl
} }
tmpl = substr(line, 1, pos - 1) if (echar != "" && pos > 1) {
quotec = substr(line, pos, 1) prevc = substr(line, pos - 1, 1)
nextc = substr(line, pos + 1, 1) quotec = substr(line, pos, 1)
if (nextc == "," || nextc == "") { nextc = substr(line, pos + 1, 1)
resl = resl tmpl if (prevc == echar) {
destl[0] = substr(line, pos + 2) tmpl = substr(line, 1, pos - 2)
destl[1] = nextc == "," resl = resl tmpl quotec
return resl line = substr(line, pos + 1)
} else if (nextc == "\"") { continue
resl = resl tmpl quotec }
line = substr(line, pos + 2) 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 { } else {
resl = resl tmpl quotec tmpl = substr(line, 1, pos - 1)
line = substr(line, pos + 1) quotec = substr(line, pos, 1)
nextc = substr(line, pos + 1, 1)
if (nextc == colsep || nextc == "") {
resl = resl tmpl
destl[0] = substr(line, pos + 2)
destl[1] = nextc == colsep
return resl
} else if (nextc == qchar) {
resl = resl tmpl quotec
line = substr(line, pos + 2)
} else {
resl = resl tmpl quotec
line = substr(line, pos + 1)
}
} }
} }
} }
function __csv_parse_unquoted(line, destl, pos) { function __csv_parse_unquoted(line, destl, colsep, qchar, echar, pos) {
pos = index(line, ",") pos = index(line, colsep)
if (pos == 0) { if (pos == 0) {
destl[0] = "" destl[0] = ""
destl[1] = 0 destl[1] = 0
@ -1642,18 +1819,18 @@ function __csv_parse_unquoted(line, destl, pos) {
return substr(line, 1, pos - 1) 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(fields)
array_new(destl) array_new(destl)
i = 1 i = 1
shouldparse = 0 shouldparse = 0
while (shouldparse || line != "") { while (shouldparse || line != "") {
if (line ~ /^"/) { if (index(line, qchar) == 1) {
value = __csv_parse_quoted(line, destl) value = __csv_parse_quoted(line, destl, colsep, qchar, echar)
line = destl[0] line = destl[0]
shouldparse = destl[1] shouldparse = destl[1]
} else { } else {
value = __csv_parse_unquoted(line, destl) value = __csv_parse_unquoted(line, destl, colsep, qchar, echar)
line = destl[0] line = destl[0]
shouldparse = destl[1] shouldparse = destl[1]
} }
@ -1667,6 +1844,20 @@ function array_parsecsv(fields, line, nbfields, shouldparse, destl, i) {
} }
return length(fields) 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) { function parsecsv(line, fields) {
array_parsecsv(fields, line) array_parsecsv(fields, line)
array_getline(fields) array_getline(fields)
@ -1685,18 +1876,18 @@ function __csv_should_quote(s) {
if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1 if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1
return 0 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 = "" line = ""
count = mkindices(fields, indices) count = mkindices(fields, indices)
for (i = 1; i <= count; i++) { for (i = 1; i <= count; i++) {
value = fields[indices[i]] value = fields[indices[i]]
if (i > 1) line = line asep if (i > 1) line = line colsep
if (qsep != "" && index(value, qsep) != 0) { if (qchar != "" && index(value, qchar) != 0) {
if (escape) gsub(qsep, quote_subrepl(escape) "&", value); if (echar != "") gsub(qchar, quote_subrepl(echar) "&", value);
else gsub(qsep, "&&", value); else gsub(qchar, "&&", value);
} }
if (qsep != "" && (index(value, qsep) != 0 || index(value, asep) != 0 || __csv_should_quote(value))) { if (qchar != "" && (index(value, mvsep) != 0 || index(value, colsep) != 0 || __csv_should_quote(value))) {
line = line qsep value qsep line = line qchar value qchar
} else { } else {
line = line value line = line value
} }
@ -2057,6 +2248,64 @@ function __po_process_options() {
set_array "$destargs_" @ "$@" set_array "$destargs_" @ "$@"
return 0 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() { function __lf_get_age() {
local y=$(date "+%Y") local y=$(date "+%Y")
@ -2773,13 +3022,14 @@ function simple_menu() {
} }
__ac_files=() function __ac_forgetall() { __ac_files=(); }
__ac_forgetall
function __ac_trap() { function __ac_trap() {
local file local file
for file in "${__ac_files[@]}"; do for file in "${__ac_files[@]}"; do
[ -e "$file" ] && rm -rf "$file" 2>/dev/null [ -e "$file" ] && rm -rf "$file" 2>/dev/null
done done
__ac_files=() __ac_forgetall
} }
trap __ac_trap 1 3 15 EXIT trap __ac_trap 1 3 15 EXIT
function autoclean() { function autoclean() {
@ -2836,6 +3086,13 @@ function ac_set_tmpdir() {
set_var "$1" "$__acst_t" set_var "$1" "$__acst_t"
fi fi
} }
function debug_tee() {
if show_debug; then
tee "$@"
else
cat
fi
}
function get_defaults_files() { function get_defaults_files() {
@ -2889,24 +3146,6 @@ if [ -n "$UTOOLS_CHROOT" ]; then
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE" [ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi 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 if [ -z "$ULIBDIR" -o "$ULIBDIR" != "$ULIBINIT" ]; then
ULIBPROVIDED=() ULIBPROVIDED=()
@ -3113,6 +3352,7 @@ function is_interaction() {
-y|--automatic) [ -n "$__interaction" -a "$__interaction" -eq 1 ];; -y|--automatic) [ -n "$__interaction" -a "$__interaction" -eq 1 ];;
-c|--default) [ -n "$__interaction" -a "$__interaction" -eq 2 ];; -c|--default) [ -n "$__interaction" -a "$__interaction" -eq 2 ];;
-i|--interactive) [ -n "$__interaction" -a "$__interaction" -eq 3 ];; -i|--interactive) [ -n "$__interaction" -a "$__interaction" -eq 3 ];;
-C) [ -n "$__interaction" -a "$__interaction" -ge 2 ];;
*) return 1;; *) return 1;;
esac esac
} }
@ -3909,16 +4149,41 @@ BEGIN {
refM = ctnow[1]; refH = ctnow[2]; refdom = ctnow[3]; refmon = ctnow[4]; refdow = ctnow[5] refM = ctnow[1]; refH = ctnow[2]; refdom = ctnow[3]; refmon = ctnow[4]; refdow = ctnow[5]
ctref = refM " " refH " " refdom " " refmon " " refdow ctref = refM " " refH " " refdom " " refmon " " refdow
print "##now: " ctref 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 print "export " $0
next 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 M = $1; H = $2; dom = $3; mon = $4; dow = $5
sub(/^[ ]*[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]*/, "", $0) sub(/^[ ]*[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]*/, "", $0)
if (!match_ctline) match_indented = 0
ctline = M " " H " " dom " " mon " " dow ctline = M " " H " " dom " " mon " " dow
gsub(/\*/, "0-59", M) gsub(/\*/, "0-59", M)
@ -3938,6 +4203,19 @@ BEGIN {
if (Mok && Hok && monok && (domok || dowok)) { if (Mok && Hok && monok && (domok || dowok)) {
print "##matches: " ctline 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) print "__ctexec " quote_value($0)
} }
next next

View File

@ -7,14 +7,16 @@ PUBKEYS="@@PUBKEYS@@"
##@inc[../base ##@inc[../base
## Fonctions de base ## Fonctions de base
if [ "$0" == "-bash" ]; then if [ -n "$UTOOLS_HAVE_SCRIPTVARS" ]; then
:
elif [ "$0" == "-bash" ]; then
scriptname= scriptname=
scriptdir= scriptdir=
script= script=
else else
scriptname=`basename -- "$0"` scriptname="$(basename -- "$0")"
scriptdir=`dirname -- "$0"` scriptdir="$(dirname -- "$0")"
scriptdir=`cd "$scriptdir"; pwd` scriptdir="$(cd "$scriptdir"; pwd)"
script="$scriptdir/$scriptname" script="$scriptdir/$scriptname"
fi fi
: "${ULIBDIR:=$scriptdir}" : "${ULIBDIR:=$scriptdir}"
@ -758,6 +760,40 @@ function relpath() {
echo "${rp%//}" echo "${rp%//}"
fi 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() { function splitwcs() {
local __sw_p="$1" local __sw_p="$1"
local __sw_dd="${2:-basedir}" __sw_df="${3:-filespec}" __sw_part __sw_d __sw_f 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() { function array_lsfiles() {
__array_ls files "$@" __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() { function merge_contlines() {
awk 'substr($0, length($0)) == "\\" { awk 'substr($0, length($0)) == "\\" {
while (getline nextline) { while (getline nextline) {
@ -1177,7 +1225,11 @@ function extract_archive() {
elif endswith "$arch" .tar; then elif endswith "$arch" .tar; then
tar xf "$arch" -C "$destdir" "$@" || return tar xf "$arch" -C "$destdir" "$@" || return
elif endswith "$arch" .jar || endswith "$arch" .war || endswith "$arch" .ear; then 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 else
return 1 return 1
fi fi
@ -1187,9 +1239,9 @@ function get_archive_basename() {
basename="${basename%.zip}" basename="${basename%.zip}"
basename="${basename%.tgz}" basename="${basename%.tgz}"
basename="${basename%.tbz2}" basename="${basename%.tbz2}"
basename="${basename%.tar}"
basename="${basename%.gz}" basename="${basename%.gz}"
basename="${basename%.bz2}" basename="${basename%.bz2}"
basename="${basename%.tar}"
basename="${basename%.jar}" basename="${basename%.jar}"
basename="${basename%.war}" basename="${basename%.war}"
basename="${basename%.ear}" basename="${basename%.ear}"
@ -1200,9 +1252,9 @@ function get_archive_appname() {
appname="${appname%.zip}" appname="${appname%.zip}"
appname="${appname%.tgz}" appname="${appname%.tgz}"
appname="${appname%.tbz2}" appname="${appname%.tbz2}"
appname="${appname%.tar}"
appname="${appname%.gz}" appname="${appname%.gz}"
appname="${appname%.bz2}" appname="${appname%.bz2}"
appname="${appname%.tar}"
appname="${appname%.jar}" appname="${appname%.jar}"
appname="${appname%.war}" appname="${appname%.war}"
appname="${appname%.ear}" appname="${appname%.ear}"
@ -1223,6 +1275,8 @@ function get_archive_version() {
print vs["1"] print vs["1"]
} else if (match($0, /([0-9]+([-_.][0-9]+)*([a-zA-Z][0-9]*|[-_.][0-9]+[a-zA-Z][0-9]*)?)$/, vs)) { } else if (match($0, /([0-9]+([-_.][0-9]+)*([a-zA-Z][0-9]*|[-_.][0-9]+[a-zA-Z][0-9]*)?)$/, vs)) {
print vs["1"] 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() { function run_as_root() {
is_root || 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=' __AWKDEF_FUNCTIONS='
function quote_html(s) { function quote_html(s) {
@ -1515,36 +1670,58 @@ function merge_line(input, field, key, line) {
line = find_line(input, field, $key) line = find_line(input, field, $key)
if (line != "") $0 = $0 FS line 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) line = substr(line, 2)
resl = "" resl = ""
while (1) { while (1) {
pos = index(line, "\"") pos = index(line, qchar)
if (pos == 0) { if (pos == 0) {
resl = resl line resl = resl line
destl[0] = "" destl[0] = ""
destl[1] = 0 destl[1] = 0
return resl return resl
} }
tmpl = substr(line, 1, pos - 1) if (echar != "" && pos > 1) {
quotec = substr(line, pos, 1) prevc = substr(line, pos - 1, 1)
nextc = substr(line, pos + 1, 1) quotec = substr(line, pos, 1)
if (nextc == "," || nextc == "") { nextc = substr(line, pos + 1, 1)
resl = resl tmpl if (prevc == echar) {
destl[0] = substr(line, pos + 2) tmpl = substr(line, 1, pos - 2)
destl[1] = nextc == "," resl = resl tmpl quotec
return resl line = substr(line, pos + 1)
} else if (nextc == "\"") { continue
resl = resl tmpl quotec }
line = substr(line, pos + 2) 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 { } else {
resl = resl tmpl quotec tmpl = substr(line, 1, pos - 1)
line = substr(line, pos + 1) quotec = substr(line, pos, 1)
nextc = substr(line, pos + 1, 1)
if (nextc == colsep || nextc == "") {
resl = resl tmpl
destl[0] = substr(line, pos + 2)
destl[1] = nextc == colsep
return resl
} else if (nextc == qchar) {
resl = resl tmpl quotec
line = substr(line, pos + 2)
} else {
resl = resl tmpl quotec
line = substr(line, pos + 1)
}
} }
} }
} }
function __csv_parse_unquoted(line, destl, pos) { function __csv_parse_unquoted(line, destl, colsep, qchar, echar, pos) {
pos = index(line, ",") pos = index(line, colsep)
if (pos == 0) { if (pos == 0) {
destl[0] = "" destl[0] = ""
destl[1] = 0 destl[1] = 0
@ -1555,18 +1732,18 @@ function __csv_parse_unquoted(line, destl, pos) {
return substr(line, 1, pos - 1) 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(fields)
array_new(destl) array_new(destl)
i = 1 i = 1
shouldparse = 0 shouldparse = 0
while (shouldparse || line != "") { while (shouldparse || line != "") {
if (line ~ /^"/) { if (index(line, qchar) == 1) {
value = __csv_parse_quoted(line, destl) value = __csv_parse_quoted(line, destl, colsep, qchar, echar)
line = destl[0] line = destl[0]
shouldparse = destl[1] shouldparse = destl[1]
} else { } else {
value = __csv_parse_unquoted(line, destl) value = __csv_parse_unquoted(line, destl, colsep, qchar, echar)
line = destl[0] line = destl[0]
shouldparse = destl[1] shouldparse = destl[1]
} }
@ -1580,6 +1757,20 @@ function array_parsecsv(fields, line, nbfields, shouldparse, destl, i) {
} }
return length(fields) 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) { function parsecsv(line, fields) {
array_parsecsv(fields, line) array_parsecsv(fields, line)
array_getline(fields) array_getline(fields)
@ -1598,18 +1789,18 @@ function __csv_should_quote(s) {
if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1 if (s ~ /[[:blank:][:cntrl:][:space:]]$/) return 1
return 0 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 = "" line = ""
count = mkindices(fields, indices) count = mkindices(fields, indices)
for (i = 1; i <= count; i++) { for (i = 1; i <= count; i++) {
value = fields[indices[i]] value = fields[indices[i]]
if (i > 1) line = line asep if (i > 1) line = line colsep
if (qsep != "" && index(value, qsep) != 0) { if (qchar != "" && index(value, qchar) != 0) {
if (escape) gsub(qsep, quote_subrepl(escape) "&", value); if (echar != "") gsub(qchar, quote_subrepl(echar) "&", value);
else gsub(qsep, "&&", value); else gsub(qchar, "&&", value);
} }
if (qsep != "" && (index(value, qsep) != 0 || index(value, asep) != 0 || __csv_should_quote(value))) { if (qchar != "" && (index(value, mvsep) != 0 || index(value, colsep) != 0 || __csv_should_quote(value))) {
line = line qsep value qsep line = line qchar value qchar
} else { } else {
line = line value line = line value
} }
@ -1970,6 +2161,64 @@ function __po_process_options() {
set_array "$destargs_" @ "$@" set_array "$destargs_" @ "$@"
return 0 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() { function __lf_get_age() {
local y=$(date "+%Y") local y=$(date "+%Y")
@ -2686,13 +2935,14 @@ function simple_menu() {
} }
__ac_files=() function __ac_forgetall() { __ac_files=(); }
__ac_forgetall
function __ac_trap() { function __ac_trap() {
local file local file
for file in "${__ac_files[@]}"; do for file in "${__ac_files[@]}"; do
[ -e "$file" ] && rm -rf "$file" 2>/dev/null [ -e "$file" ] && rm -rf "$file" 2>/dev/null
done done
__ac_files=() __ac_forgetall
} }
trap __ac_trap 1 3 15 EXIT trap __ac_trap 1 3 15 EXIT
function autoclean() { function autoclean() {
@ -2749,6 +2999,13 @@ function ac_set_tmpdir() {
set_var "$1" "$__acst_t" set_var "$1" "$__acst_t"
fi fi
} }
function debug_tee() {
if show_debug; then
tee "$@"
else
cat
fi
}
function get_defaults_files() { function get_defaults_files() {
@ -2802,24 +3059,6 @@ if [ -n "$UTOOLS_CHROOT" ]; then
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE" [ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi 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 if [ -z "$ULIBDIR" -o "$ULIBDIR" != "$ULIBINIT" ]; then
ULIBPROVIDED=() ULIBPROVIDED=()