Wrap option parsing and main into functions

This commit is contained in:
Alexandre Aubin 2018-02-12 23:41:34 +01:00
parent 370a12e544
commit a3f589d9bb

View file

@ -425,10 +425,13 @@ Options :
# to the standard error, and a non-interactive shell will exit. # to the standard error, and a non-interactive shell will exit.
set -u set -u
AUTOMODE=0 function parse_options()
DISTRIB=stable {
BUILD_IMAGE=0 AUTOMODE=0
while getopts ":aid:h" option; do DISTRIB=stable
BUILD_IMAGE=0
while getopts ":aid:h" option; do
case $option in case $option in
a) a)
AUTOMODE=1 AUTOMODE=1
@ -454,42 +457,50 @@ while getopts ":aid:h" option; do
exit 1 exit 1
;; ;;
esac esac
done done
}
step ensure_root || die "This script must be run as root" function main()
{
parse_options
if is_raspbian ; then step ensure_root || die "This script must be run as root"
if is_raspbian ; then
step ensure_pi_logout || die "The user pi should be logged out" step ensure_pi_logout || die "The user pi should be logged out"
fi fi
step upgrade_system || die "Unable to update the system" step upgrade_system || die "Unable to update the system"
step installscript_dependencies || die "Unable to install dependencies to install script" step installscript_dependencies || die "Unable to install dependencies to install script"
step create_custom_config || die "Creating custom configuration file /etc/yunohost/yunohost.conf failed" step create_custom_config || die "Creating custom configuration file /etc/yunohost/yunohost.conf failed"
step confirm_installation || die "Installation cancelled at your request" step confirm_installation || die "Installation cancelled at your request"
step setup_package_source || die "Setting up deb package sources failed" step setup_package_source || die "Setting up deb package sources failed"
step apt_update || die "Error caught during 'apt-get update'" step apt_update || die "Error caught during 'apt-get update'"
step register_debconf || die "Unable to insert new values into debconf database" step register_debconf || die "Unable to insert new values into debconf database"
step workaround_avahi_installation || die "Unable to install workaround for avahi installation" step workaround_avahi_installation || die "Unable to install workaround for avahi installation"
step install_yunohost_packages || die "Installation of Yunohost packages failed" step install_yunohost_packages || die "Installation of Yunohost packages failed"
step restart_services || die "Error caught during services restart" step restart_services || die "Error caught during services restart"
if is_raspbian ; then if is_raspbian ; then
step del_user_pi || die "Unable to delete user pi" step del_user_pi || die "Unable to delete user pi"
step change_hostname || die "Unable to change hostname" step change_hostname || die "Unable to change hostname"
step setup_firstboot || die "Unable to setup firstboot" step setup_firstboot || die "Unable to setup firstboot"
fi fi
if [[ "$BUILD_IMAGE" == "1" ]] ; then if [[ "$BUILD_IMAGE" == "1" ]] ; then
step clean_image || die "Unable to clean image" step clean_image || die "Unable to clean image"
fi fi
if is_raspbian ; then if is_raspbian ; then
# Reboot should be done before postinstall to be able to run iptables rules # Reboot should be done before postinstall to be able to run iptables rules
reboot reboot
fi fi
step post_install || die "Post-installation failed" step post_install || die "Post-installation failed"
# Success ! # Success !
success success
exit 0 exit 0
}
main