#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2023 The Falco Authors.
#
#
# 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.
#
# Simple script that desperately tries to load the kernel instrumentation by
# looking for it in a bunch of ways. Convenient when running Falco inside
# a container or in other weird environments.
#

set -euo pipefail

CRI_PROTO_URL="https://raw.githubusercontent.com/kubernetes/cri-api/master/pkg/apis/runtime/v1/api.proto"
CRI_PROTO_TMP=$(mktemp /tmp/falcosecurity-libs-cri-proto.XXXXXX)
CRI_PROTO="$(dirname $0)/../cri-v1.proto"

cleanup() {
	rm -f "$CRI_PROTO_TMP"
}

trap cleanup EXIT

(
	echo "//// automatically generated by $0, rerun to update"
	echo ""
	curl -fsSL "$CRI_PROTO_URL" | grep -v gogoproto | sed '-res@std(in|out|err) @f_std\1 @g' | sed 's/ \[deprecated=true\]//g'
) > "$CRI_PROTO_TMP" && mv "$CRI_PROTO_TMP" "$CRI_PROTO"
