From 9bf955307e4dd767e81d8b08ebfd00abc88cadf9 Mon Sep 17 00:00:00 2001 From: Pier Carlo Chiodi Date: Fri, 18 Jun 2021 18:26:27 +0200 Subject: [PATCH] Docker: verify output dirs are writable --- docker/run.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docker/run.sh b/docker/run.sh index 04154ebb..9d4c0fa8 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -32,11 +32,46 @@ OUTPUT_DIR_HTML="/root/arouteserver_html" if [[ ! -e "${OUTPUT_DIR}" && ! -d "${OUTPUT_DIR}" ]]; then error "The output directory ${OUTPUT_DIR} can't be found. - This is the directory where the configurations generate by ARouteServer will be saved. + This is the directory where the configurations generated by ARouteServer will be saved. Please be sure to mount the desired directory of the host to the ${OUTPUT_DIR} directory on the container. You can run the container passing the '-v PATH_OF_DIRECTORY_ON_THE_HOST:${OUTPUT_DIR}' argument." fi +TEST_WRITABLE_FILE="${OUTPUT_DIR}/.test_dir_is_writable" + +set +e +touch ${TEST_WRITABLE_FILE} &>/dev/null +EXIT_CODE=$? +set -e + +if [[ ${EXIT_CODE} -ne 0 ]]; then + error "It seems that the output directory ${OUTPUT_DIR} is not writable. + This is the directory where the configurations generated by ARouteServer will be saved. + Please be sure to mount the desired directory of the host to the ${OUTPUT_DIR} directory on the container. + You can run the container passing the '-v PATH_OF_DIRECTORY_ON_THE_HOST:${OUTPUT_DIR}' argument." +fi + +rm ${TEST_WRITABLE_FILE} &>/dev/null + +if [[ -e "${OUTPUT_DIR_HTML}" && -d "${OUTPUT_DIR_HTML}" ]]; then + + TEST_WRITABLE_FILE="${OUTPUT_DIR_HTML}/.test_dir_is_writable" + + set +e + touch ${TEST_WRITABLE_FILE} &>/dev/null + EXIT_CODE=$? + set -e + + if [[ ${EXIT_CODE} -ne 0 ]]; then + error "It seems that the HTML output directory ${OUTPUT_DIR_HTML} is not writable. + This is the directory where the textual representation of route server policy generated by ARouteServer will be saved. + Please be sure to mount the desired directory of the host to the ${OUTPUT_DIR_HTML} directory on the container. + You can run the container passing the '-v PATH_OF_DIRECTORY_ON_THE_HOST:${OUTPUT_DIR_HTML}' argument." + fi + + rm ${TEST_WRITABLE_FILE} &>/dev/null +fi + if [[ -z "${DAEMON}" ]]; then error_envvar_not_set "DAEMON" fi