Skip to content
Snippets Groups Projects
Commit 681c725d authored by Thomas Juerges's avatar Thomas Juerges
Browse files

Automatically translate paths beginning in ${HOME} to /hosthome

This allows to specify only
    tools/ConfigDb/update_ConfigDb.sh tools/ConfigDb/LOFAR_ConfigDb.json
instead of
    tools/ConfigDb/update_ConfigDb.sh /hosthome/workspace/git/LOFAR2.0/tango/tools/ConfigDb/LOFAR_ConfigDb.json
parent f653d5b4
No related branches found
No related tags found
No related merge requests found
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}
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}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment