Skip to content

Commit

Permalink
Merge pull request #247 from vespa-engine/toregge/use-shellcheck-for-…
Browse files Browse the repository at this point in the history
…rpm-build-scripts

Use shellcheck for rpm build scripts.
  • Loading branch information
toregge authored Oct 10, 2024
2 parents f285a22 + f325e36 commit 5365df6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
1 change: 1 addition & 0 deletions build/almalinux-8/rpmbuild/build-rpm-inner.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -ex
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# shellcheck source=../../../shared-rpmbuild/build-rpm-inner-common.sh
. /shared-work/build-rpm-inner-common.sh

enable_repos()
Expand Down
2 changes: 1 addition & 1 deletion build/almalinux-8/rpmbuild/build-rpm.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

cd $(cd $(dirname $0) && env pwd)
cd "$(cd "$(dirname "$0")" && env pwd)" || exit 1

. ../../../shared-rpmbuild/build-rpm-common.sh

Expand Down
11 changes: 6 additions & 5 deletions build/almalinux-8/rpmbuild/refresh-test-repo
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

WORKDIR=$(cd $(dirname $0) && env pwd)
cd $WORKDIR
WORKDIR=$(cd "$(dirname "$0")" && env pwd)
cd "$WORKDIR" || exit 1

. ../../../shared/common.sh


if test -f /usr/bin/createrepo_c
then
mkdir -p RPMS/$(arch)
createrepo_c RPMS/$(arch)
mkdir -p "RPMS/$(arch)"
createrepo_c "RPMS/$(arch)"
else
$CONTAINER_ENGINE run --rm -v $WORKDIR:/work docker.io/almalinux:8 bash -c 'dnf -y install createrepo_c && mkdir -p /work/RPMS/$(arch) && createrepo_c /work/RPMS/$(arch) && chown -R --ref /work/build-rpm-inner.sh /work/RPMS'
# shellcheck disable=SC2016
$CONTAINER_ENGINE run --rm -v "$WORKDIR:/work docker.io/almalinux:8" bash -c 'dnf -y install createrepo_c && mkdir -p /work/RPMS/$(arch) && createrepo_c /work/RPMS/$(arch) && chown -R --ref /work/build-rpm-inner.sh /work/RPMS'
fi
29 changes: 17 additions & 12 deletions shared-rpmbuild/build-rpm-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@

run_container()
{
# shellcheck disable=SC2086
$CONTAINER_ENGINE run \
-v $(env pwd):/work \
-v $(cd ../../.. && env pwd)/shared-rpmbuild:/shared-work \
-v $SRC_DIR:/src \
-v "$(env pwd):/work" \
-v "$(cd ../../.. && env pwd)/shared-rpmbuild:/shared-work" \
-v "$SRC_DIR:/src" \
--tmpfs /tmp \
--tmpfs /var/tmp \
--tmpfs /run \
$DOCKER_CREATE_ARGS \
--hostname ${CONTAINER_HOSTNAME} \
--network ${CONTAINER_NETWORK} \
--name ${CONTAINER_NAME} \
--hostname "${CONTAINER_HOSTNAME}" \
--network "${CONTAINER_NETWORK}" \
--name "${CONTAINER_NAME}" \
--privileged \
$CONTAINER_FOREGROUND \
"$CONTAINER_FOREGROUND" \
--init \
${DOCKER_IMAGE} \
"${DOCKER_IMAGE}" \
$CONTAINER_COMMAND $1
}

Expand All @@ -29,11 +30,13 @@ build_rpm_common()
unset CONTAINER_COMMAND
unset CONTAINER_FOREGROUND

args=`getopt amrs $*`
args=$(getopt amrs "$@")
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Usage: build-rpm.sh (-a | -m) [-r] [-s] packagename" 1>&2
exit 1
fi
# shellcheck disable=SC2086
set -- $args
while :; do
case "$1" in
Expand All @@ -59,7 +62,7 @@ build_rpm_common()
;;
*)
SRC_DIR=$HOME/git/vespa-3rdparty-deps
if test -d $SRC_DIR/"$package"
if test -d "$SRC_DIR/$package"
then
:
else
Expand All @@ -86,12 +89,14 @@ build_rpm_common()
;;
esac

# shellcheck source=../shared/common.sh
. ../../../shared/common.sh
# shellcheck disable=2153
CONTAINER_NAME=rpmbuild-${CONTAINER_SHORTNAME}${CONTAINER_SUFFIX}
CONTAINER_HOSTNAME=${CONTAINER_NAME}${DOMAIN_SUFFIX}
VOLUMES=${VOLUMESBASE}/${CONTAINER_NAME}
$CONTAINER_ENGINE stop ${CONTAINER_NAME} || true
$CONTAINER_ENGINE rm ${CONTAINER_NAME} || true
$CONTAINER_ENGINE stop "${CONTAINER_NAME}" || true
$CONTAINER_ENGINE rm "${CONTAINER_NAME}" || true
if test -z "$VOLUMESBASE"
then
DOCKER_CREATE_ARGS="\
Expand Down
21 changes: 13 additions & 8 deletions shared-rpmbuild/build-rpm-inner-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enable_cuda_repos_helper()
aarch64) arch=sbsa;;
*) arch=$cpu_arch;;
esac
dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$distro/$arch/cuda-$distro.repo
dnf config-manager --add-repo "https://developer.download.nvidia.com/compute/cuda/repos/$distro/$arch/cuda-$distro.repo"
}

build_rpm_inner_common()
Expand Down Expand Up @@ -95,9 +95,10 @@ build_rpm_inner_common()
both|srpm)
git config --global --add safe.directory /src
vespaversion=$(cd /src && git tag -l | sed -n -r -e 's,^v([0-9]+\.[0-9]+\.[0-9]+)$,\1,p' | sort -V | tail -1)
( cd /src && ./dist.sh $vespaversion )
( cd /src && ./dist.sh "$vespaversion" )
;;
rebuild)
# shellcheck disable=SC2086
vespaversion=$(cd ~/rpmbuild/SPECS && echo $package-[0-9]*.spec | sed -n -e 's,^'$package'-\([0-9.]*\)\.spec$,\1,p')
if test -z "$vespaversion"
then
Expand All @@ -113,17 +114,19 @@ build_rpm_inner_common()
both|srpm)
SRC=/src-copy
rsync -aHvSx --delete /src/ $SRC/
make -C $SRC/$package -f .copr/Makefile srpm outdir=~/rpmbuild/SRPMS
rm -rf $SRC/$package/.copr/rpmbuild
make -C "$SRC/$package" -f .copr/Makefile srpm outdir=~/rpmbuild/SRPMS
rm -rf "$SRC/$package/.copr/rpmbuild"
;;
esac
case "$mode" in
both|rebuild)
rmdir ~/rpmbuild/SRPMS 2>/dev/null || true
if test -d ~/rpmbuild/SRPMS
then
# shellcheck disable=SC2086
rpm -i ~/rpmbuild/SRPMS/vespa-$package-*.src.rpm
else
# shellcheck disable=SC2086
rpm -i /work/vespa-$package-*.src.rpm
fi
specname=vespa-$package
Expand All @@ -139,22 +142,24 @@ build_rpm_inner_common()
;;
esac
legacy_dnf -y install 'dnf-command(builddep)'
legacy_dnf -y builddep ~/rpmbuild/SPECS/$specname.spec
legacy_dnf -y builddep ~/rpmbuild/SPECS/"$specname".spec
if test -x /usr/bin/go
then
go env -w GOPROXY="https://proxy.golang.org,direct"
mkdir -p ~/tmp
export GOTMPDIR=~/tmp
fi
# shellcheck disable=SC2015
rpm -q ccache >/dev/null 2>&1 && ccache -M 16G || true
( ulimit -Sc 0; rpmbuild -ba ~/rpmbuild/SPECS/$specname.spec )
# shellcheck disable=SC3045
( ulimit -Sc 0; rpmbuild -ba ~/rpmbuild/SPECS/"$specname".spec )
;;
esac
ARCH=$(arch)
mkdir -p /work/RPMS/${ARCH} /work/SRPMS
mkdir -p "/work/RPMS/${ARCH}" /work/SRPMS
case "$mode" in
both|rebuild)
cp -p ~/rpmbuild/RPMS/*/*.rpm /work/RPMS/${ARCH}
cp -p ~/rpmbuild/RPMS/*/*.rpm "/work/RPMS/${ARCH}"
cp -p ~/rpmbuild/SRPMS/*.src.rpm /work/SRPMS
chown --reference=/work/build-rpm-inner.sh -R /work/RPMS /work/SRPMS
rm -rf ~/rpmbuild/*
Expand Down
6 changes: 4 additions & 2 deletions shared/common.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# Common code to get settings

if test -f $HOME/.config/vespa/docker-setups
if test -f "$HOME"/.config/vespa/docker-setups
then
# get default values, e.g.
# CONTAINER_SUFFIX="-mac"
# DOMAIN_SUFFIX=".internal"
# CONTAINER_NETWORK=default
# CONTAINER_ENGINE=podman
# VOLUMESBASE=
. $HOME/.config/vespa/docker-setups
# shellcheck disable=SC1091
. "$HOME"/.config/vespa/docker-setups
fi

if test -z "$CONTAINER_ENGINE"
Expand Down

0 comments on commit 5365df6

Please sign in to comment.