diff --git a/tools/ConfigDb/load_ConfigDb.sh b/tools/ConfigDb/load_ConfigDb.sh index cc7123223ac4303c457f2b0a9fcae5b5b4157c2d..6b5fbb11d31a6f2ce727312111be67486038365e 100755 --- a/tools/ConfigDb/load_ConfigDb.sh +++ b/tools/ConfigDb/load_ConfigDb.sh @@ -1,10 +1,32 @@ -if [ ${#} -ne 1 ]; then - echo "You must provide a file name for the TANGO_HOST DB dump!" - exit -1 -# Check if the filename begins with /hosthome/, /opt/lofar2.0/tango or /opt/lofar2.0/: -elif [ ${1:0:10} != /hosthome/ -a ${1:0:20} != /opt/lofar2.0/tango/ -a ${1:0:14} != /opt/lofar2.0/ ]; then - echo "You must provide a full file path that begins with one of \"/hosthome/\", \"/opt/lofar2.0/tango/\" or \"/opt/lofar2.0/\". Why is that? Because the file will be loaded from within the Docker container and only some of the host's file system directories are mounted in the container." +function help() +{ + echo -e "\nERROR: ${1}\nYou must provide a file that can be accessed from within the Docker container. This is possible for files that\n\t- Have a path in \${HOME} or\n\t- Have a full file path that begins with one of \"/hosthome/\", \"/opt/lofar2.0/tango/\" or \"/opt/lofar2.0/\".\n\nWhy is that? Because the file will be loaded from within the Docker container and only some of the host's file system directories are mounted in the container." exit -2 +} + +if [ ${#} -eq 1 ]; then + file=${1} +else + help "A file name must be provided." +fi + +# Check if the filename begins with /hosthome/, /opt/lofar2.0/tango or +# /opt/lofar2.0/ or if it is in the ${HOME} directory: +if [ ${1:0:10} != /hosthome/ -a ${1:0:20} != /opt/lofar2.0/tango/ -a ${1:0:14} != /opt/lofar2.0/ ]; then + pushd $(dirname ${file}) >/dev/null + full_path=${PWD} + popd >/dev/null + # Check if the file's directory begins with ${HOME}. Then it can be + # accessed via /hosthome. The replacement will then shorten the result. + home_replaced=${full_path#${HOME}} + if [ ${#home_replaced} -ne ${#full_path} ]; then + if [ ! -f ${file} ]; then + help "The file \"${1}\" does not exist." + fi + + # The file can be accessed through /hosthome. Modify the parameter. + file=/hosthome${home_replaced}/$(basename ${file}) + fi fi -docker exec -it ${TANGO_CONTAINER_ENV} dsconfig json2tango --write ${1} +docker exec -it ${TANGO_CONTAINER_ENV} dsconfig json2tango --write ${file} diff --git a/tools/ConfigDb/update_ConfigDb.sh b/tools/ConfigDb/update_ConfigDb.sh index 003ddd7eacb65d3916c3658b710b36e874f83a51..1c6587a0fef0a81e07ca6f6ea3b03da5084b4320 100755 --- a/tools/ConfigDb/update_ConfigDb.sh +++ b/tools/ConfigDb/update_ConfigDb.sh @@ -1,10 +1,32 @@ -if [ ${#} -ne 1 ]; then - echo "You must provide a file name for the TANGO_HOST DB dump!" - exit -1 -# Check if the filename begins with /hosthome/, /opt/lofar2.0/tango or /opt/lofar2.0/: -elif [ ${1:0:10} != /hosthome/ -a ${1:0:20} != /opt/lofar2.0/tango/ -a ${1:0:14} != /opt/lofar2.0/ ]; then - echo "You must provide a full file path that begins with one of \"/hosthome/\", \"/opt/lofar2.0/tango/\" or \"/opt/lofar2.0/\". Why is that? Because the file will be loaded from within the Docker container and only some of the host's file system directories are mounted in the container." +function help() +{ + echo -e "\nERROR: ${1}\nYou must provide a file that can be accessed from within the Docker container. This is possible for files that\n\t- Have a path in \${HOME} or\n\t- Have a full file path that begins with one of \"/hosthome/\", \"/opt/lofar2.0/tango/\" or \"/opt/lofar2.0/\".\n\nWhy is that? Because the file will be loaded from within the Docker container and only some of the host's file system directories are mounted in the container." exit -2 +} + +if [ ${#} -eq 1 ]; then + file=${1} +else + help "A file name must be provided." +fi + +# Check if the filename begins with /hosthome/, /opt/lofar2.0/tango or +# /opt/lofar2.0/ or if it is in the ${HOME} directory: +if [ ${1:0:10} != /hosthome/ -a ${1:0:20} != /opt/lofar2.0/tango/ -a ${1:0:14} != /opt/lofar2.0/ ]; then + pushd $(dirname ${file}) >/dev/null + full_path=${PWD} + popd >/dev/null + # Check if the file's directory begins with ${HOME}. Then it can be + # accessed via /hosthome. The replacement will then shorten the result. + home_replaced=${full_path#${HOME}} + if [ ${#home_replaced} -ne ${#full_path} ]; then + if [ ! -f ${file} ]; then + help "The file \"${1}\" does not exist." + fi + + # The file can be accessed through /hosthome. Modify the parameter. + file=/hosthome${home_replaced}/$(basename ${file}) + fi fi -docker exec -it ${TANGO_CONTAINER_ENV} dsconfig json2tango --write --update ${1} +docker exec -it ${TANGO_CONTAINER_ENV} dsconfig json2tango --write --update ${file}