8000 minix/distrib/sets/regpkg at main · k0mr4d3/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
executable file
·
1072 lines (1013 loc) · 30.4 KB

regpkg

File metadata and controls

executable file
·
1072 lines (1013 loc) · 30.4 KB
# Failing that, depend on any version "-[0-9]*".
#
# XXX: We could extend the format of the "deps" file to carry
# this sort of information, so we wouldn't have to guess.
#
case "${t}" in
${osvers}.*) depversion=">=${osvers}" ;;
*) depversion="-[0-9]*" ;;
esac
#
# Add the dependencies.
#
# We always add a "@pkgdep" line for each prerequisite package.
#
# If the prerequisite pkg is already registered (as it should be
# if our caller is doing things in the right order), then we put
# its exact version number in a "@blddep" line.
#
${AWK} '$1 ~ '/"${pkg}"/' { print $2 }' "${rundir}/deps" | ${SORT} | \
while read depname; do
# ${pkgdepglob} is a shell glob pattern that should match
# any version of a pkg. ${pkgdep} uses the special syntax
# for pkg dependencies, and is not usable as a shell
# glob pattern.
pkgdepglob="${depname}-[0-9]*"
pkgdep="${depname}${depversion}"
echo "@pkgdep ${pkgdep}"
blddep="$(cd "${SYSPKG_DB_TOPDIR}" && echo ${pkgdepglob} \
|| bomb)"
case "${blddep}" in
*\*) # pkgdepglob did not match anything
echo >&2 "${WARNING}${pkg} depends on '${pkgdep}' but there is no matching syspkg in ${SYSPKG_DB_TOPDIR}"
;;
*\ *) # pkgdepglob matched more than once.
echo >&2 "${ERRWARN}${pkg} depends on '${pkgdep}' but there are multiple matching syspkgs in ${SYSPKG_DB_TOPDIR}"
${force} || bomb
# If ${force} is set, then assume that the last
# match is the most recent.
# XXX: This might be wrong, because of
# differences between lexical sorting and
# numeric sorting.
lastmatch="${blddep##* }"
echo "@blddep ${lastmatch}"
;;
*) # exactly one match.
# XXX: We ignore the possibility that the
# version we found via ${pkgdepglob} might not
# satisfy ${pkgdep}. We could conceivably use
# "pkg_admin pmatch" to check, but that's not a
# host tool so we can't assume that it will be
# available.
echo "@blddep ${blddep}"
;;
esac
done >>"${PLIST}"
# create the comment (should be one line)
comment="$(${AWK} '$1 ~ '/"${pkg}"/' \
{ print substr($0, length($1) + 2) }' \
"${rundir}/comments")"
case "${comment}" in
"") echo >&2 "${WARNING}no comment for \"${pkg}\" (using placeholder)"
comment="System package for ${pkg}"
;;
*"${nl}"*)
echo >&2 "${ERRWARN}multi-line comment for \"${pkg}\""
${force} || bomb
;;
esac
echo "${comment}" > "${SYSPKG_DB_SUBDIR}/+COMMENT"
# create the description (could be multiple lines)
descr="$(${AWK} '$1 ~ '/"${pkg}"/' {
print substr($0, length($1) + 2) }' \
"${rundir}/descrs")"
case "${descr}" in
"") echo >&2 "${WARNING}no description for \"${pkg}\" (re-using comment)" 2>&1
descr="${comment}"
;;
esac
echo "${descr}" > "${SYSPKG_DB_SUBDIR}/+DESC"
${PRINTF} "\nHomepage:\nhttp://www.NetBSD.org/\n" >> "${SYSPKG_DB_SUBDIR}/+DESC"
# create the build information
if [ x"${BUILD_INFO_CACHE}" = x ]; then
{
# These variables describe the build
# environment, not the target.
echo "OPSYS=$(${UNAME} -s)"
echo "OS_VERSION=$(${UNAME} -r)"
${MAKE} -B -f- all <<EOF
.include <bsd.own.mk>
all:
@echo OBJECT_FMT=${OBJECT_FMT}
@echo MACHINE_ARCH=${MACHINE_ARCH}
@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
EOF
} > "${SYSPKG_DB_SUBDIR}/+BUILD_INFO"
else
cp "${BUILD_INFO_CACHE}" "${SYSPKG_DB_SUBDIR}/+BUILD_INFO"
fi
# test for attributes
args=""
attrs="$(${AWK} '$1 ~ '/"${pkg}"/' { \
print substr($0, length($1) + 2) }' \
"${rundir}/attrs")"
for a in "${attrs}"; do
case "${attrs}" in
"") ;;
preserve)
echo "${pkg}-${t}" >"${SYSPKG_DB_SUBDIR}/+PRESERVE"
args="${args} -n ${SYSPKG_DB_SUBDIR}/+PRESERVE"
;;
esac
done
#
# Create ${SYSPKGSIR}/+CONTENTS from ${PLIST}, by adding an
# "@name" line and a lot of "@comment MD5:" lines.
#
{
rcsid='$NetBSD: regpkg,v 1.20 2012/11/03 07:59:46 mbalmer Exp $'
utcdate="$(${ENV_CMD} TZ=UTC LOCALE=C \
${DATE} '+%Y-%m-%d %H:%M')"
user="${USER:-root}"
host="$(${HOSTNAME_CMD})"
echo "@name ${pkg}-${t}"
echo "@comment Packaged at ${utcdate} UTC by ${user}@${host}"
echo "@comment Packaged using ${prog} ${rcsid}"
# XXX: "option extract-in-place" might help to get
# pkg_add to create directories.
# XXX: no, it doesn't work. Yet another pkg_add bug.
## echo "@option extract-in-place"
# Move the @pkgdep and @blddep lines up, so that
# they are easy to see when people do "less
# ${DESTDIR}/var/db/syspkg/*/+CONTENTS".
${EGREP} '^(@pkgdep|@blddep)' "${PLIST}" || true
# Now do the remainder of the file.
while read line; do
case "${line}" in
@pkgdep*|@blddep*)
# already handled by grep above
;;
@cwd*)
# There should be exactly one @cwd line.
# Just after it, add an "@exec mkdir"
# line for every directory. This is to
# work around a pkg-add bug (see
# <http://mail-index.NetBSD.org/tech-pkg/2003/12/11/0018.html>)
echo "${line}"
print_dir_exec_lines
;;
@*)
# just pass through all other @foo lines
echo "${line}"
;;
*)
# This should be a file name. Pass it
# through, and append "@comment MD5:".
# XXX why not SHA256 ?
echo "${line}"
file="${DESTDIR}${line}"
if [ -f "${file}" -a -r "${file}" ];
then
md5sum="$(${CKSUM} -n -m "${file}" \
| ${AWK} '{print $1}'
)"
echo "@comment MD5:${md5sum}"
fi
;;
esac
done <"${PLIST}"
} >"${SYSPKG_DB_SUBDIR}/+CONTENTS"
#
# Update ${SYSPKG_DB_TOPDIR}/pkgdb.byfile.db.
#
{
init_db_opts # sets dbfile, dbtype, and db_opts
# Transform ${PLIST} into a form to be used as keys in
# ${dbfile}. The results look like absolute paths,
# but they are really relative to ${DESTDIR}.
#
# "@dirrm ." -> "/"
# "@dirrm foo/bar" -> "/foo/bar"
# "@dirrm ./foo/bar" -> "/foo/bar"
# "foo/bar/baz" -> "/foo/bar/baz"
# "./foo/bar/baz" -> "/foo/bar/baz"
#
dblist="${SCRATCH}/dblist"
${AWK} '/^@dirrm \.\// {gsub("^.", "", $2); print $2; next}
/^@dirrm \.$/ {print "/"; next}
/^@dirrm/ {print "/" $2; next}
/^@/ {next}
/^\.\// {gsub("^.", "", $0); print $0; next}
/./ {print "/" $0; next}' \
<"${PLIST}" >"${dblist}"
# Add all the path names to the database.
${AWK} '{print $1 "\t" "'"${pkg}-${t}"'"}' <"${dblist}" \
| ${DB} -w ${db_opts} -F "${tab}" -f - "${dbtype}" "${dbfile}"
}
if ${verbose}; then
echo "Registered ${pkg}-${t} in ${SYSPKG_DB_TOPDIR}"
elif ! ${quiet}; then
echo "Registered ${pkg}-${t}"
fi
cleanup_must_delete_dbsubdir=false
}
#
# create_syspkg_tgz() creates the *.tgz file for the package.
#
# The output file is ${binpkgdir}/${pkg}-${t}.tgz.
#
create_syspkg_tgz()
{
#
# pkg_create does not understand metalog files, so we have to
# use pax directly.
#
# We create two specfiles: specfile_overhead describes the
# special files that are part of the package system's metadata
# (+CONTENTS, +COMMENT, +DESCR, and more); and specfile_payload
# describes the files and directories that we actually want as
# part of the package's payload.
#
# We then use the specfiles to create a compressed tarball that
# contains both the overhead files and the payload files.
#
# There's no trivial way to get a single pax run to do
# everything we want, so we run pax twice, with a different
# working directory and a different specfile each time.
#
# We could conceivably make clever use of pax's "-s" option to
# get what we want from a single pax run with a single (more
# complicated) specfile, but the extra trouble doesn't seem
# warranted.
#
cleanup_must_delete_binpkgfile=true
specfile_overhead="${SCRATCH}/spec_overhead"
specfile_payload="${SCRATCH}/spec_payload"
tarball_uncompressed="${SCRATCH}/tarball_uncompressed"
# Create a specfile for all the overhead files (+CONTENTS and
# friends).
{
plusnames_first="${SCRATCH}/plusnames_first"
plusnames_rest="${SCRATCH}/plusnames_rest"
# Ensure that the first few files are in the same order
# that "pkg_create" would have used, just in case anything
# depends on that. Other files in alphabetical order.
SHOULD_BE_FIRST="+CONTENTS +COMMENT +DESC"
(
cd "${SYSPKG_DB_SUBDIR}" || bomb
for file in ${SHOULD_BE_FIRST}; do
[ -e "./${file}" ] && echo "${file}"
done >"${plusnames_first}"
${LS} -1 | ${FGREP} -v -f "${plusnames_first}" \
>"${plusnames_rest}" \
|| true
)
# Convert the file list to specfile format, and override the
# uid/gid/mode.
{
echo ". optional type=dir"
${AWK} '{print "./" $0 " type=file uid=0 gid=0 mode=0444"
}' "${plusnames_first}" "${plusnames_rest}"
} >"${specfile_overhead}"
}
# Create a specfile for the payload of the package.
{
spec1="${SCRATCH}/spec1"
spec2="${SCRATCH}/spec2"
# Transform ${PLIST} into simple specfile format:
#
# "@dirrm ." -> ". type=dir"
# "@dirrm foo/bar" -> "./foo/bar type=dir"
# "@dirrm ./foo/bar" -> "./foo/bar type=dir"
# "foo/bar/baz" -> "./foo/bar/baz"
# "./foo/bar/baz" -> "./foo/bar/baz"
#
# Ignores @cwd lines. This should be safe, given how
# makeplist works.
${AWK} '/^@dirrm \.\// {print $2 " type=dir"; next}
/^@dirrm \.$/ {print ". type=dir"; next}
/^@dirrm/ {print "./" $2 " type=dir"; next}
/^@/ {next}
/^\.\// {print $0; next}
/./ {print "./" $0; next}' \
<"${PLIST}" >"${spec1}"
# If metalog was specified, attributes from metalog override
# attributes in the file system. We also fake up an
# entry for the ./etc/mtree/set.${pkgset} file.
{
if [ -n "${metalog}" ]; then
${AWK} -f "${rundir}/join.awk" \
"${spec1}" "${metalog}"
${AWK} -f "${rundir}/join.awk" \
"${spec1}" /dev/stdin <<EOF
./etc/mtree/set.${pkgset} type=file mode=0444 uname=root gname=operator
EOF
else
cat "${spec1}"
fi
} >"${spec2}"
#
# If a file or directory to was mentioned explicitly
# in ${PLIST} but not mentioned in ${metalog}, then the
# file or directory will not be mentioned in ${spec2}.
# This is an error, and means that the metalog was
# not built correctly.
#
if [ -n "${metalog}" ]; then
names1="${SCRATCH}/names1"
names2="${SCRATCH}/names2"
${AWK} '{print $1}' <"${spec1}" | ${SORT} >"${names1}"
${AWK} '{print $1}' <"${spec2}" | ${SORT} >"${names2}"
if ${FGREP} -v -f "${names2}" "${spec1}" >/dev/null
then
cat >&2 <<EOM
${ERRWARN}The metalog file (${metalog}) does not
contain entries for the following files or directories
which should be part of the ${pkg} syspkg:
EOM
${FGREP} -v -f "${names2}" "${spec1}" >&2
${force} || bomb
fi
if ${FGREP} -v -f "${names1}" "${spec2}" >/dev/null
then
cat >&2 <<EOM
${ERRWARN}The following lines are in the metalog file
(${metalog}), and the corresponding files or directories
should be in the ${pkg} syspkg, but something is wrong:
EOM
${FGREP} -v -f "${names1}" "${spec2}" >&2
bomb
fi
fi
# Add lines (tagged "optional") for any implicit directories.
#
# For example, if we have a file ./foo/bar/baz, then we add
# "./foo/bar optional type=dir", "./foo optional type=dir",
# and ". optional type=dir", unless those directories were
# already mentioned explicitly.
#
${AWK} -f "${rundir}/getdirs.awk" "${spec2}" \
| ${SORT} -u >"${specfile_payload}"
}
# Use two pax invocations followed by gzip to create
# the tgz file.
#
# Remove any leading "./" from path names, because that
# could confuse tools that work with binary packages.
(
cd "${SYSPKG_DB_SUBDIR}" && \
${PAX} -O -w -d -N"${etcdir}" -M '-s,^\./,,' \
-f "${tarball_uncompressed}" \
<"${specfile_overhead}" \
|| bomb
)
(
cd "${DESTDIR:-/}" && \
${PAX} -O -w -d -N"${etcdir}" -M '-s,^\./,,' \
-a -f "${tarball_uncompressed}" \
<"${specfile_payload}" \
|| bomb
)
${GZIP_CMD} -9n <"${tarball_uncompressed}" >"${binpkgfile}" || bomb
# (Extra space is to make message line up with "Registered" message.)
if ${verbose}; then
echo " Packaged ${binpkgfile}"
elif ! ${quiet}; then
echo " Packaged ${binpkgfile##*/}"
fi
cleanup_must_delete_binpkgfile=false
}
#
# do_register_syspkg() registers the syspkg if appropriate.
#
# If SYSPKG_DB_SUBDIR already exists, that might be an error, depending
# on ${force} and ${update} flags.
#
do_register_syspkg()
{
# Check that necessary variables are defined
[ -n "${SYSPKG_DB_TOPDIR}" ] || bomb
[ -n "${SYSPKG_DB_SUBDIR}" ] || bomb
# Create SYSPKG_DB_TOPDIR if necessary
[ -d "${SYSPKG_DB_TOPDIR}" ] || mkdir -p "${SYSPKG_DB_TOPDIR}" || bomb
# A function to delete db entries referring to any version of ${pkg}
delete_old_db_entries()
{
init_db_opts # sets dbfile, dbtype, and db_opts
dblist="${SCRATCH}/dblist"
${DB} ${db_opts} -O "${tab}" "${dbtype}" "${dbfile}" \
| ${AWK} -F "${tab}" '$2 ~ /^'"${pkg}"'-[0-9]/ { print $1 }' \
>"${dblist}"
${DB} -d ${db_opts} -f "${dblist}" "${dbtype}" "${dbfile}"
}
# A function to delete any old version of ${pkg}
delete_old_pkg()
{
pattern="${pkg}-[0-9]*"
matches="$(cd "${SYSPKG_DB_TOPDIR}" && echo ${pattern} \
|| bomb)"
echo >&2 "${NOTE}deleting old pkg (${matches})"
cleanup_must_delete_dbsubdir=true
delete_old_db_entries
( cd "${SYSPKG_DB_TOPDIR}" && rm -rf ${matches} )
}
# Check whether another version of ${pkg} is already registered.
pattern="${pkg}-[0-9]*"
matches="$(cd "${SYSPKG_DB_TOPDIR}" && echo ${pattern} || bomb)"
case "${matches}" in
*\*) ;; # wildcard did not match anything
"${pkg}-${t}") ;; # exact match
*) echo >&2 "${ERRWARNNOTE}another version of ${pkg} is already registered"
${verbose} && echo >&2 " in ${SYSPKG_DB_TOPDIR}"
${verbose} && echo >&2 " (while registering ${pkg}-${t})"
${force} || ${update} || bomb
delete_old_pkg
;;
esac
# Check whether the desired version of ${pkg} is already registered,
# and create it if appropriate.
if [ -d "${SYSPKG_DB_SUBDIR}" ]; then
echo >&2 "${ERRWARNNOTE}${pkg}-${t} is already registered"
${verbose} && echo >&2 " in ${SYSPKG_DB_TOPDIR}"
if ${force}; then
delete_old_pkg
register_syspkg
elif ${update}; then
#
# If all files in SYSPKG_DB_SUBDIR are newer
# than all files in the pkg, then do nothing.
# Else delete and re-register the pkg.
#
[ -n "${newestfile}" ] || init_newestfile
if [ -n "${newestfile}" ]; then
case "$(${FIND} "${SYSPKG_DB_SUBDIR}" -type f \
! -newer "${newestfile}" -print)" \
in
"") ;;
*)
echo >&2 "${NOTE}some files are newer but pkg version is unchanged"
delete_old_pkg
register_syspkg
;;
esac
else
# No files in the pkg? (This could happen
# if a pkg contains only directories.)
# Do nothing (keep the already-registered pkg).
:
fi
else
bomb
fi
else
register_syspkg
fi
}
#
# do_create_syspkg_tgz() creates the binary pkg (*.tgz) if
# appropriate.
#
# If binpkgfile already exists, that might be an error, depending on
# ${force} and ${update} flags.
#
0