Updated config to /config/$1 instead of /config_$1 + added .gitignore for /config

This commit is contained in:
xdrm-brackets 2018-01-29 13:33:47 +01:00
parent d023d6cbad
commit 1893a5bd49
4 changed files with 18 additions and 13 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config

26
launch
View File

@ -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;

2
read
View File

@ -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;

2
write
View File

@ -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;