mirror of
https://github.com/YunoHost/install_script.git
synced 2024-09-03 20:06:25 +02:00
Rework message / logging system
This commit is contained in:
parent
6cbe6f5399
commit
caef25128e
1 changed files with 39 additions and 39 deletions
|
@ -27,7 +27,7 @@ readonly THIS_MACHINE_RELEASE="$(lsb_release -c | awk '{print $2}')"
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
print "
|
echo "
|
||||||
Usage :
|
Usage :
|
||||||
`basename $0` [-a] [-d <DISTRIB>] [-h]
|
`basename $0` [-a] [-d <DISTRIB>] [-h]
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ function main()
|
||||||
|
|
||||||
step post_install || die "Post-installation failed"
|
step post_install || die "Post-installation failed"
|
||||||
|
|
||||||
# Success !
|
info "Installation logs are available in $YUNOHOST_LOG"
|
||||||
success
|
success "YunoHost installation completed !"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,50 +117,50 @@ function main()
|
||||||
# Helpers #
|
# Helpers #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function print() {
|
readonly normal=$(printf '\033[0m')
|
||||||
printf "%s\n" "$*";
|
readonly bold=$(printf '\033[1m')
|
||||||
|
readonly faint=$(printf '\033[2m')
|
||||||
|
readonly underline=$(printf '\033[4m')
|
||||||
|
readonly negative=$(printf '\033[7m')
|
||||||
|
readonly red=$(printf '\033[31m')
|
||||||
|
readonly green=$(printf '\033[32m')
|
||||||
|
readonly orange=$(printf '\033[33m')
|
||||||
|
readonly blue=$(printf '\033[34m')
|
||||||
|
readonly yellow=$(printf '\033[93m')
|
||||||
|
readonly white=$(printf '\033[39m')
|
||||||
|
|
||||||
|
function success()
|
||||||
|
{
|
||||||
|
local msg=${1}
|
||||||
|
echo "[${green} OK ${normal}] ${msg}" | tee -a $YUNOHOST_LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
function notify_about_install_logs() {
|
function info()
|
||||||
print "
|
{
|
||||||
Installation logs are located in $YUNOHOST_LOG
|
local msg=${1}
|
||||||
" 1>&2
|
echo "[${blue}INFO${normal}] ${msg}" | tee -a $YUNOHOST_LOG
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function success() {
|
function warn()
|
||||||
tput setf 2
|
{
|
||||||
print "Success !"
|
local msg=${1}
|
||||||
tput sgr 0
|
echo "[${orange}WARN${normal}] ${msg}" | tee -a $YUNOHOST_LOG >&2
|
||||||
notify_about_install_logs
|
}
|
||||||
|
|
||||||
|
function error()
|
||||||
|
{
|
||||||
|
local msg=${1}
|
||||||
|
echo "[${red}FAIL${normal}] ${msg}" | tee -a $YUNOHOST_LOG >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
function die() {
|
function die() {
|
||||||
# Print to log file
|
error "$1"
|
||||||
print "
|
info "Installation logs are available in $YUNOHOST_LOG"
|
||||||
Failure !
|
exit 1
|
||||||
The following error was caught during Yunohost installation :
|
|
||||||
|
|
||||||
$1
|
|
||||||
" >> $YUNOHOST_LOG
|
|
||||||
|
|
||||||
# Print to terminal
|
|
||||||
tput setf 4
|
|
||||||
print "Failure !"
|
|
||||||
tput sgr 0
|
|
||||||
|
|
||||||
print "\
|
|
||||||
The following error was caught during YunoHost installation :
|
|
||||||
|
|
||||||
$1
|
|
||||||
" 1>&2
|
|
||||||
|
|
||||||
notify_about_install_logs
|
|
||||||
exit "${2:-1}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function step() {
|
function step() {
|
||||||
printf "[ $(date --rfc-3339=seconds) ] ----- [ entering %-30s ]\n" "$1" >> $YUNOHOST_LOG
|
info "Running $1"
|
||||||
$*
|
$*
|
||||||
local return_code="$?"
|
local return_code="$?"
|
||||||
return $return_code
|
return $return_code
|
||||||
|
@ -339,7 +339,7 @@ function workaround_avahi_installation() {
|
||||||
|
|
||||||
# Return without error if avahi already exists
|
# Return without error if avahi already exists
|
||||||
if id avahi > /dev/null 2>&1 ; then
|
if id avahi > /dev/null 2>&1 ; then
|
||||||
print "User avahi already exists (with uid $(id avahi)), skipping avahi workaround" >> $YUNOHOST_LOG
|
info "User avahi already exists (with uid $(id avahi)), skipping avahi workaround"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ function workaround_avahi_installation() {
|
||||||
avahi_id=$((500 + RANDOM % 500))
|
avahi_id=$((500 + RANDOM % 500))
|
||||||
done
|
done
|
||||||
|
|
||||||
print "Workaround for avahi : creating avahi user with uid $avahi_id" >> $YUNOHOST_LOG
|
info "Workaround for avahi : creating avahi user with uid $avahi_id"
|
||||||
|
|
||||||
# Use the same adduser parameter as in the avahi-daemon postinst script
|
# Use the same adduser parameter as in the avahi-daemon postinst script
|
||||||
# Just specify --uid explicitely
|
# Just specify --uid explicitely
|
||||||
|
|
Loading…
Add table
Reference in a new issue