summaryrefslogtreecommitdiff
path: root/check-chroots.sh
blob: 79e1df3d6f600095684c9c10226c00cd04730faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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