openfoam/wmake/scripts/wmake-check-dir
Mark Olesen 9e3d06853e ENH: add 'subcommand' handling to wmake (#1693)
- initial split of wmake-related commands into "plumbing" and
  "porcelain" akin to how git handles things.

- wmakeBuildInfo (very low-level), now relocated to the wmake/scripts
  and accessible for the user as "wmake -build-info".

  This satisfies a long-standing desire to access build information
  in a fashion similar to the api/patch information.

CONFIG: avoid git information when building with a debian/ directory

- when a 'debian/' directory exists, there is a high probability that
  the '.git/' directory is from debian and not from OpenFOAM (ie,
  useless here). This corresponds to an implicit '-no-git', which has
  no effect when building from pristine sources.

ENH: wmakeCheckPwd becomes scripts/wmake-check-dir

- accessible for the user as "wmake -check-dir" and with 1 or 2
  directory names. A wmakeCheckPwd symlink left for compatibility.
2020-05-12 10:05:24 +02:00

135 lines
3.1 KiB
Bash
Executable File

#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# Copyright (C) 2011-2015 OpenFOAM Foundation
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# wmake/scripts/wmake-check-dir
# Backend for "wmake -check-dir"
#
# wmake/wmakeCheckPwd (1912 and earlier)
#
# Usage
# wmake-check-dir <dir>
# wmake-check-dir <dir> <dir2>
#
# Description
# Check that two directories are identical after resolving the absolute
# paths. If only a single directory is specified, check against the
# working directory.
#
# Exit status 0 when directories are identical.
#
#-------------------------------------------------------------------------------
printHelp() {
cat<<USAGE
Usage: ${0##*/} [OPTION] dir [dir2]
options:
-q | -quiet suppress all normal output
-h | -help display short help and exit
Check that two directories are identical after resolving the absolute paths.
If only a single directory is specified, check against the working directory.
Exit status 0 when directories are identical
Exit status 1 on error
USAGE
exit 0 # A clean exit
}
# Report error and exit
unset optQuiet
die()
{
if [ -z "$optQuiet" ]
then
exec 1>&2
echo "${0##*/}: $1"
shift
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
fi
exit 1
}
#------------------------------------------------------------------------------
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
printHelp
;;
-q | -quiet | -s | -silent)
optQuiet=true
;;
--)
shift
break
;;
-*)
die "Unknown option: '$1'" "See '${0##*/} -help' for usage"
;;
*)
break
;;
esac
shift
done
dirName1="${1%/}"
dirName2="${2%/}"
: "${dirName1:=/}"
: "${dirName2:=$PWD}"
[ "$#" -eq 1 ] || \
[ "$#" -eq 2 ] || \
die "Expected 1 or 2 arguments, was given $#"
# Simple lexical check
[ "$dirName1" = "$dirName2" ] && exit 0
# Check existence
[ -d "$dirName1" ] || die "Directory does not exist '$dirName1'"
resolved1="$(cd "$dirName1" 2>/dev/null && pwd -P)"
if [ "$#" -eq 1 ]
then
resolved2="$(pwd -P)"
else
# Check existence
[ -d "$dirName2" ] || die "Directory does not exist '$dirName2'"
resolved2="$(cd "$dirName2" 2>/dev/null && pwd -P)"
fi
# Compare absolute paths, without symlinks
if [ "$resolved1" = "$resolved2" ]
then
exit 0
fi
if [ "$#" -eq 1 ]
then
die "Current directory is not '$dirName1'"
else
die "Directories are different"
fi
#------------------------------------------------------------------------------