From 1893a5bd49315840c80517306b4f29dbb6bd0a37 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 29 Jan 2018 13:33:47 +0100 Subject: [PATCH] Updated config to /config/$1 instead of /config_$1 + added .gitignore for /config --- .gitignore | 1 + launch | 26 +++++++++++++++----------- read | 2 +- write | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..30fa1ce --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config \ No newline at end of file diff --git a/launch b/launch index 301219c..558135f 100755 --- a/launch +++ b/launch @@ -16,14 +16,18 @@ test $# -ge 5 && TRIGGER="$5"; # (2) Secondary setup #--------------------------------------------------------# -# (1) Reset configuration file -test -f $ROOT/config && rm $ROOT/config; +# (1) Create config dir (if doesn't exist) # +test ! -d $ROOT/config && mkdir $ROOT/config; -# (2) Create buffer paths -BUF_IN="/tmp/buf_in_$4"; -BUF_OUT="/tmp/buf_out_$2_$3"; +# (2) Reset configuration file (if exists) +CONF_FILE=$ROOT/config/$1; +test -f $CONF_FILE && rm $CONF_FILE; -# (3) Flush buffers +# (3) Create buffer paths +BUF_IN="/tmp/buf_in_$1"; +BUF_OUT="/tmp/buf_out_$1"; + +# (4) Flush buffers echo -ne "" > $BUF_IN; echo -ne "" > $BUF_OUT; @@ -104,8 +108,8 @@ OUT_PID=$!; # (5) Store the config file for 'write' + 'send' to work properly #--------------------------------------------------------# -# (1) Store config file in 'config_$NAME' -echo -e "#!/bin/bash\nBUF_IN=\"$BUF_IN\"; BUF_OUT=\"$BUF_OUT\";\nIN_PID=$IN_PID; OUT_PID=$OUT_PID;\n" > $ROOT/config_$1; +# (1) Store config file in 'config/$NAME' +echo -e "#!/bin/bash\nBUF_IN=\"$BUF_IN\"; BUF_OUT=\"$BUF_OUT\";\nIN_PID=$IN_PID; OUT_PID=$OUT_PID;\n" > $CONF_FILE; # (2) Notify server started # @@ -114,8 +118,8 @@ echo -e "#!/bin/bash\nBUF_IN=\"$BUF_IN\"; BUF_OUT=\"$BUF_OUT\";\nIN_PID=$IN_PID; # (6) Manage ending proccess #--------------------------------------------------------# # (1) Kill subproccesses if Ctrl+C # -trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $ROOT/config_$1; pkill nc 2>/dev/null; rm $BUF_OUT; rm $BUF_IN; exit 1;" INT; -trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $ROOT/config_$1; pkill nc 2>/dev/null; rm $BUF_OUT; rm $BUF_IN; exit 1;" KILL; +trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $CONF_FILE; pkill nc 2>/dev/null; rm $BUF_OUT; rm $BUF_IN; exit 1;" INT; +trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $CONF_FILE; pkill nc 2>/dev/null; rm $BUF_OUT; rm $BUF_IN; exit 1;" KILL; # (2) Wait for daemons to stop # wait $OUT_PID; @@ -123,7 +127,7 @@ wait $IN_PID; pkill nc 2>/dev/null; # (3) Remove config file # -rm $ROOT/config_$1; +rm $CONF_FILE; # (4) Remove buffers # rm $BUF_OUT; diff --git a/read b/read index c0bfc89..78eb45e 100755 --- a/read +++ b/read @@ -11,7 +11,7 @@ FLUSH=1; test $# -ge 2 -a "$2" = "-" && FLUSH=0; # (2) load configuration file -test -f $ROOT/config_$1 && source $ROOT/config_$1 || ( echo "ERR: No such name" && exit 1 ) || exit 1; +test -f $ROOT/config/$1 && source $ROOT/config/$1 || ( echo "ERR: No such name" && exit 1 ) || exit 1; # (3) Read content from file cat $BUF_IN; diff --git a/write b/write index e6c542b..030feb5 100755 --- a/write +++ b/write @@ -7,7 +7,7 @@ ROOT=$(dirname `realpath $0`); test $# -lt 2 && echo "ERR: Missing arguments (name, message)" && exit 1; # (2) load configuration file -test -f $ROOT/config_$1 && source $ROOT/config_$1 || ( echo "ERR: No such name" && exit 1 ) || exit 1; +test -f $ROOT/config/$1 && source $ROOT/config/$1 || ( echo "ERR: No such name" && exit 1 ) || exit 1; # (3) Write content to file echo -ne "$2" >> $BUF_OUT;