Fix arguments parsing

This commit is contained in:
Maniack Crudelis 2017-04-04 11:39:43 +02:00
parent e3fd48f2ac
commit 23bef139d3
2 changed files with 60 additions and 54 deletions

View file

@ -15,7 +15,7 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(
clean_exit () { clean_exit () {
# Exit and remove all temp files # Exit and remove all temp files
# $1 = exit code # $1 = exit code
# Deactivate LXC network # Deactivate LXC network
LXC_TURNOFF LXC_TURNOFF
@ -67,53 +67,59 @@ else
arguments=${arguments//--bash-mode/-y} arguments=${arguments//--bash-mode/-y}
# Read and parse all the arguments # Read and parse all the arguments
while [ $# -ne 0 ] # Use a function here, to use standart arguments $@ and use more simply getopts and shift.
do parse_arg () {
# Initialize the index of getopts while [ $# -ne 0 ]
OPTIND=1 do
# Parse with getopts only if the argument begin by - # Initialize the index of getopts
if [ ${1:0:1} = "-" ] OPTIND=1
then # Parse with getopts only if the argument begin by -
getopts ":b:fihly " parameter if [ ${1:0:1} = "-" ]
case $parameter in then
b) getopts ":b:fihly " parameter
# --branch=branch-name case $parameter in
gitbranch="$OPTARG" b)
;; # --branch=branch-name
f) gitbranch="$OPTARG"
# --force-install-ok ;;
force_install_ok=1 f)
;; # --force-install-ok
i) force_install_ok=1
# --interrupt ;;
interrupt=1 i)
;; # --interrupt
h) interrupt=1
# --help ;;
notice=1 h)
;; # --help
l) notice=1
# --build-lxc ;;
build_lxc=1 l)
;; # --build-lxc
y) build_lxc=1
# --bash-mode ;;
bash_mode=1 y)
;; # --bash-mode
\?) bash_mode=1
echo "Invalid argument: -$OPTARG" >&2 ;;
notice=1 \?)
;; echo "Invalid argument: -$OPTARG" >&2
:) notice=1
echo "-$OPTARG parameter requires an argument." >&2 ;;
notice=1 :)
;; echo "-$OPTARG parameter requires an argument." >&2
esac notice=1
else ;;
app_arg="$1" esac
fi else
shift app_arg="$1"
done fi
shift
done
}
# Call parse_arg and pass the modified list of args.
parse_arg $arguments
fi fi
# Prevent a conflict between --interrupt and --bash-mode # Prevent a conflict between --interrupt and --bash-mode

View file

@ -82,7 +82,7 @@ LXC_START () {
break break
fi fi
# Failed if the container failed to start # Fail if the container failed to start
if [ $i -eq $max_try ] && [ $failstart -eq 1 ] if [ $i -eq $max_try ] && [ $failstart -eq 1 ]
then 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" 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 fi
done 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_LOG 1
# Copy the package into the container. # Copy the package into the container.
@ -142,9 +142,9 @@ LXC_STOP () {
} }
LXC_TURNOFF () { 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 if sudo iptables --check FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT 2> /dev/null
then then
sudo iptables --delete FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT >> "$test_result" 2>&1 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 sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
fi fi
echo "Deactivate the network bridge." echo "Disable the network bridge."
if sudo ifquery $lxc_bridge --state > /dev/null if sudo ifquery $lxc_bridge --state > /dev/null
then then
sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1 sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1
@ -168,7 +168,7 @@ LXC_TURNOFF () {
LXC_CONNECT_INFO () { LXC_CONNECT_INFO () {
# Print access information # Print access information
echo "> For access the container:" echo "> To access the container:"
echo "To execute one command:" echo "To execute one command:"
echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m" echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m"