Commit 44aa330a authored by Zachary Seguin's avatar Zachary Seguin

Add update script

parent a1a7394f
#!/bin/bash
has_update () {
port=$1
portname=$(basename -- $1)
if [ $(grep 'replaced_by' "$port/Portfile" | wc -l) -gt 0 ]; then
echo "Skipping $portname as it has been replaced"
return 1
fi
echo "Checking $portname for update..."
res=$(port livecheck $port | wc -l)
if [ "$res" -eq 0 ]; then
return 1
else
return 0
fi
}
log () {
echo ' .. ' ${*}
}
update () {
port=$1
portname=$(basename -- $1)
log "Upgrading $portname..."
# Get the new version number
raw_version=$(port livecheck $port)
port_version=$(echo $raw_version | sed -E 's/.*port version: ([^,]+),.*/\1/')
new_version=$(echo $raw_version | sed -E 's/.*new version: ([^\)]+).*/\1/')
log Current: $port_version
log New: $new_version
# Replace the version number in the Portfile
sed -E -i '' "s/(version.*)$port_version/\1$new_version/" "$port/Portfile"
# Update the port index
portindex
# Upgrade the port (use `upgrade outdated` since some get dynamic versions (like py37-*))
upgrade=$(port upgrade outdated 2>&1)
# Checksums probably failed - get the new ones
if [ $? -ne 0 ]; then
# Update the checksums
log=$(echo $upgrade | sed -E 's#.*See (/opt/local/var/[^ ]+) for details.*#\1#g')
new_checksums=$(tail $log | grep ':info:checksum' | sed 's/:info:checksum //g' | grep -A 2 '^checksums' | sed 's/\\/\\\\/g')
if [[ "$new_checksums" != "" ]]; then
perl -0777p -e 's/^checksums.*\n.*\n.*/'"$new_checksums"'/m' -i'' "$port/Portfile"
fi
# Do the upgrade
port upgrade outdated
fi
log "Done $portname"
}
for port in */*; do
if has_update $port; then
echo " .. updating"
update $port
else
echo " .. up to date"
fi
done
# Re-index
portindex
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment