Skip to content

Commit

Permalink
Improve scripts/update_apt_package_in_package_list.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tkilias committed Dec 8, 2023
1 parent 4719e70 commit 6e45ef7
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions scripts/update_apt_package_in_package_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ PACKAGE=$(echo "$LIST_NEWEST_VERSION_OUTPUT" | cut -f 1 -d "|")
CANDIDATE_VERSION=$(echo "$LIST_NEWEST_VERSION_OUTPUT" | cut -f 3 -d "|")
CURRENT_VERSION=$(echo "$LIST_NEWEST_VERSION_OUTPUT" | cut -f 2 -d "|")

if [[ "$REPLACE" == "yes" ]]
then
SED_REPLACE_OPTION=("-i")
else
SED_REPLACE_OPTION=()
fi
grep -E -R "^$PACKAGE\|$CURRENT_VERSION" "$SEARCH_DIRECTORY" \
| cut -f 1 -d ":" \
| xargs -I{} sed "${SED_REPLACE_OPTION[@]}" -E "s/^($PACKAGE\|$CURRENT_VERSION).*$/$PACKAGE|$CANDIDATE_VERSION/g" "{}" \
| grep -E "^$PACKAGE\|"
FILES=$(grep -E -R "^$PACKAGE\|$CURRENT_VERSION" "$SEARCH_DIRECTORY" | cut -f 1 -d ":")
for FILE in $FILES
do
echo "Found package $PACKAGE|$CURRENT_VERSION in $FILE"
echo "Original lines:"
grep -E "^$PACKAGE\|$CURRENT_VERSION" "$FILE"
echo "Updated lines:"
SEARCH_REPLACE_PATTERN="s/^($PACKAGE\|$CURRENT_VERSION).*$/$PACKAGE|$CANDIDATE_VERSION/g"
sed -E "$SEARCH_REPLACE_PATTERN" "$FILE" | grep -E "^$PACKAGE\|"
if [[ "$REPLACE" == "yes" ]]
then
echo "Updating file $FILE:"
sed -i -E "$SEARCH_REPLACE_PATTERN" "$FILE"
fi
echo
done

0 comments on commit 6e45ef7

Please sign in to comment.