Reorganize functions + misc stuff

This commit is contained in:
Alexandre Aubin 2018-02-12 23:49:54 +01:00
parent a3f589d9bb
commit 719bbf1095

View file

@ -15,8 +15,112 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
YUNOHOST_LOG="/var/log/yunohost-installation.log"
THIS_MACHINE_RELEASE="$(lsb_release -c | awk '{print $2}')"
set -u
# Globals
readonly YUNOHOST_LOG="/var/log/yunohost-installation.log"
readonly THIS_MACHINE_RELEASE="$(lsb_release -c | awk '{print $2}')"
###############################################################################
# Main functions #
###############################################################################
function usage() {
print "
Usage :
`basename $0` [-a] [-d <DISTRIB>] [-h]
Options :
-a Enable automatic mode. No questions are asked.
This does not perform the post-install step.
-d Choose the distribution to install ('stable', 'testing', 'unstable').
Defaults to 'stable'
-h Prints this help and exit
"
}
function parse_options()
{
AUTOMODE=0
DISTRIB=stable
BUILD_IMAGE=0
while getopts ":aid:h" option; do
case $option in
a)
AUTOMODE=1
export DEBIAN_FRONTEND=noninteractive
;;
d)
DISTRIB=$OPTARG
;;
i)
# This hidden option will allow to build generic image for Rpi/Olimex
BUILD_IMAGE=1
;;
h)
usage
exit 0
;;
:)
usage
exit 1
;;
\?)
usage
exit 1
;;
esac
done
}
function main()
{
parse_options
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"
fi
step upgrade_system || die "Unable to update the system"
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 confirm_installation || die "Installation cancelled at your request"
step setup_package_source || die "Setting up deb package sources failed"
step apt_update || die "Error caught during 'apt-get update'"
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 install_yunohost_packages || die "Installation of Yunohost packages failed"
step restart_services || die "Error caught during services restart"
if is_raspbian ; then
step del_user_pi || die "Unable to delete user pi"
step change_hostname || die "Unable to change hostname"
step setup_firstboot || die "Unable to setup firstboot"
fi
if [[ "$BUILD_IMAGE" == "1" ]] ; then
step clean_image || die "Unable to clean image"
fi
if is_raspbian ; then
# Reboot should be done before postinstall to be able to run iptables rules
reboot
fi
step post_install || die "Post-installation failed"
# Success !
success
exit 0
}
###############################################################################
# Helpers #
###############################################################################
function print() {
printf "%s\n" "$*";
@ -89,6 +193,10 @@ function is_raspbian() {
return 0
}
###############################################################################
# Installation steps #
###############################################################################
function apt_get_wrapper() {
if [[ "$AUTOMODE" == "0" ]] ;
then
@ -406,101 +514,4 @@ Do you want to try again now?
return 0
}
function usage() {
print "
Usage :
`basename $0` [-a] [-d <DISTRIB>] [-h]
Options :
-a Enable automatic mode. No questions are asked.
This does not perform the post-install step.
-d Choose the distribution to install ('stable', 'testing', 'unstable').
Defaults to 'stable'
-h Prints this help and exit
"
}
# Treat unset variables as an error when performing
# parameter expansion. An error message will be written
# to the standard error, and a non-interactive shell will exit.
set -u
function parse_options()
{
AUTOMODE=0
DISTRIB=stable
BUILD_IMAGE=0
while getopts ":aid:h" option; do
case $option in
a)
AUTOMODE=1
export DEBIAN_FRONTEND=noninteractive
;;
d)
DISTRIB=$OPTARG
;;
i)
# This hidden option will allow to build generic image for Rpi/Olimex
BUILD_IMAGE=1
;;
h)
usage
exit 0
;;
:)
usage
exit 1
;;
\?)
usage
exit 1
;;
esac
done
}
function main()
{
parse_options
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"
fi
step upgrade_system || die "Unable to update the system"
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 confirm_installation || die "Installation cancelled at your request"
step setup_package_source || die "Setting up deb package sources failed"
step apt_update || die "Error caught during 'apt-get update'"
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 install_yunohost_packages || die "Installation of Yunohost packages failed"
step restart_services || die "Error caught during services restart"
if is_raspbian ; then
step del_user_pi || die "Unable to delete user pi"
step change_hostname || die "Unable to change hostname"
step setup_firstboot || die "Unable to setup firstboot"
fi
if [[ "$BUILD_IMAGE" == "1" ]] ; then
step clean_image || die "Unable to clean image"
fi
if is_raspbian ; then
# Reboot should be done before postinstall to be able to run iptables rules
reboot
fi
step post_install || die "Post-installation failed"
# Success !
success
exit 0
}
main