mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge branch 'dev' of github.com:YunoHost/yunohost into dev
This commit is contained in:
commit
a0ee39a038
5 changed files with 78 additions and 27 deletions
|
@ -43,12 +43,14 @@ ynh_replace_string () {
|
||||||
local target_file
|
local target_file
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
set +o xtrace # set +x
|
||||||
|
|
||||||
local delimit=@
|
local delimit=@
|
||||||
# Escape the delimiter if it's in the string.
|
# Escape the delimiter if it's in the string.
|
||||||
match_string=${match_string//${delimit}/"\\${delimit}"}
|
match_string=${match_string//${delimit}/"\\${delimit}"}
|
||||||
replace_string=${replace_string//${delimit}/"\\${delimit}"}
|
replace_string=${replace_string//${delimit}/"\\${delimit}"}
|
||||||
|
|
||||||
|
set -o xtrace # set -x
|
||||||
sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$target_file"
|
sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$target_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
YNH_APP_BASEDIR=$(realpath $([[ "$(basename $0)" =~ ^backup|restore$ ]] && echo '../settings' || [[ -n "$YNH_ACTION" ]] && echo '.' || echo '..' ))
|
YNH_APP_BASEDIR=$(realpath $([[ "$(basename $0)" =~ ^backup|restore$ ]] && echo '../settings' || [[ -n "${YNH_ACTION:-}" ]] && echo '.' || echo '..' ))
|
||||||
|
|
||||||
# Handle script crashes / failures
|
# Handle script crashes / failures
|
||||||
#
|
#
|
||||||
|
@ -519,6 +519,8 @@ ynh_read_var_in_file() {
|
||||||
|
|
||||||
[[ -f $file ]] || ynh_die --message="File $file does not exists"
|
[[ -f $file ]] || ynh_die --message="File $file does not exists"
|
||||||
|
|
||||||
|
set +o xtrace # set +x
|
||||||
|
|
||||||
# Get the line number after which we search for the variable
|
# Get the line number after which we search for the variable
|
||||||
local line_number=1
|
local line_number=1
|
||||||
if [[ -n "$after" ]];
|
if [[ -n "$after" ]];
|
||||||
|
@ -526,6 +528,7 @@ ynh_read_var_in_file() {
|
||||||
line_number=$(grep -n $after $file | cut -d: -f1)
|
line_number=$(grep -n $after $file | cut -d: -f1)
|
||||||
if [[ -z "$line_number" ]];
|
if [[ -z "$line_number" ]];
|
||||||
then
|
then
|
||||||
|
set -o xtrace # set -x
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -555,6 +558,7 @@ ynh_read_var_in_file() {
|
||||||
# Extract the part after assignation sign
|
# Extract the part after assignation sign
|
||||||
local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)"
|
local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)"
|
||||||
if [[ "$expression_with_comment" == "YNH_NULL" ]]; then
|
if [[ "$expression_with_comment" == "YNH_NULL" ]]; then
|
||||||
|
set -o xtrace # set -x
|
||||||
echo YNH_NULL
|
echo YNH_NULL
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -570,6 +574,7 @@ ynh_read_var_in_file() {
|
||||||
else
|
else
|
||||||
echo "$expression"
|
echo "$expression"
|
||||||
fi
|
fi
|
||||||
|
set -o xtrace # set -x
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set a value into heterogeneous file (yaml, json, php, python...)
|
# Set a value into heterogeneous file (yaml, json, php, python...)
|
||||||
|
@ -594,6 +599,8 @@ ynh_write_var_in_file() {
|
||||||
|
|
||||||
[[ -f $file ]] || ynh_die --message="File $file does not exists"
|
[[ -f $file ]] || ynh_die --message="File $file does not exists"
|
||||||
|
|
||||||
|
set +o xtrace # set +x
|
||||||
|
|
||||||
# Get the line number after which we search for the variable
|
# Get the line number after which we search for the variable
|
||||||
local line_number=1
|
local line_number=1
|
||||||
if [[ -n "$after" ]];
|
if [[ -n "$after" ]];
|
||||||
|
@ -601,6 +608,7 @@ ynh_write_var_in_file() {
|
||||||
line_number=$(grep -n $after $file | cut -d: -f1)
|
line_number=$(grep -n $after $file | cut -d: -f1)
|
||||||
if [[ -z "$line_number" ]];
|
if [[ -z "$line_number" ]];
|
||||||
then
|
then
|
||||||
|
set -o xtrace # set -x
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -631,9 +639,10 @@ ynh_write_var_in_file() {
|
||||||
# Extract the part after assignation sign
|
# Extract the part after assignation sign
|
||||||
local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)"
|
local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)"
|
||||||
if [[ "$expression_with_comment" == "YNH_NULL" ]]; then
|
if [[ "$expression_with_comment" == "YNH_NULL" ]]; then
|
||||||
|
set -o xtrace # set -x
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove comments if needed
|
# Remove comments if needed
|
||||||
local expression="$(echo "$expression_with_comment" | sed "s@$comments[^$string]*\$@@g" | sed "s@\s*[$endline]*\s*]*\$@@")"
|
local expression="$(echo "$expression_with_comment" | sed "s@$comments[^$string]*\$@@g" | sed "s@\s*[$endline]*\s*]*\$@@")"
|
||||||
endline=${expression_with_comment#"$expression"}
|
endline=${expression_with_comment#"$expression"}
|
||||||
|
@ -661,6 +670,7 @@ ynh_write_var_in_file() {
|
||||||
fi
|
fi
|
||||||
sed -ri "${range}s$delimiter(^${var_part}).*\$$delimiter\1${value}${endline}${delimiter}i" ${file}
|
sed -ri "${range}s$delimiter(^${var_part}).*\$$delimiter\1${value}${endline}${delimiter}i" ${file}
|
||||||
fi
|
fi
|
||||||
|
set -o xtrace # set -x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -727,6 +737,7 @@ ynh_secure_remove () {
|
||||||
local file
|
local file
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
set +o xtrace # set +x
|
||||||
|
|
||||||
local forbidden_path=" \
|
local forbidden_path=" \
|
||||||
/var/www \
|
/var/www \
|
||||||
|
@ -754,6 +765,8 @@ ynh_secure_remove () {
|
||||||
else
|
else
|
||||||
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
|
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
set -o xtrace # set -x
|
||||||
}
|
}
|
||||||
|
|
||||||
# Extract a key from a plain command output
|
# Extract a key from a plain command output
|
||||||
|
|
|
@ -2180,6 +2180,13 @@ def _set_default_ask_questions(arguments):
|
||||||
key = "app_manifest_%s_ask_%s" % (script_name, arg["name"])
|
key = "app_manifest_%s_ask_%s" % (script_name, arg["name"])
|
||||||
arg["ask"] = m18n.n(key)
|
arg["ask"] = m18n.n(key)
|
||||||
|
|
||||||
|
# Also it in fact doesn't make sense for any of those questions to have an example value nor a default value...
|
||||||
|
if arg.get("type") in ["domain", "user", "password"]:
|
||||||
|
if "example" in arg:
|
||||||
|
del arg["example"]
|
||||||
|
if "default" in arg:
|
||||||
|
del arg["domain"]
|
||||||
|
|
||||||
return arguments
|
return arguments
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,13 @@ def log_list(limit=None, with_details=False, with_suboperations=False):
|
||||||
logs = list(reversed(sorted(logs)))
|
logs = list(reversed(sorted(logs)))
|
||||||
|
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
logs = logs[:limit]
|
if with_suboperations:
|
||||||
|
logs = logs[:limit]
|
||||||
|
else:
|
||||||
|
# If we displaying only parent, we are still gonna load up to limit * 5 logs
|
||||||
|
# because many of them are suboperations which are not gonna be kept
|
||||||
|
# Yet we still want to obtain ~limit number of logs
|
||||||
|
logs = logs[:limit * 5]
|
||||||
|
|
||||||
for log in logs:
|
for log in logs:
|
||||||
|
|
||||||
|
@ -122,6 +128,9 @@ def log_list(limit=None, with_details=False, with_suboperations=False):
|
||||||
else:
|
else:
|
||||||
operations = [o for o in operations.values()]
|
operations = [o for o in operations.values()]
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
operations = operations[:limit]
|
||||||
|
|
||||||
operations = list(reversed(sorted(operations, key=lambda o: o["name"])))
|
operations = list(reversed(sorted(operations, key=lambda o: o["name"])))
|
||||||
# Reverse the order of log when in cli, more comfortable to read (avoid
|
# Reverse the order of log when in cli, more comfortable to read (avoid
|
||||||
# unecessary scrolling)
|
# unecessary scrolling)
|
||||||
|
@ -151,26 +160,37 @@ def log_show(
|
||||||
filter_irrelevant = True
|
filter_irrelevant = True
|
||||||
|
|
||||||
if filter_irrelevant:
|
if filter_irrelevant:
|
||||||
filters = [
|
|
||||||
r"set [+-]x$",
|
def _filter(lines):
|
||||||
r"set [+-]o xtrace$",
|
filters = [
|
||||||
r"local \w+$",
|
r"set [+-]x$",
|
||||||
r"local legacy_args=.*$",
|
r"set [+-]o xtrace$",
|
||||||
r".*Helper used in legacy mode.*",
|
r"set [+-]o errexit$",
|
||||||
r"args_array=.*$",
|
r"set [+-]o nounset$",
|
||||||
r"local -A args_array$",
|
r"trap '' EXIT",
|
||||||
r"ynh_handle_getopts_args",
|
r"local \w+$",
|
||||||
r"ynh_script_progression",
|
r"local exit_code=(1|0)$",
|
||||||
]
|
r"local legacy_args=.*$",
|
||||||
|
r"local -A args_array$",
|
||||||
|
r"args_array=.*$",
|
||||||
|
r"ret_code=1",
|
||||||
|
r".*Helper used in legacy mode.*",
|
||||||
|
r"ynh_handle_getopts_args",
|
||||||
|
r"ynh_script_progression",
|
||||||
|
r"sleep 0.5",
|
||||||
|
r"'\[' (1|0) -eq (1|0) '\]'$",
|
||||||
|
r"\[?\['? -n '' '?\]\]?$",
|
||||||
|
r"rm -rf /var/cache/yunohost/download/$",
|
||||||
|
r"type -t ynh_clean_setup$",
|
||||||
|
r"DEBUG - \+ echo '",
|
||||||
|
r"DEBUG - \+ exit (1|0)$",
|
||||||
|
]
|
||||||
|
filters = [re.compile(f) for f in filters]
|
||||||
|
return [line for line in lines if not any(f.search(line.strip()) for f in filters)]
|
||||||
else:
|
else:
|
||||||
filters = []
|
def _filter(lines):
|
||||||
|
return lines
|
||||||
|
|
||||||
def _filter_lines(lines, filters=[]):
|
|
||||||
|
|
||||||
filters = [re.compile(f) for f in filters]
|
|
||||||
return [
|
|
||||||
line for line in lines if not any(f.search(line.strip()) for f in filters)
|
|
||||||
]
|
|
||||||
|
|
||||||
# Normalize log/metadata paths and filenames
|
# Normalize log/metadata paths and filenames
|
||||||
abs_path = path
|
abs_path = path
|
||||||
|
@ -209,7 +229,7 @@ def log_show(
|
||||||
content += "\n============\n\n"
|
content += "\n============\n\n"
|
||||||
if os.path.exists(log_path):
|
if os.path.exists(log_path):
|
||||||
actual_log = read_file(log_path)
|
actual_log = read_file(log_path)
|
||||||
content += "\n".join(_filter_lines(actual_log.split("\n"), filters))
|
content += "\n".join(_filter(actual_log.split("\n")))
|
||||||
|
|
||||||
url = yunopaste(content)
|
url = yunopaste(content)
|
||||||
|
|
||||||
|
@ -282,13 +302,13 @@ def log_show(
|
||||||
if os.path.exists(log_path):
|
if os.path.exists(log_path):
|
||||||
from yunohost.service import _tail
|
from yunohost.service import _tail
|
||||||
|
|
||||||
if number and filters:
|
if number and filter_irrelevant:
|
||||||
logs = _tail(log_path, int(number * 4))
|
logs = _tail(log_path, int(number * 4))
|
||||||
elif number:
|
elif number:
|
||||||
logs = _tail(log_path, int(number))
|
logs = _tail(log_path, int(number))
|
||||||
else:
|
else:
|
||||||
logs = read_file(log_path)
|
logs = read_file(log_path)
|
||||||
logs = _filter_lines(logs, filters)
|
logs = list(_filter(logs))
|
||||||
if number:
|
if number:
|
||||||
logs = logs[-number:]
|
logs = logs[-number:]
|
||||||
infos["log_path"] = log_path
|
infos["log_path"] = log_path
|
||||||
|
|
|
@ -423,7 +423,8 @@ class ConfigPanel:
|
||||||
if services_to_reload:
|
if services_to_reload:
|
||||||
logger.info("Reloading services...")
|
logger.info("Reloading services...")
|
||||||
for service in services_to_reload:
|
for service in services_to_reload:
|
||||||
service = service.replace("__APP__", self.app)
|
if hasattr(self, "app"):
|
||||||
|
service = service.replace("__APP__", self.app)
|
||||||
service_reload_or_restart(service)
|
service_reload_or_restart(service)
|
||||||
|
|
||||||
def _iterate(self, trigger=["option"]):
|
def _iterate(self, trigger=["option"]):
|
||||||
|
@ -815,6 +816,14 @@ class UserQuestion(Question):
|
||||||
|
|
||||||
super().__init__(question, user_answers)
|
super().__init__(question, user_answers)
|
||||||
self.choices = user_list()["users"]
|
self.choices = user_list()["users"]
|
||||||
|
|
||||||
|
if not self.choices:
|
||||||
|
raise YunohostValidationError(
|
||||||
|
"app_argument_invalid",
|
||||||
|
name=self.name,
|
||||||
|
error="You should create a YunoHost user first."
|
||||||
|
)
|
||||||
|
|
||||||
if self.default is None:
|
if self.default is None:
|
||||||
root_mail = "root@%s" % _get_maindomain()
|
root_mail = "root@%s" % _get_maindomain()
|
||||||
for user in self.choices.keys():
|
for user in self.choices.keys():
|
||||||
|
@ -897,8 +906,8 @@ class DisplayTextQuestion(Question):
|
||||||
"warning": "yellow",
|
"warning": "yellow",
|
||||||
"danger": "red",
|
"danger": "red",
|
||||||
}
|
}
|
||||||
text = m18n.g(self.style) if self.style != "danger" else m18n.n("danger")
|
prompt = m18n.g(self.style) if self.style != "danger" else m18n.n("danger")
|
||||||
return colorize(text, color[self.style]) + f" {text}"
|
return colorize(prompt, color[self.style]) + f" {text}"
|
||||||
else:
|
else:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue