Skip to content

Commit

Permalink
Replace some usage of lxc info to use JSON API
Browse files Browse the repository at this point in the history
Apparently the output format of `lxc info` changed recently. To keep the
detection working, switch to JSON API and use jq to parse the result. Jq
is added as a requisite.
  • Loading branch information
peat-psuwit authored and mardy committed Sep 14, 2021
1 parent 8dafece commit 4d2b345
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crossbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ config_container_dir_mount () {
}

start_container () {
STATUS=`lxc info ${LXD_CONTAINER} | grep 'Status' | awk '{print $2}'`
STATUS=$(lxc query "/1.0/containers/${LXD_CONTAINER}/state" | \
jq --raw-output '.status')
if [ $STATUS = 'Stopped' ]; then
# lxc start may give a failure code. It also may not, so we check
# again in a bit.
Expand All @@ -289,7 +290,8 @@ start_container () {
# Unfortunately we need to check again. We check for Started this time
# because the monitor may be hung with the container failing, which will
# give us much different output
STATUS=`lxc info ${LXD_CONTAINER} | grep 'Status' | awk '{print $2}'`
STATUS=$(lxc query "/1.0/containers/${LXD_CONTAINER}/state" | \
jq --raw-output '.status')
if [ "$STATUS" != 'Running' ]; then
echo $LXD_CONTAINER_FAILURE_MSG
exit 1
Expand Down Expand Up @@ -660,7 +662,9 @@ check_for_container_network() {
NETWORK_UP=0
for i in `seq 1 10`
do
if lxc info $LXD_CONTAINER | grep -e "eth0.*inet\b" > /dev/null 2>&1 ; then
if lxc query "/1.0/containers/${LXD_CONTAINER}/state" | \
jq -e '.network.eth0.addresses | any( .family == "inet" )' \
> /dev/null 2>&1 ; then
NETWORK_UP=1
break
fi
Expand Down Expand Up @@ -802,6 +806,9 @@ fi
if ! which adb > /dev/null ; then
MISSING_PACKAGES="android-tools-adb $MISSING_PACKAGES"
fi
if ! which jq > /dev/null; then
MISSING_PACKAGES="jq $MISSING_PACKAGES"
fi

if [ ! -z "$MISSING_PACKAGES" ] ; then
echo -e "${POSITIVE_COLOR}$PROGRAM_NAME depends on $MISSING_PACKAGES. Installing:${NC}"
Expand Down

0 comments on commit 4d2b345

Please sign in to comment.