#!/usr/bin/env bash set -eu dirname=$(dirname "$0") function error() { echo "ERROR: $1" >&2 ; exit 1; } function info() { echo "INFO: $1"; } CHROOT_LIST_FILES="$*" [[ -n $CHROOT_LIST_FILES ]] || error "no chroot list file specified" WORKSPACE=${WORKSPACE:-$PWD/workspace} WORKDIR=${WORKSPACE}/workdir mkdir -p $WORKSPACE rm -rf $WORKSPACE/workdir mkdir -p $WORKSPACE/workdir cat $CHROOT_LIST_FILES >$WORKDIR/chroots_expected.txt schroot --all -l >$WORKDIR/chroots_actual.txt CHROOT_LIST=$(cat $WORKDIR/chroots_expected.txt | tr '\n' ' ') [[ -n $CHROOT_LIST ]] || error "no chroot specified" declare -i missing_num=0 declare missing_list="" info "----------" info "Checking availability of chroots: $CHROOT_LIST" for chroot in $CHROOT_LIST; do declare missing=false chroot=$(echo "$chroot" | sed -e 's/ *#.*//' -e 's/^ *//') [[ -n $chroot ]] || continue grep -q "$chroot" $WORKDIR/chroots_actual.txt || missing=true $missing && echo "ERROR: missing chroot: $chroot" $missing && missing_num=$((missing_num + 1)) $missing && missing_list="$missing_list $chroot" done if [[ $missing_num -gt 0 ]]; then echo "ERROR: $missing_num chroots missing" echo "Expected chroot list: $(echo $CHROOT_LIST)" echo "Please install the missing chroots:" echo "$missing_list" exit 1 else echo "SUCCESS: all chroots installed" fi