Commit d259f1f6 authored by Ivan Mazhukin's avatar Ivan Mazhukin

fix path detections; fix syncing

parent c7d01824
......@@ -174,21 +174,40 @@ resolve_explicit_source_path() {
printf '%s\n' "$candidate"
}
default_builder_source_path() {
default_builder_source_user() {
local current_user source_user
current_user="$(id -un)"
source_user="${BUILDER_USER:-$current_user}"
printf '%s\n' "$source_user"
}
builder_source_candidates() {
local source_user
source_user="$(default_builder_source_user)"
printf '/srv/%s/Projects/eepm\n' "$source_user"
}
resolve_builder_source_path() {
local candidate
candidate="${BUILDER_PATH:-$(default_builder_source_path)}"
candidate="$(realpath "$candidate" 2>/dev/null || printf '%s\n' "$candidate")"
verify_eepm_tree "$candidate"
printf '%s\n' "$candidate"
if [[ -n "$BUILDER_PATH" ]]; then
candidate="$(realpath "$BUILDER_PATH" 2>/dev/null || printf '%s\n' "$BUILDER_PATH")"
verify_eepm_tree "$candidate"
printf '%s\n' "$candidate"
return 0
fi
while IFS= read -r candidate; do
candidate="$(realpath "$candidate" 2>/dev/null || printf '%s\n' "$candidate")"
if [[ -d "$candidate" && -f "$candidate/bin/eepm" && -r "$candidate/bin/eepm" ]]; then
printf '%s\n' "$candidate"
return 0
fi
done < <(builder_source_candidates)
fatal "Could not find builder64 eepm tree under /srv/$(default_builder_source_user)/Projects/eepm"
}
resolve_source_path() {
......@@ -225,9 +244,32 @@ remote_eepm_tree_exists() {
local tree="$2"
build_ssh_base_args
ssh "${SSH_BASE_ARGS[@]}" "$target" \
bash -lc 'test -d "$1" && test -f "$1/bin/eepm" && test -r "$1/bin/eepm"' \
bash "$tree" >/dev/null 2>&1
ssh "${SSH_BASE_ARGS[@]}" "$target" bash -s -- "$tree" >/dev/null 2>&1 <<'EOF'
tree="$1"
test -d "$tree" && test -f "$tree/bin/eepm" && test -r "$tree/bin/eepm"
EOF
}
find_remote_builder_source_path() {
local target="$1"
local candidate
if [[ -n "$BUILDER_PATH" ]]; then
if remote_eepm_tree_exists "$target" "$BUILDER_PATH"; then
printf '%s\n' "$BUILDER_PATH"
return 0
fi
return 1
fi
while IFS= read -r candidate; do
if remote_eepm_tree_exists "$target" "$candidate"; then
printf '%s\n' "$candidate"
return 0
fi
done < <(builder_source_candidates)
return 1
}
remote_sync_dir_for_source() {
......@@ -254,7 +296,10 @@ sync_local_source_to_remote() {
info "Remote eepm tree not found in /srv; syncing local tree to $target:$remote_dir"
ssh "${SSH_BASE_ARGS[@]}" "$target" mkdir -p "$remote_dir"
ssh "${SSH_BASE_ARGS[@]}" "$target" bash -s -- "$remote_dir" <<'EOF'
remote_dir="$1"
mkdir -p "$remote_dir"
EOF
rsync -a --delete -e "ssh ${SSH_BASE_ARGS[*]}" "$source_dir"/ "$target:$remote_dir/"
printf '%s\n' "$remote_dir"
......@@ -272,7 +317,10 @@ cleanup_remote_sync_dir() {
build_ssh_base_args
info "Cleaning up remote sync dir: $target:$remote_dir"
ssh "${SSH_BASE_ARGS[@]}" "$target" rm -rf "$remote_dir"
ssh "${SSH_BASE_ARGS[@]}" "$target" bash -s -- "$remote_dir" <<'EOF'
remote_dir="$1"
rm -rf "$remote_dir"
EOF
}
create_log_file() {
......@@ -421,21 +469,23 @@ build_remote_args() {
target="$(remote_target)"
if [[ "$SOURCE_KIND" == "local" ]]; then
explicit_source="$(resolve_local_source_path)"
remote_source="$(default_builder_source_path)"
if remote_eepm_tree_exists "$target" "$remote_source"; then
if remote_source="$(find_remote_builder_source_path "$target")"; then
info "Remote eepm tree found at: $remote_source"
else
explicit_source="${SOURCE_PATH:-$(pwd -P)}"
explicit_source="$(realpath "$explicit_source")"
verify_eepm_tree "$explicit_source"
remote_source="$(sync_local_source_to_remote "$explicit_source" "$target")"
REMOTE_SYNC_DIR="$remote_source"
fi
REMOTE_ARGS+=(--eepm-source explicit --eepm-dir "$remote_source")
elif [[ "$SOURCE_KIND" == "explicit" ]]; then
explicit_source="$(resolve_explicit_source_path "$SOURCE_PATH")"
remote_source="$(default_builder_source_path)"
if remote_eepm_tree_exists "$target" "$remote_source"; then
if remote_source="$(find_remote_builder_source_path "$target")"; then
info "Remote eepm tree found at: $remote_source"
else
[[ -n "$SOURCE_PATH" ]] || fatal "Explicit source path is empty"
explicit_source="$(realpath "$SOURCE_PATH" 2>/dev/null || printf '%s\n' "$SOURCE_PATH")"
verify_eepm_tree "$explicit_source"
remote_source="$(sync_local_source_to_remote "$explicit_source" "$target")"
REMOTE_SYNC_DIR="$remote_source"
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment