Developer-Dashboard

 view release on metacpan or  search on metacpan

integration/windows/run-qemu-windows-smoke.sh  view on Meta::CPAN

  local candidate="${WINDOWS_QEMU_ENV_FILE:-}"

  if [[ -z "$candidate" && -f "$ROOT_DIR/.developer-dashboard/windows-qemu.env" ]]; then
    candidate="$ROOT_DIR/.developer-dashboard/windows-qemu.env"
  fi

  if [[ -z "$candidate" && -n "${HOME:-}" && -f "$HOME/.developer-dashboard/windows-qemu.env" ]]; then
    candidate="$HOME/.developer-dashboard/windows-qemu.env"
  fi

  if [[ -n "$candidate" ]]; then
    if [[ ! -f "$candidate" ]]; then
      echo "WINDOWS_QEMU_ENV_FILE does not exist: $candidate" >&2
      exit 1
    fi
    export WINDOWS_QEMU_ENV_FILE="$candidate"
    set -a
    # shellcheck disable=SC1090
    source "$candidate"
    set +a
  fi
}

ensure_kvm_available() {
  # Purpose: fail fast when the selected Windows VM path cannot use KVM.
  # Input: the current host /dev/kvm device state.
  # Output: exits non-zero with an explicit error when KVM access is unavailable.
  if [[ ! -e /dev/kvm ]]; then
    echo "/dev/kvm is not available on this host" >&2
    exit 1
  fi

  if [[ ! -r /dev/kvm || ! -w /dev/kvm ]]; then
    if [[ "$DD_WINDOWS_KVM_REEXEC" -eq 0 ]] && command -v sg >/dev/null 2>&1 && groups "$(id -un)" | grep -qw kvm; then
      export DD_WINDOWS_KVM_REEXEC=1
      exec sg kvm -c "\"$0\""
    fi
    echo "/dev/kvm exists but is not readable and writable for the current user" >&2
    exit 1
  fi
}

resolve_strawberry_url() {
  # Purpose: resolve the latest 64-bit Strawberry Perl MSI URL from the official release feed.
  # Input: optional WINDOWS_STRAWBERRY_URL override or host Perl with LWP::UserAgent and JSON::XS.
  # Output: exports WINDOWS_STRAWBERRY_URL with a downloadable MSI URL or exits on failure.
  if [[ -n "$WINDOWS_STRAWBERRY_URL" ]]; then
    return
  fi

  if ! command -v perl >/dev/null 2>&1; then
    echo "WINDOWS_STRAWBERRY_URL is required when perl is unavailable on the host" >&2
    exit 1
  fi

  WINDOWS_STRAWBERRY_URL="$(
    perl -MJSON::XS=decode_json -MLWP::UserAgent -e '
      my $ua = LWP::UserAgent->new( timeout => 20 );
      my $res = $ua->get("https://strawberryperl.com/releases.json");
      die $res->status_line unless $res->is_success;
      my $data = decode_json( $res->decoded_content );
      for my $release ( @{$data} ) {
        next if ( $release->{archname} || "" ) ne "MSWin32-x64-multi-thread";
        my $url = $release->{edition}{msi}{url} || "";
        next if $url eq "";
        print $url;
        exit 0;
      }
      die "No 64-bit Strawberry Perl MSI URL found in releases.json\n";
    '
  )"

  if [[ -z "$WINDOWS_STRAWBERRY_URL" ]]; then
    echo "Unable to resolve a Strawberry Perl MSI URL from the official release feed" >&2
    exit 1
  fi
  if [[ "$WINDOWS_STRAWBERRY_URL" != https://* ]]; then
    echo "WINDOWS_STRAWBERRY_URL must use https: $WINDOWS_STRAWBERRY_URL" >&2
    exit 1
  fi
  export WINDOWS_STRAWBERRY_URL
}

prepare_strawberry_installer() {
  # Purpose: cache the Strawberry Perl MSI in the OEM folder so Windows setup
  # does not depend on a live in-guest HTTP download before the smoke starts.
  # Input: resolved WINDOWS_STRAWBERRY_URL plus the Dockur OEM workdir.
  # Output: writes strawberry-perl-installer.msi into the OEM folder when missing.
  local oem_dir="$WINDOWS_DOCKUR_WORKDIR/oem"
  local installer_path="$oem_dir/strawberry-perl-installer.msi"

  mkdir -p "$oem_dir"
  if [[ -s "$installer_path" ]]; then
    return
  fi

  perl -MLWP::UserAgent -e '
    use strict;
    use warnings;

    my ( $url, $target ) = @ARGV;
    die "missing Strawberry Perl URL\n" if !defined $url || $url eq q{};
    die "missing Strawberry Perl target path\n" if !defined $target || $target eq q{};

    my $ua = LWP::UserAgent->new( timeout => 120 );
    my $res = $ua->mirror( $url, $target );
    die $res->status_line . "\n" if !$res->is_success && $res->code != 304;
  ' "$WINDOWS_STRAWBERRY_URL" "$installer_path"
}

prepare_dockur_oem_bundle() {
  # Purpose: stage the Dockur OEM and shared-folder files used by the Windows smoke.
  # Input: the built tarball path plus optional Windows Strawberry installer URL.
  # Output: writes OEM bootstrap files and shared-folder markers into the Dockur workdir.
  local storage_dir="$WINDOWS_DOCKUR_WORKDIR/storage"
  local shared_dir="$WINDOWS_DOCKUR_WORKDIR/shared"
  local oem_dir="$WINDOWS_DOCKUR_WORKDIR/oem"
  local bootstrap_ps1="$oem_dir/bootstrap.ps1"
  local install_bat="$oem_dir/install.bat"

  resolve_strawberry_url



( run in 0.659 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )