forgejo/docker/map-binaries.sh

79 lines
2.2 KiB
Bash
Raw Normal View History

2022-12-04 14:50:37 +00:00
#!/bin/bash
2022-12-06 13:32:27 +00:00
errcho () {
echo "${@}" >&2
}
2022-12-06 10:49:55 +00:00
if [ ${#@} -lt 3 ]; then
2022-12-06 13:32:27 +00:00
errcho "not enough arguments provided"
2022-12-06 10:49:55 +00:00
echo "syntax: ${0} <path directly containing the binary> <base name of the binary> <target name or false> [<version tag as in the file name>]"
2022-12-06 13:32:27 +00:00
exit 2
2022-12-04 14:50:37 +00:00
fi
BINARYLOOKUPPATH="${1}"
FILEBASENAME="${2}"
2022-12-05 21:06:06 +00:00
RENAME="${3}"
2022-12-04 14:50:37 +00:00
2022-12-06 10:49:55 +00:00
if [ ${#@} -gt 3 ] && ! [ "${4}" == "" ]; then
2022-12-06 13:32:27 +00:00
echo "Tag provided: ${4}"
2022-12-05 21:06:06 +00:00
FILEVERSION="${4}"
2022-12-04 14:50:37 +00:00
else
2022-12-06 13:32:27 +00:00
echo "No tag provided defaulting to tag ${DEFAULTTAGNAME:-main}"
2022-12-05 21:06:06 +00:00
FILEVERSION="${DEFAULTTAGNAME:-main}"
fi
OUTFILENAME=""
2022-12-06 10:49:55 +00:00
if [ "${RENAME}" == "false" ]; then
2022-12-06 13:32:27 +00:00
echo "Rename deactivated outputting as ${FILEBASENAME}"
2022-12-05 21:06:06 +00:00
OUTFILENAME="${FILEBASENAME}"
2022-12-06 13:32:27 +00:00
elif [ "${RENAME}" == "true" ]; then
OUTFILENAME="gitea"
echo "Rename set to true, renaming to ${OUTFILENAME}"
2022-12-05 21:06:06 +00:00
else
2022-12-06 13:32:27 +00:00
echo "Rename target name provided, renaming to ${RENAME}"
OUTFILENAME="${RENAME}"
2022-12-04 14:50:37 +00:00
fi
FILE_WIHTOUT_PLATFORM="${FILEBASENAME}-${FILEVERSION}"
2022-12-06 13:32:27 +00:00
DOCKERDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 3; pwd -P )"
2022-12-04 14:50:37 +00:00
WS_BASE="${DOCKERDIR%/docker}"
2022-12-06 10:49:55 +00:00
if [ ! -f "${DOCKERDIR}/archmap.txt" ]; then
2022-12-06 13:32:27 +00:00
errcho "no archmap found"
exit 4
2022-12-04 14:50:37 +00:00
fi
2022-12-06 13:32:27 +00:00
if [ ! -d "${DOCKERDIR}/bin" ]; then
echo "Folder ${DOCKERDIR}/bin missing, creating it"
mkdir -p "${DOCKERDIR}/bin"
fi
map () {
2022-12-04 14:50:37 +00:00
local file="${1}"
2022-12-06 13:32:27 +00:00
local bin_platform="${file##"./${FILE_WIHTOUT_PLATFORM}-"}"
local platform
echo "handling ${file} with detected bin_platform $bin_platform"
2022-12-04 14:50:37 +00:00
if ! grep -q "$bin_platform" "${DOCKERDIR}/archmap.txt"; then
2022-12-06 13:32:27 +00:00
errcho "no matching platform for $file found"
2022-12-04 14:50:37 +00:00
return 0
fi
2022-12-06 13:32:27 +00:00
platform="$(grep "$bin_platform" "${DOCKERDIR}/archmap.txt" | cut -d':' -f2)"
echo "Docker platform parsed: $platform"
if [ ! -d "${DOCKERDIR}/bin/$platform" ]; then
echo "First item for this platform, creating directory \"${DOCKERDIR}/bin/$platform\""
mkdir -p "${DOCKERDIR}/bin/$platform"
fi
echo "Mapped ${file} to $platform, copying to \"${DOCKERDIR}/bin/$platform/${OUTFILENAME}\""
2022-12-05 21:06:06 +00:00
cp "${file}" "${DOCKERDIR}/bin/$platform/${OUTFILENAME}"
2022-12-04 14:50:37 +00:00
}
2022-12-06 13:32:27 +00:00
cd "$WS_BASE/${BINARYLOOKUPPATH}" || exit 5
2022-12-04 14:50:37 +00:00
while IFS= read -r -d $'\0' infile; do
map "$infile"
done < <(find . -maxdepth 1 -type f -name "${FILE_WIHTOUT_PLATFORM}-*" -print0)
2022-12-06 13:57:45 +00:00
cd "$WS_BASE"