cd9c604c96
Currently, we look for the actual date be easrching form the end of the PATH, and keeping the last-found date that occurs after the wrapper. However, in some cases, the wrapper will be the last item in the PATH. This is the cae when users already have the HOST_DIR/bin at the end of their PATH, à-la: PATH="${PATH}:/path/to/buildroot/output/host/bin" In this case, we would not find any matching date. The issue is that Buildroot adds HOST_DIR/bin at the beginning of the PATH, so the real date will be to be found after the HOST_DIR that is early in the PATH, but before the HOST_DIR that is at the end. We fix the issue by searching the PATH as it is expecte to be searched, shoud Buildroot had not added its date wrapper: we use the first date executable that is found in the PATH, starting from the beginning, that is after our wrapper, abd that is not the wrapper itself. Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr> [yann.morin.1998@free.fr: - iterate in order from first-to-last - stop on the first occurence - handle the case where no date was found - extend and expand the commit log ] Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
57 lines
1.8 KiB
Bash
Executable File
57 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# vim: set sw=4 expandtab:
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
# Copyright (C) 2016 Jérôme Pouiller <jezz@sysmic.org>
|
|
#
|
|
|
|
# Do not call any 'date' before us in the PATH, or that would create
|
|
# an infinite recursion.
|
|
found=false
|
|
for date in $(which -a date); do
|
|
if [ "${date}" -ef "$0" ]; then
|
|
found=true
|
|
elif ${found}; then
|
|
DATE_BIN="${date}"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "${DATE_BIN}" ]; then
|
|
printf 'fakedate: no real date found in PATH after "%s"\n' "${0}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ -n "$SOURCE_DATE_EPOCH" ]; then
|
|
FORCE_EPOCH=1
|
|
for i in "$@"; do
|
|
# Use of --date, --file and --reference (and their short option counter
|
|
# parts) is incompatible with SOURCE_DATE_EPOCH.
|
|
# -u and -R are the only short options without argument. So they could
|
|
# appear between '-' and option we want to match.
|
|
if echo "$i" | grep -qE '^-([uR]*d|-date|[uR]*f|-file|[uR]*r|--reference)'; then
|
|
FORCE_EPOCH=0
|
|
break;
|
|
fi
|
|
done
|
|
if [ $FORCE_EPOCH -eq 1 ]; then
|
|
echo "date: Warning: using \$SOURCE_DATE_EPOCH instead of true time" >&2
|
|
ARGS="-d @$SOURCE_DATE_EPOCH"
|
|
fi
|
|
fi
|
|
|
|
exec $DATE_BIN $ARGS "$@"
|