From d4d03c260ba7f26a89b0a6833d12e3b22af69f17 Mon Sep 17 00:00:00 2001 From: Arnstein Ressem Date: Fri, 15 Dec 2023 10:39:37 +0100 Subject: [PATCH] Add configure container script to AlmaLinux 8 --- dev/almalinux-8/configure-container.sh | 52 ++++++++++++++++++++++ dev/centos-stream8/configure-container.sh | 53 +---------------------- 2 files changed, 53 insertions(+), 52 deletions(-) create mode 100755 dev/almalinux-8/configure-container.sh mode change 100755 => 120000 dev/centos-stream8/configure-container.sh diff --git a/dev/almalinux-8/configure-container.sh b/dev/almalinux-8/configure-container.sh new file mode 100755 index 0000000..9c6b8b4 --- /dev/null +++ b/dev/almalinux-8/configure-container.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +if [ $# -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +engine=$1 +container_name=$2 + +# Add yourself as user +$engine exec -it $container_name bash -c "groupadd -g $(id -g) $(id -gn)" +$engine exec -it $container_name bash -c "useradd -g $(id -g) -u $(id -u) $(id -un)" +$engine exec -it $container_name bash -c "echo '$(id -un) ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers" + +# Ensure home directory has correct owner and group +$engine exec -it $container_name bash -c "chown $(id -u):$(id -g) /home/$(id -un)" + +# Ensure home directory has correct permissions +$engine exec -it $container_name bash -c "chmod 755 /home/$(id -un)" + +# Copy authorized keys +$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c "mkdir -p /home/$(id -un)/.ssh" + +if test -f $HOME/.ssh/authorized_keys; then + $engine cp -a $HOME/.ssh/authorized_keys $container_name:/home/$(id -un)/.ssh/ +elif test -f $HOME/.ssh/id_rsa.pub; then + $engine cp -a $HOME/.ssh/id_rsa.pub $container_name:/home/$(id -un)/.ssh/authorized_keys +elif test -f $HOME/.ssh/id_ed25519.pub; then + $engine cp -a $HOME/.ssh/id_ed25519.pub $container_name:/home/$(id -un)/.ssh/authorized_keys +else + echo "ERROR: No authorized keys found in $HOME/.ssh" + exit 1 +fi + +# Set environment variables +$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c \ +"printf \"%s\n\" \ +'export LC_CTYPE=en_US.UTF-8' \ +'export LC_ALL=en_US.UTF-8' \ +'export VESPA_HOME=\$HOME/vespa' \ +'PATH=\$PATH:\$HOME/bin:\$VESPA_HOME/bin:\$HOME/git/system-test/bin:/opt/vespa-deps/bin' \ +'export PATH' \ +'export MAVEN_OPTS=\"-Xms128m -Xmx1024m\"' \ +'alias ctest=ctest3' \ +> ~/.docker_profile" +$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c \ +"grep -q '.docker_profile' ~/.bash_profile || echo 'test -f ~/.docker_profile && source ~/.docker_profile || true' >> ~/.bash_profile" + +# Adjust ccache max size +$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c "ccache -M 20G" diff --git a/dev/centos-stream8/configure-container.sh b/dev/centos-stream8/configure-container.sh deleted file mode 100755 index 9c6b8b4..0000000 --- a/dev/centos-stream8/configure-container.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -if [ $# -lt 2 ]; then - echo "Usage: $0 " - exit 1 -fi - -engine=$1 -container_name=$2 - -# Add yourself as user -$engine exec -it $container_name bash -c "groupadd -g $(id -g) $(id -gn)" -$engine exec -it $container_name bash -c "useradd -g $(id -g) -u $(id -u) $(id -un)" -$engine exec -it $container_name bash -c "echo '$(id -un) ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers" - -# Ensure home directory has correct owner and group -$engine exec -it $container_name bash -c "chown $(id -u):$(id -g) /home/$(id -un)" - -# Ensure home directory has correct permissions -$engine exec -it $container_name bash -c "chmod 755 /home/$(id -un)" - -# Copy authorized keys -$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c "mkdir -p /home/$(id -un)/.ssh" - -if test -f $HOME/.ssh/authorized_keys; then - $engine cp -a $HOME/.ssh/authorized_keys $container_name:/home/$(id -un)/.ssh/ -elif test -f $HOME/.ssh/id_rsa.pub; then - $engine cp -a $HOME/.ssh/id_rsa.pub $container_name:/home/$(id -un)/.ssh/authorized_keys -elif test -f $HOME/.ssh/id_ed25519.pub; then - $engine cp -a $HOME/.ssh/id_ed25519.pub $container_name:/home/$(id -un)/.ssh/authorized_keys -else - echo "ERROR: No authorized keys found in $HOME/.ssh" - exit 1 -fi - -# Set environment variables -$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c \ -"printf \"%s\n\" \ -'export LC_CTYPE=en_US.UTF-8' \ -'export LC_ALL=en_US.UTF-8' \ -'export VESPA_HOME=\$HOME/vespa' \ -'PATH=\$PATH:\$HOME/bin:\$VESPA_HOME/bin:\$HOME/git/system-test/bin:/opt/vespa-deps/bin' \ -'export PATH' \ -'export MAVEN_OPTS=\"-Xms128m -Xmx1024m\"' \ -'alias ctest=ctest3' \ -> ~/.docker_profile" -$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c \ -"grep -q '.docker_profile' ~/.bash_profile || echo 'test -f ~/.docker_profile && source ~/.docker_profile || true' >> ~/.bash_profile" - -# Adjust ccache max size -$engine exec -u "$(id -u):$(id -g)" -it $container_name bash -c "ccache -M 20G" diff --git a/dev/centos-stream8/configure-container.sh b/dev/centos-stream8/configure-container.sh new file mode 120000 index 0000000..e5f2126 --- /dev/null +++ b/dev/centos-stream8/configure-container.sh @@ -0,0 +1 @@ +../almalinux-8/configure-container.sh \ No newline at end of file