Ticket #34617: perl5.bash

File perl5.bash, 2.8 KB (added by BjarneDMat, 7 years ago)

my original scipt that works in a separate file structure

Line 
1#!/macports/bin/bash
2
3#
4# change these to reflect your installation:
5#
6# prefix       : where you have installed macports
7# macportsRoot : where you want to store the modifed Portfiles
8#
9#   ${1} :: type of conversion (hard|soft) (default:soft)
10#   ${2} :: old version of Perl5 (default: 12)
11#   ${3} :: new version of Perl5 (default: 16)
12#
13
14declare prefix='/macports'
15declare macportsRoot='/Volumes/Bjarne/WebServer/MacPorts/portfiles'
16
17declare type=${1:-soft}
18declare -i versionOld=${2:-12}
19declare -v versionNew=${3:-16}
20
21# don't change this
22declare rsyncMacportsOrg='/var/macports/sources/rsync.macports.org/release/tarballs/ports'
23
24mkdir -pv ${macportsRoot}
25declare -i counter=0
26declare -i totalPorts=$( port -q list | wc -l )
27declare -i portrev
28
29#
30# this time we're only interested in perl5.12
31#
32
33cd "${macportsRoot}"
34
35#
36# find all the ports that are dependent on perl5.${version}
37# or p5.${version}-<something>
38#
39while read portname[0] portname[1] portname[2]
40do
41    (( counter++ ))
42    printf "\r[ %5i | %5i ] %-50s" ${counter} ${totalPorts} ${portname[2]}
43    fundet=$( \
44        grep -E -e "(perl5.${version}|p5.${version})" $(port file ${portname[0]}) \
45    |   wc -l )
46    if [ ${fundet} -gt 0 ]
47    then
48        #
49        # copy the Portfile
50        #
51        echo ''
52        mkdir -p ${portname[2]}
53        cd  ${portname[2]}
54        cp  $(port file ${portname[0]}) 'Portfile.orig'
55
56        #
57        # splice the PortGroup command into the Portfile
58        #
59        portrev=$( grep -i "PortGroup.*perl5" 'Portfile.orig' | wc -l )
60        if [ ${portrev} -eq 0 ]
61        then
62            sed -En -e "1,/^PortSystem/p" 'Portfile.orig' \
63                >  'Portfile'
64            echo -e "PortGroup        perl5  1.0" \
65                >> 'Portfile'
66            sed -E  -e "1,/^PortSystem/d" 'Portfile.orig' \
67                >> 'Portfile'
68        else
69            cp 'Portfile.orig' 'Portfile'
70        fi
71
72        #
73        # replace the hardcoded values
74        #
75        case ${type} in
76        ( 'soft' )
77            sed -i '' -E \
78                -e "/^\#/!s/perl5.${versionOld}/perl\$\{perl5.major\}/g" \
79                -e "/^\#/!s/p5.${versionOld}/p\$\{perl5.major\}/g" \
80                'Portfile'
81        ;;
82        ( 'hard' )
83        ;;
84            sed -i '' -E \
85                -e "/^\#/!s/perl5.${versionOld}/perl5.${versionNew}/g" \
86                -e "/^\#/!s/p5.${versionOld}/p/5.${versionNew}g" \
87                'Portfile'
88        esac
89
90        #
91        # create *.diff files for all the copied Portfiles
92        #
93        rm 'patch-Portfile.diff' 2>/dev/null
94        diff -u \
95            $( port file ${portname[0]} ) \
96            'Portfile' \
97        > 'patch-Portfile.diff'
98
99        cd ${OLDPWD}
100    fi
101done < <( port list )
102printf "\r[ %5i | %5i ] %-50s\n" ${counter} ${totalPorts} '*** FINISHED ***'