#!/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 "$REMOTE_HOST" } [ $# -ne 2 ] && perror "$0 (-- Hint: is gone now, only two parameters are needed)" [ "$REMOTE_HOST" = "local" ] && perror 'It is not wise to use "local" as remote IP.' REMOTE_HOST="$1" BOOT_DIR="${ROOT_DIR}/server/boot/$REMOTE_HOST" TARGET_DIR="$2" mkdir -p "$TARGET_DIR" mkdir -p "$BOOT_DIR" EXCLUDE="$BOOT_DIR/exclude-stage4" INCLUDE="$BOOT_DIR/include-stage4" pinfo "Building rsync exclude-file for building stage 4...." echo "## Exclude file for stage4 of $REMOTE_HOST" > "$EXCLUDE" echo "## Include file for stage4 of $REMOTE_HOST" > "$INCLUDE" for FILE in $(find "$ROOT_DIR"/server/blacklists/*/ -type f); do echo "## From $FILE" >> "$EXCLUDE" echo "## From $FILE" >> "$INCLUDE" grep '^-' "$FILE" >> "$EXCLUDE" grep '^+' "$FILE" >> "$INCLUDE" done pinfo "Done." [ "y$UID" == "y0" ] || perror "You're not root. Cannot continue with rsync." # prepare rsync's options depending on whether the source is local or remote RSYNC_OPTS="" RSYNC_SOURCE="" if [[ "$REMOTE_HOST" == "local" ]]; then RSYNC_SOURCE="/" else RSYNC_SOURCE="root@$REMOTE_HOST:/" RSYNC_OPTS="-e ssh -c arcfour -oStrictHostKeyChecking=no" fi pinfo "Cloning via rsync" cat "$INCLUDE" "$EXCLUDE" | rsync -a --delete --delete-excluded --numeric-ids -v --exclude-from=- "${RSYNC_OPTS}" "${RSYNC_SOURCE}" "${TARGET_DIR}" || perror "rsync from '${RSYNC_SOURCE}' to '${TARGET_DIR}' failed."