#!/bin/bash # # Helper script to generate a stage4 export # for a remote machine per rsync. # SELF="$(readlink -f $0)" SCRIPTS_DIR="$(dirname "${SELF}")" ROOT_DIR="${SCRIPTS_DIR%/*}" . "${ROOT_DIR}/helper/logging.inc" MLTK_PID="$$" qnd_exit() { unset_quiet kill "$MLTK_PID" [ $# -ge 1 ] && kill "$1" } [ $# -lt 3 ] && perror "$0 " BASE_DIR="${ROOT_DIR}/server/local_builds/$1" BOOT_DIR="${ROOT_DIR}/server/boot/$1" [ ! -d "$BASE_DIR" ] && perror "Unknown Vorlage '$1'" BASEDIR="${BASE_DIR}/$2" [ ! -d "$BASE_DIR" ] && perror "Unknown Stage '$2' for Vorlage '$1'" TARGET_DIR="$3" mkdir -p "$TARGET_DIR" mkdir -p "$BOOT_DIR" [ ! -z "$(ls "${TARGET_DIR}")" ] && perror "Target dir '${TARGET_DIR}' not empty" pinfo "Building rsync exclude-file for building stage 4...." cp "${ROOT_DIR}/data/basic.nocopy" "${BOOT_DIR}/exclude-stage4" # this next command lists all files found in BASE_DIR and removed the prefix BASE_DIR find "${BASE_DIR}" -type f | cut -c $[${#BASE_DIR} + 1]- >> "${BOOT_DIR}/exclude-stage4" pinfo "Done." # prepare rsync's options depending on whether the source is local or remote RSYNC_OPTS="" RSYNC_SOURCE="" if [[ "$1" == "local" ]]; then RSYNC_SOURCE="/" else RSYNC_SOURCE="root@$1:/" RSYNC_OPTS="-e ssh -oStrictHostKeyChecking=no" fi pinfo "Cloning via rsync" rsync -a --numeric-ids -v --exclude-from="${BOOT_DIR}/exclude-stage4" "${RSYNC_OPTS}" "${RSYNC_SOURCE}" "${TARGET_DIR}" || perror "rsync from '${RSYNC_SOURCE}' to '${TARGET_DIR}' failed."