summaryrefslogtreecommitdiffstats
path: root/server/export_target
diff options
context:
space:
mode:
authorJonathan Bauer2013-08-01 16:18:33 +0200
committerJonathan Bauer2013-08-01 16:18:33 +0200
commitd515b42421bd5781bcec98cea1e76b36cb3dbfa8 (patch)
treef7993fd68437b74835ee6cd43ed36e8e0c665386 /server/export_target
parentadd new option '-k' to build config.tgz for given type. Example: ./mltk serve... (diff)
downloadtm-scripts-d515b42421bd5781bcec98cea1e76b36cb3dbfa8.tar.gz
tm-scripts-d515b42421bd5781bcec98cea1e76b36cb3dbfa8.tar.xz
tm-scripts-d515b42421bd5781bcec98cea1e76b36cb3dbfa8.zip
[mltk-server] added check when merging different module config together to find possible conflicts. Also changed the way the config.tgz is built: now it generates under server/local_builds/<ip>/configs/<type>/ tarballs for all the modules, and merges them together at the end
Diffstat (limited to 'server/export_target')
-rwxr-xr-xserver/export_target117
1 files changed, 75 insertions, 42 deletions
diff --git a/server/export_target b/server/export_target
index fd4112b6..970ee0d9 100755
--- a/server/export_target
+++ b/server/export_target
@@ -33,12 +33,12 @@ initial_checks() {
local TOOL_STR="$TOOL_STR initial_checks:"
- [ ! -d "${SERVER_BOOT_DIR}" ] && mkdir -p "${SERVER_BOOT_DIR}"
+ [ -d "${SERVER_BOOT_DIR}" ] || mkdir -p "${SERVER_BOOT_DIR}"
# check if SERVER_EXPORT_TARGET is valid
- if [ ! -d "${SERVER_CONFIGS_DIR}/${SERVER_EXPORT_CONFIG}" ]; then
+ [ ! -z "${SERVER_EXPORT_CONFIG}" ] || perror "Server export config not given!"
+ [ -d "${SERVER_CONFIGS_DIR}/${SERVER_EXPORT_CONFIG}" ] || \
perror "Given export config not found: ${SERVER_CONFIGS_DIR}/${SERVER_EXPORT_CONFIG}"
- fi
}
copy_kernel() {
@@ -88,55 +88,89 @@ generate_addons() {
generate_config() {
# generate config from the target directory
local TOOL_STR="${TOOL_STR} generate_config:"
- pinfo "Generating config.tgz for '$SERVER_EXPORT_CONFIG'"
-
- local TARGET_CONFIG="${SERVER_CONFIGS_DIR}/${SERVER_EXPORT_CONFIG}"
-
- # its not possible to append files to a compressed tar archiv, so start with
- # a simple tar which we will gzip at the end.
+ pinfo "Generating config.tgz for '${SERVER_CONFIG_TYPE}'"
- local TARGET_CONFIG_PATH="${SERVER_CONFIGS_DIR}/config.tar"
- local TARGET_COMPRESSED_CONFIG_PATH="${SERVER_CONFIGS_DIR}/config.tgz"
+ # directory where the activated modules are given
+ # ex: server/configs/freiburg/
+ local TARGET_CONFIG_DIR="${SERVER_CONFIGS_DIR}/${SERVER_CONFIG_TYPE}"
- [ -e "$TARGET_COMPRESSED_CONFIG_PATH" ] && rm -f "$TARGET_COMPRESSED_CONFIG_PATH"
-
- for MODULE_CONFIG in $(ls "$TARGET_CONFIG"); do
+ # directory where the generated config.tgz will land
+ local TARGET_CONFIG_FINAL_DIR="${SERVER_BOOT_DIR}/configs/${SERVER_CONFIG_TYPE}"
+ [ ! -d "$TARGET_CONFIG_FINAL_DIR" ] && mkdir -p "$TARGET_CONFIG_FINAL_DIR"
+
+ # directory where the sub-archives of modules will be built
+ local TARGET_CONFIG_BUILD_DIR="${SERVER_BUILD_DIR}/configs/${SERVER_CONFIG_TYPE}"
+ # always clean the build dir
+ rm -rf "$TARGET_CONFIG_BUILD_DIR" && mkdir -p "$TARGET_CONFIG_BUILD_DIR"
+
+ local TARGET_CONFIG_PATH="${TARGET_CONFIG_FINAL_DIR}/config.tar"
+ local TARGET_CONFIG_FINAL_PATH="${TARGET_CONFIG_FINAL_DIR}/config.tgz"
+ [ -e "$TARGET_CONFIG_PATH" ] && rm -f "$TARGET_CONFIG_PATH"
+ [ -e "$TARGET_CONFIG_FINAL_PATH" ] && rm -f "$TARGET_CONFIG_FINAL_PATH"
+
+ # now go over the activated modules and pack the contents into the tar archive
+ for MODULE_CONFIG in $(ls "$TARGET_CONFIG_DIR"); do
+ pinfo "\tGenerating sub-archive for '${MODULE_CONFIG}'"
# add files in that directory to config.tgz
- cd "$TARGET_CONFIG/$MODULE_CONFIG" || perror "Could not cd to $TARGET_CONFIG/$MODULE_CONFIG"
- tar rf "${TARGET_CONFIG_PATH}" $(ls)
+ cd "${TARGET_CONFIG_DIR}/${MODULE_CONFIG}" || perror "\tCould not cd to '${TARGET_CONFIG_DIR}/${MODULE_CONFIG}'"
+
+ # check if files are already in another module config
+ for FILE in $(find . -type f); do
+ # check for all the archives we find in TARGET_CONFIG_BUILD_DIR
+ for ARCHIV in $(ls "${TARGET_CONFIG_BUILD_DIR}/"*.tar 2>/dev/null); do
+ if [ "x$(tar tvf "${ARCHIV}" | grep "$FILE")" != "x" ]; then
+ # name of the module in conflict
+ local CONFLICTING_MODULE="$(basename ${ARCHIV%.tar})"
+ # file is present in archiv
+ pwarning "\tFile '${FILE#.}' is already present in module config of '${CONFLICTING_MODULE}'."
+ perror "\tResolve conflicts between '${CONFLICTING_MODULE}' and '${MODULE_CONFIG}', then try again."
+ fi
+ done
+
+ done
+
+ # no conflict, add file to archive
+ tar cf "${TARGET_CONFIG_BUILD_DIR}/${MODULE_CONFIG}.tar" $(ls)
RET=$?
- if [ "x$RET" != "x0" ]; then
- # something went wrong
- perror "Could not add files from $MODULE_CONFIG to $TARGET_CONFIG_PATH"
- fi
+ [ "x$RET" != "x0" ] && perror "\tCould not create '${TARGET_CONFIG_BUILD_DIR}/${MODULE_CONFIG}.tgz'"
done
- # now gzip the tarball
- gzip "${TARGET_CONFIG_PATH}" || perror "Could not gzip ${TARGET_CONFIG_PATH}"
- mv "${TARGET_CONFIG_PATH}.gz" "${TARGET_COMPRESSED_CONFIG_PATH}"
+ # now we have packed all configs separately and can concatenate them all together.
+ pinfo "Merging all sub-archive into one"
+ for MODULE_CONFIG_ARCHIV in $(ls "${TARGET_CONFIG_BUILD_DIR}/"*.tar 2>/dev/null); do
+ tar Af "${TARGET_CONFIG_PATH}" "${MODULE_CONFIG_ARCHIV}"
+ RET=$?
+ [ "x$RET" != "x0" ] && perror "Could not merge '${MODULE_CONFIG_ARCHIV}' into '${TARGET_CONFIG_PATH}.tar'"
+ done
+ # now gzip everything
+ gzip "${TARGET_CONFIG_PATH}" || perror "Could not gzip '${TARGET_CONFIG_FINAL_PATH}'"
+ mv "${TARGET_CONFIG_PATH}.gz" "${TARGET_CONFIG_FINAL_PATH}" \
+ || perror "Could not mv '${TARGET_CONFIG_PATH}.gz' to '${TARGET_CONFIG_FINAL_PATH}'"
+
+ pinfo "Created config.tgz for '${SERVER_CONFIG_TYPE}' at '${TARGET_CONFIG_FINAL_PATH}'"
}
export_target() {
-initial_checks
-copy_kernel
-
-TARGET=$1
-[ -d ${SERVER_BUILD_DIR}/${TARGET} ] || perror "Given target directory does not exist: ${SERVER_BUILD_DIR}/${TARGET}"
-
-case "$2" in
- stage31)
- generate_stage31
- ;;
- stage32)
- generate_stage32
- generate_config
- ;;
- addons)
- generate_addons
- ;;
-esac
+ initial_checks
+ copy_kernel
+
+ TARGET=$1
+ [ -d ${SERVER_BUILD_DIR}/${TARGET} ] || perror "Given target directory does not exist: ${SERVER_BUILD_DIR}/${TARGET}"
+
+ case "$2" in
+ stage31)
+ generate_stage31
+ ;;
+ stage32)
+ generate_stage32
+ #generate_config
+ ;;
+ addons)
+ generate_addons
+ ;;
+ esac
}
@@ -155,4 +189,3 @@ clean_target() {
pinfo "Cleaning '${SERVER_BOOT_DIR}/stage32_dqfs/mnt/${TARGET}.sqfs'..."
[ -e "${SERVER_BOOT_DIR}/stage32_sqfs/mnt/${TARGET}.sqfs" ] && { rm "${SERVER_BOOT_DIR}/stage32_sqfs/mnt/${TARGET}.sqfs" || perror "rm failed."; }
}
-