Avoid error output on some tests, no avahi workaround if avahi is already installed

This commit is contained in:
Julien Malik 2015-09-02 00:19:11 +02:00
parent bfe8baaa69
commit 7206d06708

View file

@ -19,11 +19,35 @@ print() {
printf "%s\n" "$*"; printf "%s\n" "$*";
} }
die() { notify_about_install_logs() {
print " print "
Yunohost installation error : Installation logs are located in /var/log/yunohost.log
" 1>&2
$1" 1>&2 }
success() {
tput setf 2
print "
Success !
"
tput sgr 0
notify_about_install_logs
}
die() {
print "\
=================================================="
tput setf 4
print "
Failure !
The following error was caught during Yunohost installation :
$1
" 1>&2
tput sgr 0
notify_about_install_logs
exit ${2:-1} exit ${2:-1}
} }
@ -97,7 +121,7 @@ set_domain() {
# Configure hostname to yunohost.yunohost.org if not already set # Configure hostname to yunohost.yunohost.org if not already set
# NOTE: This is done also during postinstall "to avoid amavis bug" # NOTE: This is done also during postinstall "to avoid amavis bug"
# so we might not need it here # so we might not need it here
[ "$(hostname -d)" != "" ] || hostname yunohost.yunohost.org > /dev/null 2>&1 [ "$(hostname -d > /dev/null 2>&1)" != "" ] || hostname yunohost.yunohost.org > /dev/null 2>&1
} }
confirm_installation() { confirm_installation() {
@ -135,7 +159,7 @@ setup_package_source() {
fi fi
# Add YunoHost repository key to the keyring # Add YunoHost repository key to the keyring
wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq wget -O- http://repo.yunohost.org/yunohost.asc -q | apt-key add - -qq > /dev/null
} }
apt_update() { apt_update() {
@ -155,21 +179,25 @@ register_debconf() {
} }
workaround_avahi_installation() { workaround_avahi_installation() {
# When attempting several installation of Yunohost on the same host # When attempting several installation of Yunohost on the same host
# with a light VM system like LXC # with a light VM system like LXC
# we hit a bug with avahi-daemon postinstallation # we hit a bug with avahi-daemon postinstallation
# This is described in detail in https://github.com/lxc/lxc/issues/25 # This is described in detail in https://github.com/lxc/lxc/issues/25
# #
# It makes the configure step of avahii-daemon fail, because the service does # It makes the configure step of avahi-daemon fail, because the service does
 # start correctly. Then all other packages depending on avahi-daemon refuse to # start correctly. Then all other packages depending on avahi-daemon refuse to
# configure themselves. # configure themselves.
# #
# The workaround we use is to generate a random uid for the avahi user, and # The workaround we use is to generate a random uid for the avahi user, and
# create the user with this id beforehand, so that the avahi-daemon postinst # create the user with this id beforehand, so that the avahi-daemon postinst
# script does not do it on its own. Our randomized uid has far less chances to # script does not do it on its own. Our randomized uid has far less chances to
# be already in use in another system than the automated one (which tries to use # be already in use in another system than the automated one (which tries to use
# consecutive uids). # consecutive uids).
# Return without error if avahi already exists
[ $(id avahi > /dev/null 2>&1) ] || return 0
# Get a random unused uid between 500 and 999 (system-user) # Get a random unused uid between 500 and 999 (system-user)
local avahi_id=$((500 + $RANDOM % 500)) local avahi_id=$((500 + $RANDOM % 500))
while [ $(cat /etc/passwd | cut -d ':' -f 3 | grep $avahi_id) ] ; while [ $(cat /etc/passwd | cut -d ':' -f 3 | grep $avahi_id) ] ;
@ -191,7 +219,10 @@ install_yunohost_packages() {
-- \ -- \
apt-get -o Dpkg::Options::="--force-confold" \ apt-get -o Dpkg::Options::="--force-confold" \
-y install \ -y install \
yunohost yunohost yunohost-config \
yunohost-config-postfix \
postfix postfix-ldap \
postfix-policyd-spf-perl
} }
restart_services() { restart_services() {
@ -205,6 +236,9 @@ restart_services() {
} }
post_install() { post_install() {
# Remove whiptail and dialog remains...
clear
local text=" local text="
Yunohost packages have been installed successfully! Yunohost packages have been installed successfully!
@ -237,7 +271,7 @@ Yunohost post-installation has failed.
Do you want to try again now? Do you want to try again now?
" "
whiptail --title "Post-installation" --yesno "$text_retry" 12 78 --defaultno \ whiptail --title "Post-installation" --yesno "$text_retry" 12 78 --defaultno \
&& return $POSTINSTALL_EXIT_CODE || return $POSTINSTALL_EXIT_CODE
/usr/bin/yunohost tools postinstall /usr/bin/yunohost tools postinstall
POSTINSTALL_EXIT_CODE="$?" POSTINSTALL_EXIT_CODE="$?"
@ -254,47 +288,38 @@ if ! ensure_root ; then
die "This script must be run as root" 1 die "This script must be run as root" 1
fi fi
echo installscript_dependencies
if ! installscript_dependencies ; then if ! installscript_dependencies ; then
die "Unable to install dependencies to install script" 2 die "Unable to install dependencies to install script" 2
fi fi
echo create_custom_config
if ! create_custom_config ; then if ! create_custom_config ; then
die "Creating custom configuration file /etc/yunohost/yunohost.conf failed" 3 die "Creating custom configuration file /etc/yunohost/yunohost.conf failed" 3
fi fi
echo set_domain
if ! set_domain ; then if ! set_domain ; then
die "Setting hostname failed" 4 die "Setting hostname failed" 4
fi fi
echo confirm_installation
if ! confirm_installation ; then if ! confirm_installation ; then
die "Installation cancelled at your request" 5 die "Installation cancelled at your request" 5
fi fi
echo setup_package_source
if ! setup_package_source "$@" ; then if ! setup_package_source "$@" ; then
die "Setting up deb package sources failed" 6 die "Setting up deb package sources failed" 6
fi fi
echo apt_update
if ! apt_update ; then if ! apt_update ; then
die "Error caught during 'apt-get update'" 7 die "Error caught during 'apt-get update'" 7
fi fi
echo register_debconf
if ! register_debconf ; then if ! register_debconf ; then
die "Unable to insert new values into debconf database" 8 die "Unable to insert new values into debconf database" 8
fi fi
echo workaround_avahi_installation
if ! workaround_avahi_installation ; then if ! workaround_avahi_installation ; then
die "Unable to install workaround for avahi installation" 20 die "Unable to install workaround for avahi installation" 20
fi fi
echo install_yunohost_packages
if ! install_yunohost_packages ; then if ! install_yunohost_packages ; then
die "\ die "\
Installation of Yunohost packages failed Installation of Yunohost packages failed
@ -303,16 +328,15 @@ You can check the install logs saved in /var/log/yunohost.log
" 9 " 9
fi fi
echo restart_services
if ! restart_services ; then if ! restart_services ; then
die "Error caught during services restart" 10 die "Error caught during services restart" 10
fi fi
echo post_install
if ! post_install ; then if ! post_install ; then
die "Post-installation failed" 11 die "Post-installation failed" 11
fi fi
# Success ! # Success !
success
exit 0 exit 0