From 6327371e4c25bd49fb08b20bc4fcccf3d7805d55 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 18 Jan 2022 11:21:37 +0100 Subject: [PATCH] net: run.sh: write launcher command to shell script Instead of passing a whole script to the terminal via command-line argument, write it to a file. This is in preparation to use the same script with tmux, see next patch. Change-Id: I15760d706b20628421c10a16514120f442d5477f --- net/templates/run.sh | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/net/templates/run.sh b/net/templates/run.sh index 426ed91..332b168 100755 --- a/net/templates/run.sh +++ b/net/templates/run.sh @@ -40,7 +40,9 @@ fi logdir="current_log" piddir="run/pids" -mkdir -p "$logdir" "$piddir" +launcherdir="run/launchers" +rm -rf "$launcherdir" +mkdir -p "$logdir" "$piddir" "$launcherdir" find_term() { # Find a terminal program and write to the global "terminal" variable @@ -93,20 +95,32 @@ term() { local pidfile_term="$piddir/$title.term.pid" pidfiles_must_not_exist "$pidfile" "$pidfile_term" + local launcher="$launcherdir/$title.sh" + + cat << EOF > "$launcher" +#!/bin/sh + +export LD_LIBRARY_PATH='/usr/local/lib' + +$1 & +echo \$! > $pidfile +wait + +echo + +while true; do + echo 'q Enter to close' + read q_to_close + if [ "x\$q_to_close" = xq ]; then + break + fi +done +EOF + chmod +x "$launcher" + $terminal \ -title "CN:$title" \ - -e sh -c "export LD_LIBRARY_PATH='/usr/local/lib' - $1 & - echo \$! > $pidfile - wait - echo - while true; do - echo 'q Enter to close' - read q_to_close - if [ \"x\$q_to_close\" = xq ]; then - break - fi - done" \ + -e sh -c "$launcher" \ & echo "$!" > "$pidfile_term"