mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Fix arguments parsing
This commit is contained in:
parent
e3fd48f2ac
commit
23bef139d3
2 changed files with 60 additions and 54 deletions
102
package_check.sh
102
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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue