update scripts for test machines

[skip ci]
This commit is contained in:
Laurent Rineau
2026-06-25 11:47:44 +02:00
parent 849bb2c539
commit d6b74a797d
2 changed files with 132 additions and 38 deletions
@@ -18,8 +18,9 @@ machine_info() {
HOST=$1
remote_script=$(printf "export PS4='+ %s >> %s'\n" "$HOST" "$PS4")$'\n'$(
cat <<'EOF'
source /etc/os-release
printf '\n- OS: `%s`\n- container implementation: `%s`\n' "$PRETTY_NAME" "$(docker --version)"
source /usr/lib/os-release
printf '\n- OS: `%s`\n- kernel: `%s`\n- container implementation: `%s`\n' "$PRETTY_NAME" "$(uname -r)" "$(docker --version)"
EOF
)
ssh "$HOST" bash -$- -s <<<"$remote_script"
@@ -149,6 +150,10 @@ machine_check_updates() {
ssh "$1" bash -$- -s <<<"$remote_script"
}
machine_run_command() {
ssh "$1" bash -$- -s <<<"$2"
}
help() {
cat <<HEREDOC
Usage: $0 [OPTION]
@@ -169,6 +174,7 @@ Information Options:
--containers list the containers running on each machine
--info list the OS and the container implementation on each machine
--updates list the available security updates on each machine
--run CMD run CMD on each machine using ssh
If no information option is given, the script will list all the information.
HEREDOC
@@ -186,16 +192,6 @@ command -v sed >/dev/null || {
error_out 'sed is required'
}
if [[ $1 == --table ]] && ! command -v pandoc >/dev/null; then
error_out 'pandoc is required for the option --table'
fi
if [[ $1 == --column ]] && ! command -v column >/dev/null; then
error_out 'column is required for the option --column'
fi
if [[ $1 == --bat ]] && ! command -v bat >/dev/null; then
error_out 'bat is required for the option --bat'
fi
set_pretty_csv_to_md_table() {
pretty_csv() (
echo
@@ -230,6 +226,7 @@ set_pretty_csv_to_cat() {
}
WHAT=()
RUN_COMMAND=
add_to_what() {
for i in "$@"; do
@@ -247,22 +244,62 @@ what_contains() {
return 1
}
for arg in "$@"; do
case "$arg" in
--table) set_pretty_csv_to_md_table ;;
--column) set_pretty_csv_to_column ;;
--bat) set_pretty_csv_to_bat ;;
--plain) set_pretty_csv_to_cat ;;
--images) add_to_what images ;;
--containers) add_to_what containers ;;
--updates) add_to_what updates ;;
--info) add_to_what info ;;
while [[ $# -gt 0 ]]; do
case "$1" in
--table)
command -v pandoc >/dev/null || error_out 'pandoc is required for the option --table'
set_pretty_csv_to_md_table
shift
;;
--column)
command -v column >/dev/null || error_out 'column is required for the option --column'
set_pretty_csv_to_column
shift
;;
--bat)
command -v bat >/dev/null || error_out 'bat is required for the option --bat'
set_pretty_csv_to_bat
shift
;;
--plain)
set_pretty_csv_to_cat
shift
;;
--images)
add_to_what images
shift
;;
--containers)
add_to_what containers
shift
;;
--updates)
add_to_what updates
shift
;;
--info)
add_to_what info
shift
;;
--run)
shift
[ $# -gt 0 ] || error_out 'missing argument for option --run'
RUN_COMMAND=$1
add_to_what run
shift
;;
--run=*)
RUN_COMMAND=${1#--run=}
[ -n "$RUN_COMMAND" ] || error_out 'missing argument for option --run'
add_to_what run
shift
;;
-h | --help)
help >&2
exit 0
;;
*)
error_out "Unknown option $arg"
error_out "Unknown option $1"
;;
esac
done
@@ -298,24 +335,26 @@ if ! declare -f pretty_csv >/dev/null; then
fi
fi
ERROR_MACHINES=""
for machine in "${TEST_MACHINES[@]}"; do
USER=${machine%@*}
HOST=${machine#*@}
# shellcheck disable=SC2029
MACHINE_CONTAINER_IMAGES[$machine]=$(ssh "$HOST" cat "/home/$USER/.config/CGAL/test_cgal_docker_images") || {
ERROR_MACHINES="$ERROR_MACHINES $machine"
}
done
if [ -n "$ERROR_MACHINES" ]; then
printf '\n> %s\n> %s\n' '[!CAUTION]' 'ERROR:'
for machine in $ERROR_MACHINES; do
if what_contains images; then
ERROR_MACHINES=""
for machine in "${TEST_MACHINES[@]}"; do
USER=${machine%@*}
HOST=${machine#*@}
# shellcheck disable=SC2016
printf '> - ERROR: cannot read file `/home/%s/.config/CGAL/test_cgal_docker_images` on ssh host `%s`\n' "$USER" "$HOST"
# shellcheck disable=SC2029
MACHINE_CONTAINER_IMAGES[$machine]=$(ssh "$HOST" cat "/home/$USER/.config/CGAL/test_cgal_docker_images") || {
ERROR_MACHINES="$ERROR_MACHINES $machine"
}
done
exit 1
if [ -n "$ERROR_MACHINES" ]; then
printf '\n> %s\n> %s\n' '[!CAUTION]' 'ERROR:'
for machine in $ERROR_MACHINES; do
USER=${machine%@*}
HOST=${machine#*@}
# shellcheck disable=SC2016
printf '> - ERROR: cannot read file `/home/%s/.config/CGAL/test_cgal_docker_images` on ssh host `%s`\n' "$USER" "$HOST"
done
exit 1
fi
fi
cat <<HEREDOC
# Test runner machines #
@@ -342,4 +381,10 @@ for machine in "${TEST_MACHINES[@]}"; do
printf '\nAvailable security updates:\n'
machine_check_updates "$HOST" "$USER"
fi
if what_contains run; then
printf '\nOutput of command `%s`:\n' "$RUN_COMMAND"
printf '\n```plain\n'
machine_run_command "$HOST" "$RUN_COMMAND"
printf '```\n'
fi
done
@@ -356,4 +356,53 @@ $SUDO_OR_PRINT systemctl daemon-reload
$SUDO_OR_PRINT systemctl enable --now podman.socket
$SUDO_OR_PRINT systemctl restart podman.socket
color_echo "Configure GRUB to use the serial console"
$SUDO_OR_PRINT sed -i -E '/^GRUB_CMDLINE_LINUX="/{
/console=ttyS0,115200n8/! s/"$/ console=ttyS0,115200n8"/
/console=tty0/! s/"$/ console=tty0"/
}' /etc/default/grub
# shellcheck disable=SC2016
$SUDO_OR_PRINT sed -i -E '
/^GRUB_TERMINAL_INPUT=/ {
s|^GRUB_TERMINAL_INPUT=.*$|GRUB_TERMINAL_INPUT="console serial"|
x
s/.*/found/
x
}
${
x
/found/! a GRUB_TERMINAL_INPUT="console serial"
x
}
' /etc/default/grub
# shellcheck disable=SC2016
$SUDO_OR_PRINT sed -i -E '
/^GRUB_SERIAL_COMMAND=/ {
s|^GRUB_SERIAL_COMMAND=.*$|GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"|
x
s/.*/found/
x
}
${
x
/found/! a GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"
x
}
' /etc/default/grub
# shellcheck disable=SC2016
$SUDO_OR_PRINT sed -i -E '
/^GRUB_TERMINAL_OUTPUT=/ {
s|^GRUB_TERMINAL_OUTPUT=.*$|GRUB_TERMINAL_OUTPUT="console serial"|
x
s/.*/found/
x
}
${
x
/found/! a GRUB_TERMINAL_OUTPUT="console serial"
x
}
' /etc/default/grub
$SUDO_OR_PRINT grub2-mkconfig -o /boot/grub2/grub.cfg
color_echo "All done!"