#!/usr/bin/env bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems                #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
# -------------------------------------------------------------------------- #

set -o errexit -o nounset -o pipefail

which wget rpm2cpio cpio dirname realpath xargs 1>/dev/null

readonly SELF=$(realpath "$0" | xargs dirname) && cd "$SELF/"

readonly SRVANY_URL="https://kojipkgs.fedoraproject.org//packages/mingw-srvany/1.1/4.fc38/noarch/mingw32-srvany-1.1-4.fc38.noarch.rpm"

wget -nd -O srvany.rpm $SRVANY_URL && rpm2cpio srvany.rpm | cpio -idmv

install -d "$SELF/exe/"

mv $SELF/usr/i686-w64-mingw32/sys-root/mingw/bin/*exe $SELF/exe/
rm -rf $SELF/srvany.rpm $SELF/usr
