2021-03-25 16:47:22 +01:00
#!/bin/bash
# -------------------------------------------------------------------------- #
2024-07-29 14:25:20 +02:00
# Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
2021-03-25 16:47:22 +01:00
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
set -e -o pipefail
if [ "$1" == '--help' ]; then
cat - >&2 <<EOF
Usage: $(basename "$0") [distro1 [distro2 ...]]
SYNOPSIS
Regenerates Gemfile.locks for each distribution/version, distribution
identificator corresponds to the directory name. When started without
any parameter, refreshes all targets. To limit functionality only
on specific targets, pass the distribution identificators as arguments
on the command line.
IMPORTANT: Requires working Docker or Podman (with podman-docker wrapper)!
2023-10-11 10:29:31 +02:00
IMPORTANT: Requires following vars to be exported: RHEL_USER, RHEL_PASSWORD and RHEL_POOL_ID
2021-03-25 16:47:22 +01:00
EXAMPLES
$(basename "$0") - updates all distributions
$(basename "$0") CentOS8 Ubuntu2004 - updates only specified ones
EOF
exit 1
fi
if ! docker image ls &>/dev/null; then
echo 'ERROR: Requires working Docker (Podman)' >&2
exit 1
fi
# Whole current repository will be passed into build
GIT_DIR=$(readlink -f "$(dirname "$0")/../../")
cd "${GIT_DIR}/share/install_gems/"
# Specify targets as argument or take all
DIRS=$*
DIRS=${DIRS:-$(ls -d */)}
for DIR in $DIRS; do
TARGET=${DIR%%/}
TARGET=${TARGET,,}
# guess container image and tag
DOCKER_IMAGE=${TARGET%%[0-9]*}
2023-10-11 10:21:10 +02:00
[[ -e "$DIR/IMAGE" ]] && DOCKER_IMAGE=$(cat "$DIR/IMAGE")
2021-03-25 16:47:22 +01:00
DOCKER_TAG=${TARGET##${DOCKER_IMAGE}}
2023-10-11 10:21:10 +02:00
[[ -e "$DIR/TAG" ]] && DOCKER_TAG=$(cat "$DIR/TAG")
2021-03-25 16:47:22 +01:00
case "${DOCKER_IMAGE}" in
ubuntu)
DOCKER_TAG=$(echo "${DOCKER_TAG}" | sed -e 's/^\([0-9][0-9]\)/\1./')
;;
esac
echo "--- Platform ${TARGET} (${DOCKER_IMAGE}:${DOCKER_TAG})"
2022-11-14 20:48:30 +01:00
docker run --rm -v "${GIT_DIR}:/git:z" -i "${DOCKER_IMAGE}:${DOCKER_TAG}" bash -s <<EOF
2021-03-25 16:47:22 +01:00
set -xe -o pipefail
export LC_ALL=C
# install/remove essential packages
if command -v dpkg >/dev/null; then
apt-get update -qq
apt-get install -y ruby >/dev/null
dpkg -r ruby-bundler
elif command -v rpm >/dev/null; then
2023-10-11 10:21:10 +02:00
if grep -m1 '^Red Hat' /etc/redhat-release; then
export SMDEV_CONTAINER_OFF=1
subscription-manager register --username ${RHEL_USER} \
--password ${RHEL_PASSWORD} \
--force
subscription-manager attach --pool=${RHEL_POOL_ID}
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms ||:
subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms ||:
2022-10-14 19:42:58 +02:00
fi
2021-03-25 16:47:22 +01:00
if command -v dnf >/dev/null; then
2024-07-17 16:19:49 +02:00
dnf -q -y --nogpgcheck upgrade almalinux-release ||:
2021-03-25 16:47:22 +01:00
dnf -q -y install 'dnf-command(config-manager)'
2022-10-14 19:42:58 +02:00
dnf config-manager --set-enabled powertools ||:
dnf config-manager --set-enabled crb ||: # alma9
2021-03-25 16:47:22 +01:00
fi
yum -q -y install rubygems findutils
yum -q -y remove rubygem-bundler
fi
2024-04-30 14:40:10 +02:00
# install Bundler
2021-03-25 16:47:22 +01:00
find /usr -name 'bundler*.gemspec' -delete
export PATH=\$PATH:/usr/local/bin
2024-04-30 14:40:10 +02:00
# use latest bundler since ruby 3.2
if ruby -e 'Gem::Version.new(\`ruby --version | cut -d " " -f2\`) > Gem::Version.new("3.2") ? exit(0) : exit(1)'; then
gem install bundler --no-document --quiet
else
gem install bundler -v '<2' --no-document --quiet
fi
2021-03-25 16:47:22 +01:00
# install OpenNebula
mkdir -p /run/lock
cd /git
if ! ./install.sh &>/tmp/install.out; then
cat /tmp/install.out
exit 1
fi
# install gems, check version in lock and copy back
/usr/share/one/install_gems
VERSION=\$(tail -1 /usr/share/one/Gemfile.lock | sed -e 's/\s*//')
2024-04-30 14:40:10 +02:00
echo "Generated with Bundler version \$VERSION"
2021-03-25 16:47:22 +01:00
mkdir -p /git/share/install_gems/${DIR}/
\\cp -f /usr/share/one/Gemfile.lock /git/share/install_gems/${DIR}/
2023-10-11 10:21:10 +02:00
# unsubscribe
subscription-manager remove --all ||:
2021-03-25 16:47:22 +01:00
exit 0
EOF
echo
done