Ticket #49009: port-update-state-checksum

File port-update-state-checksum, 890 bytes (added by RJVB (René Bertin), 9 years ago)

Updates the checksum tag stored in the statefile(s) of the given port(s). Prevents that awkward moment you realise you forgot to use port's -o option.

Line 
1#!/bin/sh
2
3PORT=""
4OPTS=""
5
6while [ $# != 0 ] ;do
7        case $1 in
8                -*)
9                        # unused for now
10                        OPTS="${OPTS} $1"
11                        ;;
12                *)
13                        PORT="${PORT} $1"
14                        ;;
15        esac
16        shift
17done
18
19if [ "${PORT}" != "" ] ;then
20        for p in $PORT ;do
21                WD="`port work ${p}`"
22                STATEFILE=${WD}/.macports.${p}.state
23                PFILE="`port dir ${p}`/Portfile"
24                CHKSUM="`openssl sha256 -r ${PFILE} | sed -e 's| \*.*||g'`"
25                if [ -e ${STATEFILE} ] ;then
26                        OCHKSUM="`fgrep 'checksum:' ${STATEFILE} | sed -e 's|checksum: ||g'`"
27                        if [ "${OCHKSUM}" != "${CHKSUM}" ] ;then
28                                echo "Changing ${p}'s checksum from ${OCHKSUM} to ${CHKSUM}"
29                                cp -p ${STATEFILE} ${STATEFILE}.bak
30                                sed -e "s|checksum: .*|checksum: ${CHKSUM}|g" < ${STATEFILE}.bak > ${STATEFILE}
31                                rm -f ${STATEFILE}.bak
32                        fi
33                fi
34        done
35else
36        echo "Usage: `basename $0` <port1> [port2 [port3 [...]]]"
37        echo "This utility updates the checksum in the port's state file"
38fi