phpsg.sh: use realpath to simplify paths.

This commit is contained in:
Nicolás A. Ortega Froysa 2025-03-04 10:00:14 +01:00
parent a32d24a086
commit 67c83bf85a

View File

@ -38,10 +38,10 @@ while getopts "o:s:j:Sh" opt
do do
case "$opt" in case "$opt" in
o) o)
OUTPUT_DIR="$(echo "${OPTARG}" | sed 's:/*$::')" OUTPUT_DIR="$(realpath --relative-base=./ "${OPTARG}")"
;; ;;
s) s)
SOURCE_DIR="$(echo "${OPTARG}" | sed 's:/*$::')" SOURCE_DIR="$(realpath --relative-base=./ "${OPTARG}")"
;; ;;
j) j)
JOBS="${OPTARG}" JOBS="${OPTARG}"
@ -78,11 +78,11 @@ export SOURCE_DIR
function process_file() { function process_file() {
local file="$1" local file="$1"
local DEST_FILE local DEST_FILE="${OUTPUT_DIR}/${file/#${SOURCE_DIR}\//}"
local DEST_DIR local DEST_DIR
if [[ $file = *.php ]] if [[ $file = *.php ]]
then then
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1)):-4}" DEST_FILE="${DEST_FILE::-4}"
DEST_DIR="$(dirname "$DEST_FILE")" DEST_DIR="$(dirname "$DEST_FILE")"
if ! [ "$file" -nt "$DEST_FILE" ] if ! [ "$file" -nt "$DEST_FILE" ]
then then
@ -96,7 +96,6 @@ function process_file() {
php "$file" > "$DEST_FILE" php "$file" > "$DEST_FILE"
echo "done" echo "done"
else else
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1))}"
DEST_DIR="$(dirname "$DEST_FILE")" DEST_DIR="$(dirname "$DEST_FILE")"
if ! [ "$file" -nt "$DEST_FILE" ] if ! [ "$file" -nt "$DEST_FILE" ]
then then