2013-10-09 15:11:32 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# MAINTAINER: portmgr@FreeBSD.org
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
if [ -z "${STAGEDIR}" -o -z "${PREFIX}" -o -z "${LOCALBASE}" ]; then
|
|
|
|
echo "STAGEDIR, PREFIX, LOCALBASE required in environment." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-11-23 12:23:19 +00:00
|
|
|
LF=$(printf '\nX')
|
|
|
|
LF=${LF%X}
|
|
|
|
|
2013-10-09 15:11:32 +00:00
|
|
|
warn() {
|
|
|
|
echo "Warning: $@" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
err() {
|
|
|
|
echo "Error: $@" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
shebang() {
|
|
|
|
rc=0
|
2013-11-23 12:23:19 +00:00
|
|
|
IFS="$LF" ; for f in `find ${STAGEDIR} -type f`; do
|
bsd.stage.mk: Fewer false positives, much faster, easier maintenance.
Bugfixes:
* @cmd in pkg-plist is now properly handled.
- It was previously treated the same as though there was a directory
following it, missing the prefix. (ordering matters in case...esac)
- Due to the cwd=${PREFIX} inside the while read line loop, state
tracking was broken and every new line assumed that cwd were the
prefix.
* stage-qa no longer complains about unstripped binaries if debugging is
active (WITH_DEBUG set && WITHOUT_DEBUG unset).
* The compress-man target uses ECHO_MSG, not ECHO_CMD, to print its
build step.
Additions:
* The plist parser now understands @unexec rmdir ... || ... lines,
including those with redirections, so that there are no false
positives for directories stripped with @unexec rmdir (usually
happens on stuff installed outside $PREFIX, as in /var).
* The system's root and var mtrees are now also expanded to avoid
false @dirrm positives if a port installs directories under /var
and has to create parents in the stagedir that are present in a fully
installed system (i. e. in the real $PREFIX).
* Given that pkg_create is deemed beyond repair with respect to deleting
files outside prefix, generate @unexec rmdir statements for such
directories, rather than @dirrmtry, to sidestep the problem.
Speedups:
* the orphan check now generates sorted lists of staged files,
and plisted/mtree files, and compares them with comm(1).
This saves us the overhead of running one grep process per file
and up to two per directory, and defers the actual list
processing to a shell utility. Complexity has not changed,
but overhead per item has.
* the orphan check now uses one file for directories and one file for
files mentioned in pkg-plist, so we need not decorate them with "dir "
and parse them out any longer.
* qa.sh's shebang scanner only looks at the first line of a file,
sed is told to exit from the 2nd line.
Other Changes:
* Split the makeplist/check-orphans logic out of bsd.stage.mk,
it is too unwieldy to maintain in make-escaped shell syntax,
and permits shell tracing with "SH=sh -x" (including quotes!)
* Unify the functions "makeplist" and "check-orphans" in one
script. The only difference is that makeplist assumes an empty
pkg-plist, whereas check-orphans parses it.
* overhaul the mtree extractor, avoiding awk.
Reviewed by: bapt
Approved by: portmgr (bapt)
2013-10-31 19:07:38 +00:00
|
|
|
interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p;2q' $f)
|
2013-10-09 15:11:32 +00:00
|
|
|
case "$interp" in
|
|
|
|
"") ;;
|
|
|
|
/usr/bin/env) ;;
|
|
|
|
${LOCALBASE}/*) ;;
|
|
|
|
${PREFIX}/*) ;;
|
|
|
|
/usr/bin/awk) ;;
|
|
|
|
/usr/bin/sed) ;;
|
2013-12-06 23:12:52 +00:00
|
|
|
/usr/bin/nawk) ;;
|
|
|
|
/bin/csh) ;;
|
2013-10-09 15:11:32 +00:00
|
|
|
/bin/sh) ;;
|
|
|
|
*)
|
|
|
|
err "${interp} is an invalid shebang you need USES=shebangfix for ${f#${STAGEDIR}${PREFIX}/}"
|
|
|
|
rc=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
symlinks() {
|
|
|
|
rc=0
|
2013-11-23 12:23:19 +00:00
|
|
|
IFS="$LF" ; for l in `find ${STAGEDIR} -type l`; do
|
2013-10-09 15:11:32 +00:00
|
|
|
link=$(readlink ${l})
|
|
|
|
case "${link}" in
|
|
|
|
${STAGEDIR}*) err "Bad symlinks ${l} pointing inside the stage directory"
|
|
|
|
rc=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
paths() {
|
|
|
|
rc=0
|
|
|
|
dirs="${STAGEDIR} ${WRKDIR}"
|
2013-11-23 12:23:19 +00:00
|
|
|
IFS="$LF" ; for f in `find ${STAGEDIR} -type f`;do
|
2013-10-09 15:11:32 +00:00
|
|
|
for d in ${dirs}; do
|
|
|
|
if grep -q ${d} ${f} ; then
|
|
|
|
err "${f} is referring to ${d}"
|
|
|
|
rc=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# For now do not raise an error, just warnings
|
|
|
|
stripped() {
|
bsd.stage.mk: Fewer false positives, much faster, easier maintenance.
Bugfixes:
* @cmd in pkg-plist is now properly handled.
- It was previously treated the same as though there was a directory
following it, missing the prefix. (ordering matters in case...esac)
- Due to the cwd=${PREFIX} inside the while read line loop, state
tracking was broken and every new line assumed that cwd were the
prefix.
* stage-qa no longer complains about unstripped binaries if debugging is
active (WITH_DEBUG set && WITHOUT_DEBUG unset).
* The compress-man target uses ECHO_MSG, not ECHO_CMD, to print its
build step.
Additions:
* The plist parser now understands @unexec rmdir ... || ... lines,
including those with redirections, so that there are no false
positives for directories stripped with @unexec rmdir (usually
happens on stuff installed outside $PREFIX, as in /var).
* The system's root and var mtrees are now also expanded to avoid
false @dirrm positives if a port installs directories under /var
and has to create parents in the stagedir that are present in a fully
installed system (i. e. in the real $PREFIX).
* Given that pkg_create is deemed beyond repair with respect to deleting
files outside prefix, generate @unexec rmdir statements for such
directories, rather than @dirrmtry, to sidestep the problem.
Speedups:
* the orphan check now generates sorted lists of staged files,
and plisted/mtree files, and compares them with comm(1).
This saves us the overhead of running one grep process per file
and up to two per directory, and defers the actual list
processing to a shell utility. Complexity has not changed,
but overhead per item has.
* the orphan check now uses one file for directories and one file for
files mentioned in pkg-plist, so we need not decorate them with "dir "
and parse them out any longer.
* qa.sh's shebang scanner only looks at the first line of a file,
sed is told to exit from the 2nd line.
Other Changes:
* Split the makeplist/check-orphans logic out of bsd.stage.mk,
it is too unwieldy to maintain in make-escaped shell syntax,
and permits shell tracing with "SH=sh -x" (including quotes!)
* Unify the functions "makeplist" and "check-orphans" in one
script. The only difference is that makeplist assumes an empty
pkg-plist, whereas check-orphans parses it.
* overhaul the mtree extractor, avoiding awk.
Reviewed by: bapt
Approved by: portmgr (bapt)
2013-10-31 19:07:38 +00:00
|
|
|
[ -x /usr/bin/file ] || return # this is fatal
|
|
|
|
[ -n "${STRIP}" ] || return 0
|
2013-11-23 12:23:19 +00:00
|
|
|
IFS="$LF" ; for f in `find ${STAGEDIR} -type f`; do
|
2013-10-09 15:11:32 +00:00
|
|
|
output=`/usr/bin/file ${f}`
|
|
|
|
case "${output}" in
|
2013-10-19 00:17:10 +00:00
|
|
|
*:*\ ELF\ *,\ not\ stripped*) warn "${f} is not stripped consider using \${STRIP_CMD}";;
|
2013-10-09 15:11:32 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-10-10 17:09:33 +00:00
|
|
|
desktopfileutils() {
|
|
|
|
if [ -z "${USESDESKTOPFILEUTILS}" ]; then
|
|
|
|
grep -q MimeType= ${STAGEDIR}${PREFIX}/share/applications/*.desktop 2>/dev/null &&
|
|
|
|
warn "you need USES=desktop-file-utils"
|
|
|
|
else
|
|
|
|
grep -q MimeType= ${STAGEDIR}${PREFIX}/share/applications/*.desktop 2>/dev/null ||
|
|
|
|
warn "you may not need USES=desktop-file-utils"
|
|
|
|
fi
|
2013-10-11 02:52:35 +00:00
|
|
|
return 0
|
2013-10-10 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sharedmimeinfo() {
|
|
|
|
if [ -z "${USESSHAREDMIMEINFO}" ]; then
|
|
|
|
find ${STAGEDIR}${PREFIX}/share/mime/packages/*.xml ! -name "freedesktop\.org\.xml" -quit 2>/dev/null &&
|
|
|
|
warn "you need USES=shared-mime-info"
|
|
|
|
else
|
|
|
|
find ${STAGEDIR}${PREFIX}/share/mime/packages/*.xml ! -name "freedesktop\.org\.xml" -quit 2>/dev/null ||
|
|
|
|
warn "you may not need USES=shared-mime-info"
|
|
|
|
fi
|
2013-10-11 02:52:35 +00:00
|
|
|
return 0
|
2013-10-10 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-20 18:12:49 +00:00
|
|
|
suidfiles() {
|
|
|
|
filelist=`find ${STAGEDIR} -type f \
|
|
|
|
\( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
|
|
|
|
\( -perm -u+s -or -perm -g+s \)`
|
|
|
|
if [ -n "${filelist}" ]; then
|
|
|
|
warn "setuid files in the stage directory (are these necessary?):"
|
|
|
|
ls -liTd ${filelist}
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
checks="shebang symlinks paths stripped desktopfileutils sharedmimeinfo suidfiles"
|
2013-10-09 15:11:32 +00:00
|
|
|
|
|
|
|
ret=0
|
|
|
|
cd ${STAGEDIR}
|
|
|
|
for check in ${checks}; do
|
|
|
|
${check} || ret=1
|
|
|
|
done
|
|
|
|
|
|
|
|
exit $ret
|