From 23bef139d34935905835c03e6432b19713da740c Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Tue, 4 Apr 2017 11:39:43 +0200 Subject: [PATCH] Fix arguments parsing --- package_check.sh | 102 +++++++++++++++++++++------------------- sub_scripts/launcher.sh | 12 ++--- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/package_check.sh b/package_check.sh index 854b6ac..a278db1 100755 --- a/package_check.sh +++ b/package_check.sh @@ -15,7 +15,7 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$( clean_exit () { # Exit and remove all temp files # $1 = exit code - + # Deactivate LXC network LXC_TURNOFF @@ -67,53 +67,59 @@ else arguments=${arguments//--bash-mode/-y} # Read and parse all the arguments - while [ $# -ne 0 ] - do - # Initialize the index of getopts - OPTIND=1 - # Parse with getopts only if the argument begin by - - if [ ${1:0:1} = "-" ] - then - getopts ":b:fihly " parameter - case $parameter in - b) - # --branch=branch-name - gitbranch="$OPTARG" - ;; - f) - # --force-install-ok - force_install_ok=1 - ;; - i) - # --interrupt - interrupt=1 - ;; - h) - # --help - notice=1 - ;; - l) - # --build-lxc - build_lxc=1 - ;; - y) - # --bash-mode - bash_mode=1 - ;; - \?) - echo "Invalid argument: -$OPTARG" >&2 - notice=1 - ;; - :) - echo "-$OPTARG parameter requires an argument." >&2 - notice=1 - ;; - esac - else - app_arg="$1" - fi - shift - done + # Use a function here, to use standart arguments $@ and use more simply getopts and shift. + parse_arg () { + while [ $# -ne 0 ] + do + # Initialize the index of getopts + OPTIND=1 + # Parse with getopts only if the argument begin by - + if [ ${1:0:1} = "-" ] + then + getopts ":b:fihly " parameter + case $parameter in + b) + # --branch=branch-name + gitbranch="$OPTARG" + ;; + f) + # --force-install-ok + force_install_ok=1 + ;; + i) + # --interrupt + interrupt=1 + ;; + h) + # --help + notice=1 + ;; + l) + # --build-lxc + build_lxc=1 + ;; + y) + # --bash-mode + bash_mode=1 + ;; + \?) + echo "Invalid argument: -$OPTARG" >&2 + notice=1 + ;; + :) + echo "-$OPTARG parameter requires an argument." >&2 + notice=1 + ;; + esac + else + app_arg="$1" + fi + shift + done + } + + # Call parse_arg and pass the modified list of args. + parse_arg $arguments fi # Prevent a conflict between --interrupt and --bash-mode diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh index b106613..17ac702 100755 --- a/sub_scripts/launcher.sh +++ b/sub_scripts/launcher.sh @@ -82,7 +82,7 @@ LXC_START () { break fi - # Failed if the container failed to start + # Fail if the container failed to start if [ $i -eq $max_try ] && [ $failstart -eq 1 ] then ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "red" "bold" @@ -92,7 +92,7 @@ LXC_START () { fi done - # Count the number of line of the current yunohost log file. + # Count the number of lines of the current yunohost log file. COPY_LOG 1 # Copy the package into the container. @@ -142,9 +142,9 @@ LXC_STOP () { } LXC_TURNOFF () { - # Deactivate LXC network + # Disable LXC network - echo "Deactivate iptables rules." + echo "Disable iptables rules." if sudo iptables --check FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT 2> /dev/null then sudo iptables --delete FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT >> "$test_result" 2>&1 @@ -158,7 +158,7 @@ LXC_TURNOFF () { sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 fi - echo "Deactivate the network bridge." + echo "Disable the network bridge." if sudo ifquery $lxc_bridge --state > /dev/null then sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1 @@ -168,7 +168,7 @@ LXC_TURNOFF () { LXC_CONNECT_INFO () { # Print access information - echo "> For access the container:" + echo "> To access the container:" echo "To execute one command:" echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m"