2021-01-29 01:31:56 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
|
2022-03-07 07:58:20 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
|
2021-03-17 17:27:19 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021 Paul Dersey <pdersey@gmail.com>
|
2021-05-18 12:37:34 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021 Melg Eight <public.melg8@gmail.com>
|
2021-02-18 07:29:58 +00:00
|
|
|
#
|
2021-01-29 01:31:56 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-04-07 00:09:45 +01:00
|
|
|
# shellcheck source=/dev/null
|
2022-05-23 06:56:18 +01:00
|
|
|
. "${SOURCES}/bootstrap.cfg"
|
2022-04-07 00:09:45 +01:00
|
|
|
|
2022-05-04 00:48:02 +01:00
|
|
|
# Get a list of files
|
|
|
|
get_files() {
|
|
|
|
local prefix
|
|
|
|
prefix="${1}"
|
|
|
|
fs=
|
|
|
|
if [ -n "$(ls 2>/dev/null)" ]; then
|
|
|
|
fs=$(echo ./*)
|
|
|
|
fi
|
|
|
|
if [ -n "$(ls .[0-z]* 2>/dev/null)" ]; then
|
|
|
|
fs="${fs} $(echo .[0-z]*)"
|
|
|
|
fi
|
|
|
|
for f in ${fs}; do
|
|
|
|
if [ -d "${f}" ]; then
|
|
|
|
cd "${f}"
|
|
|
|
get_files "${prefix}/${f}"
|
|
|
|
cd ..
|
|
|
|
else
|
|
|
|
echo -n "${prefix}/${f} "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:02:08 +00:00
|
|
|
# Reset all timestamps to unix time 0
|
|
|
|
reset_timestamp() {
|
2022-02-23 09:59:57 +00:00
|
|
|
if command -v find >/dev/null 2>&1; then
|
2022-02-19 00:57:51 +00:00
|
|
|
# find does not error out on exec error
|
2022-05-17 01:01:48 +01:00
|
|
|
find . -print0 | xargs -0 touch -h -t 197001010000.00
|
2022-02-10 10:55:06 +00:00
|
|
|
else
|
|
|
|
# A rudimentary find implementation that does the trick
|
|
|
|
fs=
|
2022-02-23 09:59:57 +00:00
|
|
|
if [ -n "$(ls 2>/dev/null)" ]; then
|
2022-03-07 07:58:20 +00:00
|
|
|
fs=$(echo ./*)
|
2022-01-14 11:02:08 +00:00
|
|
|
fi
|
2022-02-23 09:59:57 +00:00
|
|
|
if [ -n "$(ls .[0-z]* 2>/dev/null)" ]; then
|
2022-02-10 10:55:06 +00:00
|
|
|
fs="${fs} $(echo .[0-z]*)"
|
2022-01-14 11:02:08 +00:00
|
|
|
fi
|
2022-02-10 10:55:06 +00:00
|
|
|
for f in ${fs}; do
|
2022-05-17 01:01:48 +01:00
|
|
|
touch -h -t 197001010000.00 "${f}"
|
2022-02-10 10:55:06 +00:00
|
|
|
if [ -d "${f}" ]; then
|
|
|
|
cd "${f}"
|
|
|
|
reset_timestamp
|
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2022-01-14 11:02:08 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 09:59:57 +00:00
|
|
|
# Fake grep
|
2022-04-04 11:50:35 +01:00
|
|
|
_grep() {
|
2022-05-17 01:01:48 +01:00
|
|
|
local text="${1}"
|
|
|
|
local fname="${2}"
|
2022-04-04 11:50:35 +01:00
|
|
|
if command -v grep >/dev/null 2>&1; then
|
|
|
|
grep "${text}" "${fname}"
|
|
|
|
else
|
|
|
|
# shellcheck disable=SC2162
|
|
|
|
while read line; do
|
|
|
|
case "${line}" in *"${text}"*)
|
|
|
|
echo "${line}" ;;
|
|
|
|
esac
|
|
|
|
done < "${fname}"
|
|
|
|
fi
|
2022-02-23 09:59:57 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 23:00:47 +01:00
|
|
|
get_revision() {
|
|
|
|
local pkg=$1
|
|
|
|
cd "${SRCDIR}/repo"
|
|
|
|
# Get revision (n time this package has been built)
|
|
|
|
revision="$(echo "${pkg}"*)"
|
|
|
|
# Different versions of bash
|
|
|
|
if [ "${revision}" = "${pkg}*" ] || [ -z "${revision}" ]; then
|
|
|
|
revision=0
|
|
|
|
else
|
|
|
|
revision="${revision##*_}"
|
|
|
|
revision="${revision%%.*}"
|
|
|
|
revision=$((++revision))
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Installs binary packages from an earlier run
|
|
|
|
# This is useful to speed up development cycle
|
|
|
|
bin_preseed() {
|
|
|
|
if [ -d "${SRCDIR}/repo-preseeded" ]; then
|
|
|
|
get_revision "${pkg}"
|
|
|
|
cd "${SRCDIR}/repo-preseeded"
|
2022-10-23 00:16:35 +01:00
|
|
|
if [ "${UPDATE_CHECKSUMS}" = "True" ] || src_checksum "${pkg}" $((revision)); then
|
2022-05-24 23:00:47 +01:00
|
|
|
echo "${pkg}: installing prebuilt package."
|
2022-10-23 00:17:05 +01:00
|
|
|
mv "${pkg}_${revision}"* ../repo || \
|
|
|
|
mv "${pkg%-*}${pkg##*-}-0_${revision}"* ../repo || \
|
|
|
|
return 1
|
2022-05-24 23:00:47 +01:00
|
|
|
if [[ "${pkg}" == bash-* ]]; then
|
|
|
|
# tar does not like overwriting running bash
|
|
|
|
# shellcheck disable=SC2153
|
|
|
|
rm -f "${PREFIX}/bin/bash" "${PREFIX}/bin/sh"
|
|
|
|
fi
|
|
|
|
# shellcheck disable=SC2144
|
|
|
|
if [ -f *-repodata ]; then
|
|
|
|
mv -- *-repodata ../repo
|
|
|
|
fi
|
|
|
|
cd "${SRCDIR}/repo"
|
2022-10-02 23:39:25 +01:00
|
|
|
rm -f /tmp/filelist.txt
|
2022-05-24 23:00:47 +01:00
|
|
|
src_apply "${pkg}" $((revision))
|
|
|
|
cd "${SOURCES}"
|
2022-06-02 20:25:23 +01:00
|
|
|
return 0
|
2022-05-24 23:00:47 +01:00
|
|
|
fi
|
|
|
|
fi
|
2022-06-02 20:25:23 +01:00
|
|
|
return 1
|
2022-05-24 23:00:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:31:56 +00:00
|
|
|
# Common build steps
|
|
|
|
# Build function provides a few common stages with default implementation
|
|
|
|
# that can be overridden on per package basis in the build script.
|
2021-02-18 07:29:58 +00:00
|
|
|
# build takes three arguments:
|
2021-01-29 01:31:56 +00:00
|
|
|
# 1) name-version of the package
|
|
|
|
# 2) optionally specify build script. Default is name-version.sh
|
2022-05-04 19:32:45 +01:00
|
|
|
# 3) directory of patches. Default is patches
|
|
|
|
# 4) directory to cd into. Default is ${pkg}
|
2022-01-14 11:02:08 +00:00
|
|
|
build() {
|
2021-01-29 01:31:56 +00:00
|
|
|
pkg=$1
|
|
|
|
script_name=${2:-${pkg}.sh}
|
2022-05-04 19:32:45 +01:00
|
|
|
dirname=${4:-${pkg}}
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2022-11-02 03:35:48 +00:00
|
|
|
# shellcheck ignore=SC2015
|
2022-10-02 23:39:25 +01:00
|
|
|
bin_preseed && return || true # Normal build if preseed fails
|
2022-05-24 23:00:47 +01:00
|
|
|
|
2021-06-24 00:32:19 +01:00
|
|
|
cd "${SOURCES}/${pkg}" || (echo "Cannot cd into ${pkg}!"; kill $$)
|
2021-01-28 18:53:44 +00:00
|
|
|
echo "${pkg}: beginning build using script ${script_name}"
|
2021-01-29 01:31:56 +00:00
|
|
|
base_dir="${PWD}"
|
2022-05-04 19:32:45 +01:00
|
|
|
patch_dir="${base_dir}/${3:-patches}"
|
2021-01-29 01:31:56 +00:00
|
|
|
mk_dir="${base_dir}/mk"
|
2021-01-28 18:53:44 +00:00
|
|
|
files_dir="${base_dir}/files"
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2022-04-13 00:08:29 +01:00
|
|
|
rm -rf "build"
|
|
|
|
mkdir "build"
|
2021-01-29 01:31:56 +00:00
|
|
|
cd "build"
|
|
|
|
|
|
|
|
build_script="${base_dir}/${script_name}"
|
|
|
|
if test -e "${build_script}"; then
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "${build_script}"
|
|
|
|
fi
|
2021-02-03 21:30:02 +00:00
|
|
|
|
2022-05-12 10:50:28 +01:00
|
|
|
echo "${pkg}: getting sources."
|
|
|
|
build_stage=src_get
|
|
|
|
call $build_stage
|
|
|
|
|
2021-02-03 21:30:02 +00:00
|
|
|
echo "${pkg}: unpacking source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_unpack
|
|
|
|
call $build_stage
|
2022-04-24 04:59:17 +01:00
|
|
|
unset EXTRA_DISTFILES
|
2021-02-03 21:30:02 +00:00
|
|
|
|
2021-04-13 13:34:11 +01:00
|
|
|
cd "${dirname}" || (echo "Cannot cd into build/${dirname}!"; kill $$)
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: preparing source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_prepare
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: configuring source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_configure
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
|
|
|
echo "${pkg}: compiling source."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_compile
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2022-01-14 11:02:08 +00:00
|
|
|
echo "${pkg}: install to fakeroot."
|
2021-05-03 23:48:06 +01:00
|
|
|
build_stage=src_install
|
|
|
|
call $build_stage
|
2021-01-29 01:31:56 +00:00
|
|
|
|
2022-01-14 11:02:08 +00:00
|
|
|
echo "${pkg}: creating package."
|
2022-05-24 23:00:47 +01:00
|
|
|
get_revision "${pkg}"
|
2022-04-04 11:50:35 +01:00
|
|
|
cd "${DESTDIR}"
|
|
|
|
src_pkg
|
2022-01-14 11:02:08 +00:00
|
|
|
|
2022-05-24 23:00:47 +01:00
|
|
|
src_checksum "${pkg}" "${revision}"
|
2021-02-18 07:29:58 +00:00
|
|
|
|
2021-06-10 11:24:50 +01:00
|
|
|
echo "${pkg}: cleaning up."
|
2022-01-14 11:02:08 +00:00
|
|
|
rm -rf "${SOURCES}/${pkg}/build"
|
2022-04-13 00:08:29 +01:00
|
|
|
rm -rf "${DESTDIR}"
|
|
|
|
mkdir -p "${DESTDIR}"
|
2022-01-14 11:02:08 +00:00
|
|
|
|
|
|
|
echo "${pkg}: installing package."
|
2022-05-24 23:00:47 +01:00
|
|
|
src_apply "${pkg}" "${revision}"
|
2021-06-10 11:24:50 +01:00
|
|
|
|
2021-01-29 01:31:56 +00:00
|
|
|
echo "${pkg}: build successful"
|
2022-01-14 11:02:08 +00:00
|
|
|
|
2021-06-24 00:32:19 +01:00
|
|
|
cd "${SOURCES}"
|
2021-02-03 22:09:21 +00:00
|
|
|
|
|
|
|
unset -f src_unpack src_prepare src_configure src_compile src_install
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:35:31 +01:00
|
|
|
interpret_source_line() {
|
|
|
|
url="${1}"
|
|
|
|
checksum="${2}"
|
|
|
|
fname="${3}"
|
|
|
|
# Default to basename of url if not given
|
|
|
|
fname="${fname:-$(basename "${url}")}"
|
|
|
|
if ! [ -e "${fname}" ]; then
|
|
|
|
curl -L "${url}" --output "${fname}"
|
|
|
|
fi
|
|
|
|
echo "${checksum} ${fname}" | sha256sum -c
|
|
|
|
}
|
|
|
|
|
2022-05-12 10:50:28 +01:00
|
|
|
# Default get function that downloads source tarballs.
|
|
|
|
default_src_get() {
|
2022-05-23 06:56:18 +01:00
|
|
|
# shellcheck disable=SC2153
|
|
|
|
cd "${DISTFILES}"
|
2022-09-29 11:35:31 +01:00
|
|
|
# shellcheck disable=SC2162
|
|
|
|
while read line; do
|
|
|
|
# This is intentional - we want to split out ${line} into separate arguments.
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
interpret_source_line ${line}
|
|
|
|
done < "${base_dir}/sources"
|
2022-05-23 06:56:18 +01:00
|
|
|
cd -
|
2022-05-12 10:50:28 +01:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:35:31 +01:00
|
|
|
# Intelligently extracts a file based upon its filetype.
|
|
|
|
extract_file() {
|
2022-10-23 00:17:05 +01:00
|
|
|
f="${3:-$(basename "${1}")}"
|
2022-09-29 11:35:31 +01:00
|
|
|
if test $# -gt 3; then
|
|
|
|
shift 3
|
|
|
|
extract="$*"
|
2022-05-12 10:50:28 +01:00
|
|
|
else
|
2022-09-29 11:35:31 +01:00
|
|
|
extract=
|
2022-05-12 10:50:28 +01:00
|
|
|
fi
|
2022-09-29 11:35:31 +01:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
case "${noextract}" in
|
|
|
|
*${f}*)
|
|
|
|
cp "${DISTFILES}/${f}" .
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
case "${f}" in
|
|
|
|
*.tar*)
|
|
|
|
if test -e "${PREFIX}/libexec/rmt"; then
|
|
|
|
# Again, we want to split out into words.
|
|
|
|
# shellcheck disable=SC2086
|
2022-10-10 12:23:04 +01:00
|
|
|
tar --no-same-owner -xf "${DISTFILES}/${f}" ${extract}
|
2022-09-29 11:35:31 +01:00
|
|
|
else
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
case "${f}" in
|
2022-10-10 12:23:04 +01:00
|
|
|
*.tar.gz) tar -xzf "${DISTFILES}/${f}" ${extract} ;;
|
2022-09-29 11:35:31 +01:00
|
|
|
*.tar.bz2)
|
|
|
|
# Initial bzip2 built against meslibc has broken pipes
|
2022-10-10 12:23:04 +01:00
|
|
|
bzip2 -dc "${DISTFILES}/${f}" | tar -xf - ${extract} ;;
|
2022-09-29 11:35:31 +01:00
|
|
|
*.tar.xz)
|
2022-10-10 12:23:04 +01:00
|
|
|
tar -xf "${DISTFILES}/${f}" --use-compress-program=xz ${extract} ;;
|
2022-09-29 11:35:31 +01:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
cp "${DISTFILES}/${f}" .
|
|
|
|
;;
|
2022-04-13 00:08:29 +01:00
|
|
|
esac
|
2022-09-29 11:35:31 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Default unpacking function that unpacks all sources.
|
|
|
|
default_src_unpack() {
|
|
|
|
# Handle the first one differently
|
|
|
|
first_line=$(head -n 1 ../sources)
|
|
|
|
# Again, we want to split out into words.
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
extract_file ${first_line}
|
|
|
|
# This assumes there is only one directory in the tarball
|
|
|
|
# Get the dirname "smartly"
|
|
|
|
if ! [ -e "${dirname}" ]; then
|
|
|
|
for i in *; do
|
|
|
|
if [ -d "${i}" ]; then
|
|
|
|
dirname="${i}"
|
|
|
|
break
|
|
|
|
fi
|
2021-05-08 12:32:40 +01:00
|
|
|
done
|
|
|
|
fi
|
2022-09-29 11:35:31 +01:00
|
|
|
# shellcheck disable=SC2162
|
|
|
|
tail -n +2 ../sources | while read line; do
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
extract_file ${line}
|
|
|
|
done
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Default function to prepare source code.
|
|
|
|
# It applies all patches from patch_dir (at the moment only -p0 patches are supported).
|
2021-01-28 18:53:44 +00:00
|
|
|
# Then it copies our custom makefile and any other custom files from files directory.
|
2021-01-29 01:31:56 +00:00
|
|
|
default_src_prepare() {
|
|
|
|
if test -d "${patch_dir}"; then
|
|
|
|
for p in "${patch_dir}"/*.patch; do
|
2021-03-02 22:02:07 +00:00
|
|
|
echo "Applying patch: ${p}"
|
2021-01-29 01:31:56 +00:00
|
|
|
patch -Np0 < "${p}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
makefile="${mk_dir}/main.mk"
|
|
|
|
if test -e "${makefile}"; then
|
|
|
|
cp "${makefile}" Makefile
|
|
|
|
fi
|
2021-01-28 18:53:44 +00:00
|
|
|
|
|
|
|
if test -d "${files_dir}"; then
|
|
|
|
cp "${files_dir}"/* "${PWD}/"
|
|
|
|
fi
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Default function for configuring source.
|
|
|
|
default_src_configure() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
|
|
|
# Default function for compiling source. It simply runs make without any parameters.
|
|
|
|
default_src_compile() {
|
2021-04-02 12:24:40 +01:00
|
|
|
make -f Makefile PREFIX="${PREFIX}"
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Default installing function. PREFIX should be set by run.sh script.
|
|
|
|
# Note that upstream makefiles might ignore PREFIX and have to be configured in configure stage.
|
|
|
|
default_src_install() {
|
2021-04-02 12:24:40 +01:00
|
|
|
make -f Makefile install PREFIX="${PREFIX}" DESTDIR="${DESTDIR}"
|
2021-01-29 01:31:56 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 11:50:35 +01:00
|
|
|
create_tarball_pkg() {
|
2022-04-05 18:43:23 +01:00
|
|
|
# If grep is unavailable, then tar --sort is unavailable.
|
2022-04-04 11:50:35 +01:00
|
|
|
# So this does not need a command -v grep.
|
2022-05-18 23:58:01 +01:00
|
|
|
tar_basename="${pkg}_${revision}.tar"
|
|
|
|
dest_tar="/usr/src/repo/${tar_basename}"
|
|
|
|
if command -v find >/dev/null 2>&1 && command -v sort >/dev/null 2>&1; then
|
|
|
|
find . -print0 | LC_ALL=C sort -z > /tmp/filelist.txt
|
|
|
|
fi
|
|
|
|
cd /usr/src/repo
|
|
|
|
|
2022-04-04 11:50:35 +01:00
|
|
|
if tar --help | grep ' \-\-sort' >/dev/null 2>&1; then
|
2022-05-13 10:45:23 +01:00
|
|
|
tar -C "${DESTDIR}" --sort=name --hard-dereference \
|
2022-05-18 23:58:01 +01:00
|
|
|
--numeric-owner --owner=0 --group=0 --mode=go=rX,u+rw,a-s -cf "${dest_tar}" .
|
2022-04-04 11:50:35 +01:00
|
|
|
elif command -v find >/dev/null 2>&1 && command -v sort >/dev/null 2>&1; then
|
|
|
|
cd "${DESTDIR}"
|
2022-05-13 10:45:23 +01:00
|
|
|
tar --no-recursion --null -T /tmp/filelist.txt \
|
2022-05-18 23:58:01 +01:00
|
|
|
--numeric-owner --owner=0 --group=0 --mode=go=rX,u+rw,a-s -cf "${dest_tar}"
|
2022-04-04 11:50:35 +01:00
|
|
|
cd -
|
|
|
|
else
|
2022-05-04 00:48:02 +01:00
|
|
|
echo -n > /dev/null
|
2022-05-13 10:45:23 +01:00
|
|
|
tar --numeric-owner --owner=0 --group=0 --mode=go=rX,u+rw,a-s \
|
2022-05-18 23:58:01 +01:00
|
|
|
-cf "${dest_tar}" -T /dev/null
|
2022-05-04 00:48:02 +01:00
|
|
|
cd "${DESTDIR}"
|
|
|
|
for f in $(get_files .); do
|
2022-05-13 10:45:23 +01:00
|
|
|
tar --numeric-owner --owner=0 --group=0 --mode=go=rX,u+rw,a-s \
|
2022-05-18 23:58:01 +01:00
|
|
|
-rf "${dest_tar}" "${f}"
|
2022-05-04 00:48:02 +01:00
|
|
|
done
|
|
|
|
cd -
|
2022-04-04 11:50:35 +01:00
|
|
|
fi
|
2022-05-18 23:58:01 +01:00
|
|
|
touch -t 197001010000.00 "${tar_basename}"
|
|
|
|
bzip2 --best "${tar_basename}"
|
2022-04-04 11:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
src_pkg() {
|
|
|
|
touch -t 197001010000.00 .
|
|
|
|
reset_timestamp
|
|
|
|
if command -v xbps-create >/dev/null 2>&1; then
|
|
|
|
cd /usr/src/repo
|
2022-10-23 00:17:05 +01:00
|
|
|
xbps-create -A "${ARCH}" -n "${pkg%-*}${pkg##*-}-0_${revision}" -s "${pkg}" --compression xz "${DESTDIR}"
|
2022-04-04 11:50:35 +01:00
|
|
|
echo "${pkg}: adding package to repository."
|
2022-10-23 00:17:05 +01:00
|
|
|
xbps-rindex --compression xz -a "/usr/src/repo/${pkg%-*}${pkg##*-}-0_${revision}.${ARCH}.xbps"
|
2022-04-04 11:50:35 +01:00
|
|
|
else
|
|
|
|
create_tarball_pkg
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-04-07 00:09:45 +01:00
|
|
|
src_checksum() {
|
2022-05-24 23:00:47 +01:00
|
|
|
local pkg=$1 revision=$2
|
|
|
|
local rval=0
|
2022-04-07 00:09:45 +01:00
|
|
|
if ! [ "$UPDATE_CHECKSUMS" = True ] ; then
|
2022-05-17 01:01:48 +01:00
|
|
|
# We avoid using pipes as that is not supported by initial sha256sum from mescc-tools-extra
|
|
|
|
local checksum_file=/tmp/checksum
|
2022-10-23 00:17:05 +01:00
|
|
|
_grep "${pkg}_${revision}" "${SOURCES}/SHA256SUMS.pkgs" > "${checksum_file}" || true
|
|
|
|
# XBPS style;
|
|
|
|
_grep "${pkg%-*}${pkg##*-}-0_${revision}" "${SOURCES}/SHA256SUMS.pkgs" >> "${checksum_file}" || true
|
|
|
|
# Check there is something in checksum_file
|
|
|
|
if ! [ -s "${checksum_file}" ]; then
|
|
|
|
echo "${pkg}: no checksum stored!"
|
|
|
|
false
|
|
|
|
fi
|
2022-05-24 23:00:47 +01:00
|
|
|
echo "${pkg}: checksumming created package."
|
|
|
|
sha256sum -c "${checksum_file}" || rval=$?
|
2022-05-17 01:01:48 +01:00
|
|
|
rm "${checksum_file}"
|
2022-04-07 00:09:45 +01:00
|
|
|
fi
|
2022-05-24 23:00:47 +01:00
|
|
|
return "${rval}"
|
2022-04-07 00:09:45 +01:00
|
|
|
}
|
|
|
|
|
2022-04-04 11:50:35 +01:00
|
|
|
src_apply() {
|
2022-05-24 23:00:47 +01:00
|
|
|
local pkg="${1}" revision="${2}"
|
2022-04-04 11:50:35 +01:00
|
|
|
if command -v xbps-install >/dev/null 2>&1; then
|
2022-10-23 00:17:05 +01:00
|
|
|
xbps-install -y -R /usr/src/repo "${pkg%-*}${pkg##*-}"
|
2022-04-04 11:50:35 +01:00
|
|
|
else
|
2022-05-08 20:04:29 +01:00
|
|
|
src_apply_tar "${pkg}" "${revision}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
src_apply_tar() {
|
|
|
|
local pkg=$1 revision=$2
|
|
|
|
# Overwriting files is mega busted, so do it manually
|
|
|
|
# shellcheck disable=SC2162
|
|
|
|
if [ -e /tmp/filelist.txt ]; then
|
|
|
|
while IFS= read -d $'\0' file; do
|
|
|
|
rm -f "/${file}" >/dev/null 2>&1 || true
|
|
|
|
done < /tmp/filelist.txt
|
2022-04-04 11:50:35 +01:00
|
|
|
fi
|
2022-05-17 01:01:48 +01:00
|
|
|
|
|
|
|
# Bzip2 does not like to be overwritten
|
|
|
|
if [[ "${pkg}" == bzip2-* ]]; then
|
|
|
|
mkdir -p /tmp
|
|
|
|
mv "${PREFIX}/bin/bzip2" "/tmp/bzip2"
|
|
|
|
BZIP2_PREFIX="/tmp/"
|
|
|
|
fi
|
|
|
|
"${BZIP2_PREFIX}bzip2" -dc "/usr/src/repo/${pkg}_${revision}.tar.bz2" | \
|
2022-05-08 20:04:29 +01:00
|
|
|
tar -C / -xpf -
|
2022-05-17 01:01:48 +01:00
|
|
|
unset BZIP2_PREFIX
|
|
|
|
rm -f "/tmp/bzip2"
|
2022-04-04 11:50:35 +01:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:31:56 +00:00
|
|
|
# Check if bash function exists
|
|
|
|
fn_exists() {
|
|
|
|
test "$(type -t "$1")" == 'function'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call package specific function or default implementation.
|
|
|
|
call() {
|
|
|
|
if fn_exists "$1"; then
|
|
|
|
$1
|
|
|
|
else
|
|
|
|
default_"${1}"
|
|
|
|
fi
|
|
|
|
}
|
2021-05-03 23:48:06 +01:00
|
|
|
|
|
|
|
# Call default build stage function
|
|
|
|
default() {
|
|
|
|
"default_${build_stage}"
|
|
|
|
}
|
2021-05-18 12:37:34 +01:00
|
|
|
|
2021-06-24 00:32:19 +01:00
|
|
|
# Set modified dates of all files to be 0 unix time.
|
2021-05-18 12:37:34 +01:00
|
|
|
# Should be called at the end of bootstrapping process.
|
|
|
|
# This function needs `touch` that supports --no-dereference
|
|
|
|
# (at least coreutils 8.1).
|
|
|
|
canonicalise_all_files_timestamp() {
|
|
|
|
find / -exec touch --no-dereference -t 197001010000.00 {} +
|
|
|
|
}
|
2021-08-05 13:16:19 +01:00
|
|
|
|
|
|
|
populate_device_nodes() {
|
|
|
|
# http://www.linuxfromscratch.org/lfs/view/6.1/chapter06/devices.html
|
2022-05-23 06:56:18 +01:00
|
|
|
mkdir -p "/dev"
|
|
|
|
test -c "/dev/null" || (rm -f "/dev/null" &&
|
|
|
|
mknod -m 666 "/dev/null" c 1 3)
|
|
|
|
test -c "/dev/zero" || mknod -m 666 "/dev/zero" c 1 5
|
|
|
|
test -c "/dev/random" || mknod -m 444 "/dev/random" c 1 8
|
|
|
|
test -c "/dev/urandom" || mknod -m 444 "/dev/urandom" c 1 9
|
2021-12-28 22:39:01 +00:00
|
|
|
|
|
|
|
if [ "${CHROOT}" = False ]; then
|
2022-05-23 06:56:18 +01:00
|
|
|
test -c "/dev/ptmx" || mknod -m 666 "/dev/ptmx" c 5 2
|
|
|
|
test -c "/dev/tty" || mknod -m 666 "/dev/tty" c 5 0
|
|
|
|
test -c "/dev/console" || mknod -m 666 "/dev/console" c 5 1
|
2021-12-28 22:39:01 +00:00
|
|
|
fi
|
2021-08-05 13:16:19 +01:00
|
|
|
}
|
2022-05-08 20:04:29 +01:00
|
|
|
|
|
|
|
sys_transfer() {
|
|
|
|
local dest=$1
|
2022-05-22 01:03:21 +01:00
|
|
|
local sys_sources=$2
|
2022-05-08 20:04:29 +01:00
|
|
|
|
|
|
|
mkdir -p "${dest}/${PREFIX}/bin" "${dest}/${PREFIX}/src"
|
|
|
|
|
|
|
|
# Bash, Tar and Bzip2 are required to install packages
|
|
|
|
cp "${PREFIX}/bin/bash" "${PREFIX}/bin/tar" "${PREFIX}/bin/bzip2" "${dest}${PREFIX}/bin/"
|
|
|
|
|
|
|
|
# Transfer misc files
|
2022-05-22 01:03:21 +01:00
|
|
|
cp "${SOURCES}/helpers.sh" "${SOURCES}/SHA256SUMS.pkgs" "${SOURCES}/bootstrap.cfg" "${dest}/${PREFIX}/src"
|
2022-05-08 20:04:29 +01:00
|
|
|
|
2022-05-23 06:56:18 +01:00
|
|
|
cp -r "${sys_sources}/"* "${dest}/${PREFIX}/src"
|
2022-05-22 01:03:21 +01:00
|
|
|
cp -f "${sys_sources}/init" "${dest}/"
|
|
|
|
cp -r "${PREFIX}/src/repo" "${dest}/${PREFIX}/src"
|
2022-10-02 23:39:25 +01:00
|
|
|
if [ -e "${PREFIX}/src/repo-preseeded" ]; then
|
|
|
|
cp -r "${PREFIX}/src/repo-preseeded" "${dest}/${PREFIX}/src"
|
|
|
|
fi
|
2022-05-08 20:04:29 +01:00
|
|
|
|
2022-05-22 01:03:21 +01:00
|
|
|
shift 2
|
2022-05-08 20:04:29 +01:00
|
|
|
# Copy additional binaries
|
|
|
|
set -- "${@/#/${PREFIX}/bin/}"
|
|
|
|
cp "$@" "${dest}${PREFIX}/bin/"
|
|
|
|
}
|