I have the following bash script:
#!/bin/bash -e
SUDO=sudo
$SUDO apt-get -y update || true
$SUDO apt-get -y install lxc bridge-utils || true
# remove the default bridge, if it exists
DEFAUT_BRIDGE=$(brctl show | grep "lxcbr0")
if ! [ -z "${DEFAULT_BRIDGE}" ]
then
$SUDO ip link set dev lxcbr0 down
$SUDO ip link del dev lxcbr0
fi
# add the WiFi and Mobile bridges, if they don't exist yet
WIFI_BRIDGE=$(brctl show | grep "lxcbr_wifi")
MOBILE_BRIDGE=$(brctl show | grep "lxcbr_wifi")
echo "${MOBILE_BRIDGE}"
echo "${WIFI_BRIDGE}"
if [ -z "${WIFI_BRIDGE}" ]
then
echo "adding wifi bridge"
$SUDO brctl addbr lxcbr_wifi
$SUDO brctl addif lxcbr_wifi $(./network identify wifi)
$SUDO ip link set dev lxcbr_wifi up
fi
if [ -z "${MOBILE_BRIDGE}" ]
then
echo "adding mobile bridge"
$SUDO brctl addbr lxcbr_mobile
$SUDO brctl addif lxcbr_mobile $(./network identify mobile)
$SUDO ip link set dev lxcbr_mobile up
fi
This script fails at the second apt-get command, unless I run the script in debug mode, with the option set -x. I cannot understand why the script is crashing there, since apt-get returns 0 (I checked the value of $? ) and even if it returns an error, I have "|| true".
Weirder, if I run the script in debug mode, everything works. What I am missing ? Is it apt-get fault, or something in the script ?
SUDO=sudo
? – mikeserv Jul 10 at 9:05