Skip to content

Commit

Permalink
Fix sed on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Jan 3, 2024
1 parent 178d91b commit f0d16dc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Scripts/update-copyright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

set -euo pipefail
SCRIPT_NAME="$(basename $0)"
IS_DARIN=0
if [[ "$(uname -s)" = 'Darwin' ]]; then
IS_DARIN=1
fi

# Arg1: OLD_YEAR
# Arg2: NEW_YEAR
# Arg3: File Path
replace_copyright() {
sed -i '' -e "s|Copyright (c) 2010-${1}, Deusty, LLC|Copyright (c) 2010-${2}, Deusty, LLC|g" "$3"
return $?
local PATTERN="s|Copyright (c) 2010-${1}, Deusty, LLC|Copyright (c) 2010-${2}, Deusty, LLC|g"
if [[ "${IS_DARWIN}" -eq 1 ]]; then
sed -i '' -e "${PATTERN}" "$3"
return $?
else
sed -i -e "${PATTERN}" "$3"
return $?
fi
}

current_year() {
Expand Down Expand Up @@ -60,7 +70,7 @@ export -f replace_copyright

EXTENDED_REGEX_FLAG_POST_PATH='-regextype posix-extended'
EXTENDED_REGEX_FLAG_PRE_PATH=''
if [[ "$(uname -s)" = 'Darwin' ]]; then
if [[ "${IS_DARWIN}" -eq 1 ]]; then
EXTENDED_REGEX_FLAG_PRE_PATH='-E'
EXTENDED_REGEX_FLAG_POST_PATH=''
fi
Expand All @@ -69,7 +79,7 @@ pushd "$(dirname $0)/../" > /dev/null
find ${EXTENDED_REGEX_FLAG_PRE_PATH} \
. \
${EXTENDED_REGEX_FLAG_POST_PATH} \
-regex ".*\.([hm]|swift|pch)" \
-regex '.*\.([hm]|swift|pch)' \
-exec bash -c "replace_copyright \"${OLD_YEAR}\" \"${NEW_YEAR}\" \"{}\"" \;
replace_copyright "${OLD_YEAR}" "${NEW_YEAR}" './LICENSE'
popd > /dev/null
Expand Down

0 comments on commit f0d16dc

Please sign in to comment.