This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cuttlefish-code-nature/check_filedeps.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
65 lines (61 sloc)
1.33 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: [required_input ...] | |
# --optional [optional_inputs ...] | |
# --required [required_inputs ...] | |
# --output=[output] | |
# [--skip-mtime] | |
# This script will fail if all inputs are older than the output file or if | |
# the output file does not exits. | |
# If --skip-mtime is provided, only the existance of files will be checked. | |
# Parse command line args | |
inputs=() | |
optional_inputs=() | |
optional=false | |
skip_mtime=false | |
for i in "$@" | |
do | |
case $i in | |
--output=*) | |
output="${i#*=}" | |
shift | |
;; | |
--skip-mtime) | |
skip_mtime=true | |
shift | |
;; | |
--optional) | |
optional=true | |
shift | |
;; | |
--required) | |
optional=false | |
shift | |
;; | |
*) | |
if [[ $optional = true ]]; then | |
optional_inputs+=($i) | |
else | |
inputs+=($i) | |
fi | |
shift | |
;; | |
esac | |
done | |
for input in ${inputs[@]}; do | |
if [[ ! -f $input ]]; then | |
exit 1 | |
fi | |
done | |
if [[ ! -f $output ]]; then | |
exit 0 | |
fi | |
if [[ $skip_mtime = true ]]; then | |
exit 0 | |
fi | |
all_inputs=(${inputs[@]} ${optional_inputs[@]}) | |
for input in ${all_inputs[@]}; do | |
if [[ -f $input ]] && [[ $output -ot $input ]]; then | |
exit 0 | |
fi | |
done | |
exit 1 | |