#!/bin/env bash # ------------------------------------------------------------------------------ # Main program functions # This file is part of the init.sh project # Copyright (c) 2019-2022 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # Read command line and set appropriate vars. Some basic checks can trigger # errors with immediate exit. read_commandline() { # Processing command line options local opt= local params='' params=$(getopt -n init.sh -o hvm:cjkrRDoPl:f:s \ --long help,version,module:,check-only,jump,keep-going,resume,no-root-check,no-deps,offline,no-proxy,logfile:,file:,shell,chroot,cron \ -- "$@") eval set -- "$params" while true; do case $1 in "-h"|"--help") disp_help shift exit 0 ;; "-v"|"--version") show_version shift exit 0 ;; "-m"|"--module") if [[ -z $MANUAL_MODULE_LIST ]]; then export MANUAL_MODULE_LIST="$2" else prnt E "A module list have already been given!" prnt E "Commande line only tolerate one --module parameter." die 1 --force fi shift 2 ;; "-c"|"--check-only") export CHECK_ONLY=true shift ;; "-j"|"--jump") export JUMP=true shift ;; "-k"|"--keep-going") export KEEPGOING=true shift ;; "-r"|"--resume") if [[ -s $STAGE_FILE ]]; then export RESUME=true else prnt E "The status file doesn't exists or is empty!" prnt E "Without it, resuming is impossible." die 17 --force fi shift ;; "-R"|"--no-root-check") export NO_ROOT_CHECK=true shift ;; "-D"|"--no-deps") export NO_DEPS=true shift ;; "-o"|"--offline") export OFFLINE=true shift ;; "-P"|"--no-proxy") export NO_PROXY=true shift ;; "-l"|"--logfile") if [[ -z $NEW_LOGFILE ]]; then export NEW_LOGFILE=$2 else prnt E "Impossible to specify several log files." die 1 --force fi shift 2 ;; "-f"|"--file") export CONFFILES="$CONFFILES $2" shift 2 ;; "-s"|"--shell") export RUN_SHELL=true shift ;; "--chroot") if [[ -z $CHROOT_PATH ]]; then export CHROOT_PATH=$2 else prnt E "A chroot path have already been given." die 1 --force fi shift 2 ;; "--cron") export CRON_MODE=true shift ;; --) shift break ;; *) if [[ -n $1 ]]; then prnt E "Unknow parameter \"$1\" !" die 1 fi break ;; esac done unset opt } export -f read_commandline # ------------------------------------------------------------------------------ # Do deeper command line analysis to detect unconsistancies process_commandline_and_vars() { # Check unconsistant parameters if [[ $CHECK_ONLY == true ]]; then if [[ $JUMP == true ]]; then prnt E "The options --check-only and --jump are mutually exclusive!" die 1 --force fi if [[ $KEEPGOING == true ]]; then prnt E "The options --keep-going and --check-only are not compatible!" die 1 --force fi fi if [[ $RESUME == true ]]; then if [[ $CHECK_ONLY == true ]]; then prnt E "Resuming doesn't make sense with --check-only." die 1 --force fi if [[ -n $MANUAL_MODULE_LIST ]]; then prnt E "Resume mode can't work with a manual module list." die 1 --force fi fi if [[ $CRON_MODE == true ]]; then if [[ $CHECK_ONLY == true || $JUMP == true ]]; then prnt E "Some parameters are incompatible with cron mode." die 16 --force fi fi # Configure module list if [[ -n $MANUAL_MODULE_LIST ]]; then prnt W "A manual module list will be used:" export MODULE_LIST=${MANUAL_MODULE_LIST//,/ } prnt m " * $MODULE_LIST" fi # Check for module list exis