|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This code is part of the TrinityX software suite |
| 4 | +# Copyright (C) 2023 ClusterVision Solutions b.v. |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <https://www.gnu.org/licenses/> |
| 18 | + |
| 19 | +### |
| 20 | +# |
| 21 | +# USAGE: |
| 22 | +# cat /etc/ood/config/apps/shell/env |
| 23 | +# OOD_SSH_WRAPPER=/trinity/local/ondemand/3.0/osimage/addons/chroot_wrapper.sh |
| 24 | +# |
| 25 | +# cat /trinity/local/ondemand/3.0/osimage/addons/chroot_wrapper.sh |
| 26 | +# https://vmware-controller1.cluster:8080/pun/sys/shell/ssh/vmware-controller1.cluster/image=compute,path=/trinity/images/compute,kernel_version=5.14.0-427.37.1.el9_4.x86_64 |
| 27 | +# |
| 28 | +#### |
| 29 | + |
| 30 | +function wait_till_ok { |
| 31 | + local OS_PATH=$1 |
| 32 | + if [[ -f "${OS_PATH}/tmp/lchroot.lock" ]]; then |
| 33 | + echo "lchroot is already running, waiting for it to finish (press f to force)" |
| 34 | + |
| 35 | + while [[ -f "${OS_PATH}/tmp/lchroot.lock" ]]; do |
| 36 | + read -t 1 -n 1 -s key |
| 37 | + if [[ $key == "f" ]]; then |
| 38 | + echo "" |
| 39 | + echo "Removing lock file" |
| 40 | + sudo rm "${OS_PATH}/tmp/lchroot.lock" |
| 41 | + break |
| 42 | + else |
| 43 | + echo -n "." |
| 44 | + fi |
| 45 | + done |
| 46 | + fi |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +for arg in "$@"; do |
| 51 | + if [[ "$arg" =~ image= ]]; then |
| 52 | + OS_IMAGE=$(echo "$arg" | grep -oP 'image=[^,]+' | cut -d= -f2 | tr -d "'") |
| 53 | + fi |
| 54 | + if [[ "$arg" =~ path= ]]; then |
| 55 | + OS_PATH=$(echo "$arg" | grep -oP 'path=[^,]+' | cut -d= -f2 | tr -d "'") |
| 56 | + fi |
| 57 | +done |
| 58 | + |
| 59 | + |
| 60 | +if [[ -n "$OS_IMAGE" ]]; then |
| 61 | + if [[ ! -n "$OS_PATH" ]]; then |
| 62 | + OS_PATH="{{ trix_images }}/${OS_IMAGE}" |
| 63 | + fi |
| 64 | + wait_till_ok "${OS_PATH}" |
| 65 | + sudo lchroot $OS_IMAGE |
| 66 | +else |
| 67 | + exec /usr/bin/ssh "$@" |
| 68 | +fi |
0 commit comments