summaryrefslogtreecommitdiff
path: root/contrib/containers-common/containers-common.sh
blob: 9e7b445eb73f3e98342555bc51d4b03385cb47da (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
52
53
54
55
56
#!/usr/bin/bash -e
#
# Script used for downloading man pages and config files from
# github.com/containers libraries (storage, common, image)
#
# Must be run from directory containing input specfile
#

die() {
    echo "$(basename $0): $*" >&2
    exit 1
}

branchversion() {
    gomod=$(git rev-parse --show-toplevel)/go.mod
    v=$(awk -v X=github.com/containers/$1 '$1 ~ X { print $2 }' <$gomod)
    hash=$(expr "$v" : "v.*-[0-9.]\+-\([0-9a-f]\+\)")
    if [[ -n "$hash" ]]; then
        v="$hash"
    fi
    echo "$v"
}


SPECFILE=containers-common.spec
if [[ ! -e $SPECFILE.in ]]; then
    die "Please run me from the same directory as $SPECFILE.in"
fi

declare -A moduleversion
for module in common image storage; do
    v=$(branchversion $module)
    if [[ -z "$v" ]]; then
        die "Could not find version for module '$v'"
    fi
    moduleversion[$module]=$v
done

builddir=containers-common-${moduleversion[common]}
mkdir -p $builddir

sed -e "s/COMMON_BRANCH/${moduleversion[common]}/g" \
    -e "s/IMAGE_BRANCH/${moduleversion[image]}/g"  \
    -e "s/STORAGE_BRANCH/${moduleversion[storage]}/g"  \
    <$SPECFILE.in >$builddir/$SPECFILE

cd $builddir
spectool -fg $SPECFILE

if [[ ! -e storage.conf ]]; then
    die "spectool did not pull storage.conf"
fi

echo "Changing storage.conf..."
sed -i -e 's/^driver.*=.*/driver = "overlay"/' -e 's/^mountopt.*=.*/mountopt = "nodev,metacopy=on"/' \
        storage.conf