e7548edb5f
Using -ef to check for the same file is nicer than relying on a magic symlink-to-fakedate. Notice that -ef isn't stricly posix (but supported by bash/dash/zsh), so I've changed the shebang to /bin/bash. While we are at it, restructure the logic to do a single exec at the end instead of handling the epoch/!epoch cases differently for simplicity. With that out of the way we can directly install it as $HOST/usr/bin/date instead of the fakedate / date symlink. [Peter: drop IFS=: change] Signed-off-by: Peter Korsgaard <peter@korsgaard.com> Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
52 lines
1.8 KiB
Bash
Executable File
52 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>
|
|
#
|
|
|
|
DATE_BIN=false
|
|
# Do not call `date' directly since it will produce an infinite recursion.
|
|
# Instead, find path of true `date' binary.
|
|
for P in `echo $PATH | tr ':' ' '`; do
|
|
if [ -x "$P/date" ]; then
|
|
if ! [ "$P/date" -ef "$0" ]; then
|
|
DATE_BIN="$P/date"
|
|
break;
|
|
fi
|
|
fi
|
|
done
|
|
|
|
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 "$@"
|