Skip to content

Instantly share code, notes, and snippets.

@mohd-akram
Created October 9, 2023 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohd-akram/92912470caec3c6bc99dea748eab3779 to your computer and use it in GitHub Desktop.
Save mohd-akram/92912470caec3c6bc99dea748eab3779 to your computer and use it in GitHub Desktop.
Utility to bump revision of a list of ports (MacPorts)
#!/bin/sh
set -euo pipefail
root=
while getopts D: opt; do
case $opt in
D) root=$OPTARG ;;
?) exit 2
esac
done
shift $((OPTIND-1))
port info --line --portdir "$@" | sort | uniq | while read dir; do
if [ "$root" ]; then
dir=$root/$dir
fi
f=$dir/Portfile
n=$(awk '/^ *revision *[0-9]+/ {++i} END {print i+0}' "$f")
if [ "$n" -gt 1 ]; then
echo >&2 "skipping $f (more than one revision line)"
continue
fi
if [ "$n" -eq 0 ]; then
echo >&2 "skipping $f (revision not found)"
continue
fi
newrev=$(awk '/^ *revision *[0-9]+/ {print $2+1}' "$f")
ed -s "$f" <<-EOF
/^ *revision/s/[0-9][0-9]*/$newrev/
w
q
EOF
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment