diff options
author | Simon Rettberg | 2013-02-26 18:49:21 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-02-26 18:49:21 +0100 |
commit | bccbda5a0d09d5218db2c7af339794a7eb6ee598 (patch) | |
tree | 31521f2bf4a4e302166dcb538aa2dc0a92b8c388 /mltk | |
parent | Added dependency system for modules (REQUIRED_MODULES var in *.conf of module... (diff) | |
download | tm-scripts-bccbda5a0d09d5218db2c7af339794a7eb6ee598.tar.gz tm-scripts-bccbda5a0d09d5218db2c7af339794a7eb6ee598.tar.xz tm-scripts-bccbda5a0d09d5218db2c7af339794a7eb6ee598.zip |
Implemented more flexible command line parsing
Diffstat (limited to 'mltk')
-rwxr-xr-x | mltk | 170 |
1 files changed, 103 insertions, 67 deletions
@@ -16,8 +16,8 @@ # # ----------------------------------------------------------------------------- -SELF=$(readlink -f $0) -ROOT_DIR=$(dirname ${SELF}) +SELF="$(readlink -f $0)" +ROOT_DIR="$(dirname "${SELF}")" MLTK_PID="$$" qnd_exit() { @@ -45,21 +45,27 @@ banner () { print_usage() { echo "Toolkit for creating preboot mini-linux for OpenSLX NG (mltk)" - echo "Usage: $(basename ${SELF}) MODULE [OPTIONS]" + echo "Usage: $(basename ${SELF}) --[target] [-b] [-c] [-d] [module]*" echo -e "" - echo -e " MODULE:" - echo -e " core \t minimal initramfs (stage 3.1) to mount the system-container (stage 3.2)." - echo -e " tools \t minimal systemd-based rootfs including basic tools." - echo -e " all \t all of the above." + echo -e " Target:" + echo -e " --core \t minimal initramfs (stage 3.1) to mount the system-container (stage 3.2)." + echo -e " --tools \t minimal systemd-based rootfs including basic tools (required for --core)." echo -e "" - echo -e " OPTIONS:" - echo -e " build, -b \t builds [MODULE]" - echo -e " clean, -c \t clean build files for [MODULE]" - echo -e " debug, -d \t activates debug output." + echo -e " Target options:" + echo -e " -b \t build current target" + echo -e " -c \t clean current target" + echo -e " -d \t activates debug output for current target" echo -e "" - echo -e " Module specific options:" - echo -e " tools [OPTION] [TOOL]" - echo -e " TOOL can be: \t $(echo $(ls ${ROOT_DIR}/remote/tools))" + echo -e " For target tools, you can pass names of specific modules to clean/build." + echo -e " Otherwise, all modules will be built/cleaned." + echo -e "" + echo -e " Examples:" + echo -e " --tools -c -b base policykit sshd (clean all tools, build base, policykit and sshd)" + echo -e " --core -c -b --tools -c -b (clean all tools, build all tools, clean core, build core)" + echo -e " --tools -c base sshd -b sshd, ldm (clean base and sshd, build sshd and ldm, be verbose)" + echo -e "" + echo -e " Existing modules for --tools are:" + echo -e " $(echo $(ls ${ROOT_DIR}/remote/tools))" } initial_checks() { @@ -71,74 +77,104 @@ initial_checks() { fi # setup_tools and build_core - BUILD_CORE=${ROOT_DIR}/server/build_core - SETUP_TOOLS=${ROOT_DIR}/remote/setup_tools + BUILD_CORE="${ROOT_DIR}/server/build_core" + SETUP_TOOLS="${ROOT_DIR}/remote/setup_tools" - [ ! -e ${BUILD_CORE} ] && echo "Missing script build_core, re-clone. Exiting." && exit 1 - [ ! -e ${SETUP_TOOLS} ] && echo "Missing script setup_tools, re-clone. Exiting." && exit 1 + [ ! -e "${BUILD_CORE}" ] && perror "Missing script build_core, re-clone. Exiting." + [ ! -e "${SETUP_TOOLS}" ] && perror "Missing script setup_tools, re-clone. Exiting." } read_params() { - MODULE=$1 - case "$1" in - core) - TARGET_CORE=1 - ;; - tools) - TARGET_TOOLS=1 - ;; - all) - TARGET_CORE=1 - TARGET_TOOLS=1 - ;; - *) - print_usage - exit 1 - ;; - esac - shift - - while true ; do - case "$1" in - -c|clean) - CLEAN=1 - shift - ;; - -b|build) - BUILD=1 - shift - ;; - -d|debug) - DEBUG=1 - shift - ;; - *) - break - ;; - esac + local MODE="" + local SUBMODE="" + while [ "$#" -gt "0" ]; do + local PARAM="$1" + shift + + # select target: core or tools + if [[ "$PARAM" == "--"* ]]; then + case "$PARAM" in + --core) + MODE="CORE" + ;; + --tools) + MODE="TOOLS" + ;; + *) + pwarning "Unknown target: $PARAM" + print_usage + exit 1 + ;; + esac + SUBMODE="" + continue + fi + + [ "x$MODE" = "x" ] && pwarning "Cannot handle param $PARAM - no target selected yet" && print_usage && exit 1 + + # options to current target + if [[ "$PARAM" == "-"* ]]; then + case "$PARAM" in + -c) + SUBMODE="CLEAN" + ;; + -b) + SUBMODE="BUILD" + ;; + -d) + eval ${MODE}_DEBUG="1" + continue + ;; + *) + pwarning "Unknown flag to target: $PARAM" + print_usage + exit 1 + ;; + esac + eval ${MODE}_${SUBMODE}="1" + continue + fi + + # module name + [[ $MODE != TOOLS ]] && pwarning "You cannot specify module names for target CORE." && print_usage && exit 1 + [[ $SUBMODE != CLEAN && $SUBMODE != BUILD ]] && pwarning "Module name given for --tools, but no action specified (eg. build)" && print_usage && exit 1 + eval "${MODE}_LIST_${SUBMODE}=\"\$${MODE}_LIST_${SUBMODE} \$PARAM\"" done + #pinfo "tools clean: $TOOLS_CLEAN -$TOOLS_LIST_CLEAN" + #pinfo "tools build: $TOOLS_BUILD -$TOOLS_LIST_BUILD" + #pinfo "core clean: $CORE_CLEAN" + #pinfo "core build: $CORE_BUILD" + # exit if no command - [ "x$BUILD" = "x" -a "x$CLEAN" = "x" ] && print_usage && exit 1 - - TOOLS="$@" + [[ $CORE_CLEAN == 0 && $CORE_BUILD == 0 && $TOOLS_CLEAN == 0 && $TOOLS_BUILD == 0 ]] && print_usage && exit 1 } run() { - [ "x$DEBUG" != "x1" ] && set_quiet - if [ $TARGET_TOOLS ]; then - . ${SETUP_TOOLS} - [ $CLEAN ] && clean_tools $TOOLS - [ $BUILD ] && generate_stage32 $TOOLS + if [[ $TOOLS_CLEAN == 1 || $TOOLS_BUILD == 1 ]]; then + [[ $TOOLS_DEBUG == 1 ]] && unset_quiet || set_quiet + . "${SETUP_TOOLS}" || perror "Cannot source ${SETUP_TOOLS}" + [[ $TOOLS_CLEAN == 1 ]] && clean_tools $TOOLS_LIST_CLEAN + [[ $TOOLS_BUILD == 1 ]] && generate_stage32 $TOOLS_LIST_BUILD fi - if [ $TARGET_CORE ]; then + if [[ $CORE_CLEAN == 1 || $CORE_BUILD == 1 ]]; then + [[ $CORE_DEBUG == 1 ]] && unset_quiet || set_quiet local TOOL_STR="[CORE]" - . ${BUILD_CORE} - [ $CLEAN ] && clean_core - [ $BUILD ] && generate_stage31 + . "${BUILD_CORE}" || perror "Cannot source ${BUILD_CORE}" + [[ $CORE_CLEAN == 1 ]] && clean_core + [[ $CORE_BUILD == 1 ]] && generate_stage31 fi } +CORE_DEBUG="0" +CORE_BUILD="0" +CORE_CLEAN="0" +TOOLS_DEBUG="0" +TOOLS_CLEAN="0" +TOOLS_BUILD="0" +TOOLS_LIST_CLEAN="" +TOOLS_LIST_BUILD="" + initial_checks read_params $@ |