forgejo/docker/map-binaries.sh
Gapodo 7599887d44
Some checks failed
ci/woodpecker/push/compliance-and-tests Pipeline is pending
ci/woodpecker/push/release-version Pipeline is pending
ci/woodpecker/tag/compliance-and-tests Pipeline was successful
ci/woodpecker/tag/release-version Pipeline failed
updated build
2022-12-05 01:36:52 +01:00

50 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
if [[ ${#@} -lt 2 ]]; then
echo "not enough arguments provided" 1>&2
exit 1
fi
BINARYLOOKUPPATH="${1}"
FILEBASENAME="${2}"
COMPRESS="${3}"
if [[ ${#@} -gt 3 ]] && ! [[ "${4}" == "" ]]; then
FILEVERSION="${4}"
else
FILEVERSION="$DEFAULTTAGNAME"
fi
FILE_WIHTOUT_PLATFORM="${FILEBASENAME}-${FILEVERSION}"
DOCKERDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
WS_BASE="${DOCKERDIR%/docker}"
if [[ ! -f "${DOCKERDIR}/archmap.txt" ]]; then
echo "no archmap found" 1>&2
exit 1
fi
function map(){
local file="${1}"
local bin_platform="${file##./$FILE_WIHTOUT_PLATFORM-}"
if ! grep -q "$bin_platform" "${DOCKERDIR}/archmap.txt"; then
echo "no matching platform for $file found" 2>&1
return 0
fi
local platform="$(grep $bin_platform "${DOCKERDIR}/archmap.txt" | cut -d':' -f2)"
mkdir -p "${DOCKERDIR}/bin/$platform"
echo "Mapped ${file} to $platform, copying"
cp "${file}" "${DOCKERDIR}/bin/$platform/${FILEBASENAME}"
if [[ "$COMPRESS" == "true" ]]; then
echo "Compressing active, compressing ${DOCKERDIR}/bin/$platform/${FILEBASENAME}"
upx --best --lzma -q "${DOCKERDIR}/bin/$platform/${FILEBASENAME}"
fi
}
cd "$WS_BASE/${BINARYLOOKUPPATH}"
while IFS= read -r -d $'\0' infile; do
map "$infile"
done < <(find . -maxdepth 1 -type f -name "${FILE_WIHTOUT_PLATFORM}-*" -print0)