1 | #!/macports/bin/bash |
---|
2 | |
---|
3 | # |
---|
4 | # ${1} :: type of conversion (hard|soft) (default:soft) |
---|
5 | # ${2} :: old version of Perl5 (default: 12) |
---|
6 | # ${3} :: new version of Perl5 (default: 16) |
---|
7 | # |
---|
8 | |
---|
9 | declare type=${1:-soft} |
---|
10 | declare -i versionOld=${2:-12} |
---|
11 | declare -v versionNew=${3:-16} |
---|
12 | |
---|
13 | declare -i counter=0 |
---|
14 | declare -i totalPorts=$( port -q list | wc -l ) |
---|
15 | declare -i portrev |
---|
16 | |
---|
17 | # |
---|
18 | # this time we're only interested in perl5.12 |
---|
19 | # |
---|
20 | declare -i version=12 |
---|
21 | |
---|
22 | # |
---|
23 | # find all the ports that are dependent on perl5.${version} |
---|
24 | # or p5.${version}-<something> |
---|
25 | # |
---|
26 | while read portname[0] portname[1] portname[2] |
---|
27 | do |
---|
28 | (( counter++ )) |
---|
29 | printf "\r[ %5i | %5i ] %-50s" ${counter} ${totalPorts} ${portname[2]} |
---|
30 | fundet=$( \ |
---|
31 | grep -E -e "(perl5.${version}|p5.${version})" $(port file ${portname[0]}) \ |
---|
32 | | wc -l ) |
---|
33 | if [ ${fundet} -gt 0 ] |
---|
34 | then |
---|
35 | cd $(dirname $(port file ${portname[0]})) |
---|
36 | echo '' |
---|
37 | |
---|
38 | # |
---|
39 | # splice the PortGroup command into the Portfile |
---|
40 | # |
---|
41 | portrev=$( grep -i "PortGroup.*perl5" 'Portfile' | wc -l ) |
---|
42 | if [ ${portrev} -eq 0 ] |
---|
43 | then |
---|
44 | mv 'Portfile' 'Portfile.orig' |
---|
45 | sed -En -e "1,/^PortSystem/p" 'Portfile.orig' \ |
---|
46 | > 'Portfile' |
---|
47 | echo -e "PortGroup perl5 1.0" \ |
---|
48 | >> 'Portfile' |
---|
49 | sed -E -e "1,/^PortSystem/d" 'Portfile.orig' \ |
---|
50 | >> 'Portfile' |
---|
51 | rm 'Portfile.orig' |
---|
52 | fi |
---|
53 | |
---|
54 | # |
---|
55 | # replace the hardcoded values |
---|
56 | # |
---|
57 | case ${type} in |
---|
58 | ( 'soft' ) |
---|
59 | sed -i '' -E \ |
---|
60 | -e "/^\#/!s/perl5.${versionOld}/perl\$\{perl5.major\}/g" \ |
---|
61 | -e "/^\#/!s/p5.${versionOld}/p\$\{perl5.major\}/g" \ |
---|
62 | 'Portfile' |
---|
63 | ;; |
---|
64 | ( 'hard' ) |
---|
65 | ;; |
---|
66 | sed -i '' -E \ |
---|
67 | -e "/^\#/!s/perl5.${versionOld}/perl5.${versionNew}/g" \ |
---|
68 | -e "/^\#/!s/p5.${versionOld}/p/5.${versionNew}g" \ |
---|
69 | 'Portfile' |
---|
70 | esac |
---|
71 | fi |
---|
72 | done < <( port list ) |
---|
73 | printf "\r[ %5i | %5i ] %-50s\n" ${counter} ${totalPorts} '*** FINISHED ***' |
---|