| 1 | #!/bin/bash |
1 | #!/bin/sh |
| 2 | |
2 | |
| 3 | # Version 1.4 |
3 | # Version 1.4 |
| 4 | #- patches from Wade Fitzpatrick for equery and fgrep suggestions (bug 125674), |
4 | #- patches from Wade Fitzpatrick for equery and fgrep suggestions (bug 125674), |
| 5 | #- patches from Joerge Plate for grep being called with too many arguments (bug 114155) |
5 | #- patches from Joerge Plate for grep being called with too many arguments (bug 114155) |
| 6 | #- finally updated emerge syntax, brought up by nyhm (with some input from cab) in bug 128130. |
6 | #- finally updated emerge syntax, brought up by nyhm (with some input from cab) in bug 128130. |
| … | |
… | |
| 11 | # version 1.1 - Mr. Bones gave a lot of good input on cleaning up the script |
11 | # version 1.1 - Mr. Bones gave a lot of good input on cleaning up the script |
| 12 | # Version 1 - stuff |
12 | # Version 1 - stuff |
| 13 | |
13 | |
| 14 | # First and foremost - make sure we have a perl to work with... |
14 | # First and foremost - make sure we have a perl to work with... |
| 15 | PERL=$(which perl) |
15 | PERL=$(which perl) |
| 16 | if [ "${PERL}x" == "x" ]; then |
16 | if [ "${PERL}x" = "x" ]; then |
| 17 | echo "NO PERL INSTALLED!! (at least not in your path)" |
17 | echo "NO PERL INSTALLED!! (at least not in your path)" |
| 18 | exit |
18 | exit |
| 19 | fi |
19 | fi |
| 20 | eval $(perl '-V:version') |
20 | eval $(perl '-V:version') |
| 21 | PERL_VERSION=${version} |
21 | PERL_VERSION=${version} |
| 22 | gPERL_VERSION=`echo $PERL_VERSION|sed -e 's|\.|\\\.|g'` |
22 | gPERL_VERSION=`echo $PERL_VERSION|sed -e 's|\.|\\\.|g'` |
| 23 | source /sbin/functions.sh || { |
23 | . /etc/init.d/functions.sh || { |
| 24 | echo "$0: Could not source /sbin/functions.sh!" |
24 | echo "$0: Could not source /init.d/functions.sh!" |
| 25 | exit 1 |
25 | exit 1 |
| 26 | } |
26 | } |
| 27 | |
27 | |
| 28 | TMPDIR=${TMPDIR:-/tmp} |
28 | TMPDIR=${TMPDIR:-/tmp} |
| 29 | |
29 | |
| … | |
… | |
| 36 | MODULES_LIST=$(mktemp ${TMPDIR}/modules.list.XXXXXXXXXX) |
36 | MODULES_LIST=$(mktemp ${TMPDIR}/modules.list.XXXXXXXXXX) |
| 37 | EBUILDS_PREINSTALL=$(mktemp ${TMPDIR}/ebuilds.preinstall.XXXXXXXXXX) |
37 | EBUILDS_PREINSTALL=$(mktemp ${TMPDIR}/ebuilds.preinstall.XXXXXXXXXX) |
| 38 | EBUILDS_ORDERED=$(mktemp ${TMPDIR}/ebuilds.ordered.XXXXXXXXXX) |
38 | EBUILDS_ORDERED=$(mktemp ${TMPDIR}/ebuilds.ordered.XXXXXXXXXX) |
| 39 | EBUILDS_REINSTALL=$(mktemp ${TMPDIR}/ebuilds.reinstall.XXXXXXXXXX) |
39 | EBUILDS_REINSTALL=$(mktemp ${TMPDIR}/ebuilds.reinstall.XXXXXXXXXX) |
| 40 | |
40 | |
| 41 | function postclean { |
41 | postclean() { |
| 42 | for FILE in ${MODULES_LIST} ${EBUILDS_PREINSTALL} ${EBUILDS_ORDERED} ${EBUILDS_REINSTALL}; do |
42 | for FILE in ${MODULES_LIST} ${EBUILDS_PREINSTALL} ${EBUILDS_ORDERED} ${EBUILDS_REINSTALL}; do |
| 43 | |
43 | |
| 44 | if [ -f $FILE ]; then |
44 | if [ -f $FILE ]; then |
| 45 | rm -f $FILE |
45 | rm -f $FILE |
| 46 | fi |
46 | fi |
| … | |
… | |
| 57 | fi |
57 | fi |
| 58 | fi |
58 | fi |
| 59 | } |
59 | } |
| 60 | |
60 | |
| 61 | # This is to clean out the old .ph files generated in our last perl install |
61 | # This is to clean out the old .ph files generated in our last perl install |
| 62 | function ph_clean() { |
62 | ph_clean() { |
| 63 | echo "" |
63 | echo "" |
| 64 | echo "$(date) : Beginning a clean up of .ph files" | tee -a $LOG |
64 | echo "$(date) : Beginning a clean up of .ph files" | tee -a $LOG |
| 65 | echo "Excluding perl-${PERL_VERSION} from cleaning" | tee -a $LOG |
65 | echo "Excluding perl-${PERL_VERSION} from cleaning" | tee -a $LOG |
| 66 | |
66 | |
| 67 | local PV=${version} |
67 | local PV=${version} |
| … | |
… | |
| 82 | # Silently remove those dirs that we just emptied |
82 | # Silently remove those dirs that we just emptied |
| 83 | find $INC -depth -type d 2>/dev/null | grep -v $gPV | xargs -r rmdir 2>/dev/null |
83 | find $INC -depth -type d 2>/dev/null | grep -v $gPV | xargs -r rmdir 2>/dev/null |
| 84 | } |
84 | } |
| 85 | |
85 | |
| 86 | # Generate ph files; this is useful if we've upgraded packages with headers so that perl knows the new info |
86 | # Generate ph files; this is useful if we've upgraded packages with headers so that perl knows the new info |
| 87 | function ph_update() { |
87 | ph_update() { |
| 88 | echo "" |
88 | echo "" |
| 89 | echo "$(date) : Updating ph files" | tee -a $LOG |
89 | echo "$(date) : Updating ph files" | tee -a $LOG |
| 90 | cd /usr/include; h2ph * | tee -a $LOG |
90 | cd /usr/include; h2ph * | tee -a $LOG |
| 91 | cd /usr/include; h2ph -r sys/* arpa/* netinet/* bits/* security/* asm/* gnu/* linux/* gentoo* | tee -a $LOG |
91 | cd /usr/include; h2ph -r sys/* arpa/* netinet/* bits/* security/* asm/* gnu/* linux/* gentoo* | tee -a $LOG |
| 92 | cd /usr/include/linux; h2ph * | tee -a $LOG |
92 | cd /usr/include/linux; h2ph * | tee -a $LOG |
| 93 | } |
93 | } |
| 94 | |
94 | |
| 95 | |
95 | |
| 96 | # Build a list of modules installed under older perls - only valid if the module was an ebuild :) |
96 | # Build a list of modules installed under older perls - only valid if the module was an ebuild :) |
| 97 | function module_list() { |
97 | module_list() { |
| 98 | echo "" |
98 | echo "" |
| 99 | echo "$(date) : Building list of modules for reinstall" | tee -a $LOG |
99 | echo "$(date) : Building list of modules for reinstall" | tee -a $LOG |
| 100 | echo "Locating modules for reinstall" |
100 | echo "Locating modules for reinstall" |
| 101 | for checkfile in `find $PKGDIR -maxdepth 3 -mindepth 3 -name "CONTENTS" |xargs grep -El '/usr/lib*/perl5/' `; do |
101 | for checkfile in `find $PKGDIR -maxdepth 3 -mindepth 3 -name "CONTENTS" |xargs grep -El '/usr/lib*/perl5/' `; do |
| 102 | if [ "`grep -l "${gPERL_VERSION}" $checkfile`x" = "x" ]; then |
102 | if [ "`grep -l "${gPERL_VERSION}" $checkfile`x" = "x" ]; then |
| 103 | echo "$checkfile" >> ${MODULES_LIST} |
103 | echo "$checkfile" >> ${MODULES_LIST} |
| 104 | fi; |
104 | fi; |
| 105 | done |
105 | done |
| 106 | } |
106 | } |
| 107 | |
107 | |
| 108 | function alternate_module_list() { |
108 | alternate_module_list() { |
| 109 | # Takes longer to run, but identifes modules not associated with |
109 | # Takes longer to run, but identifes modules not associated with |
| 110 | # an ebuild. |
110 | # an ebuild. |
| 111 | # |
111 | # |
| 112 | # Reset INC - INC is dynamically generated, and if we removed any ph |
112 | # Reset INC - INC is dynamically generated, and if we removed any ph |
| 113 | # files - and they were the only thing left in a dir - then there's |
113 | # files - and they were the only thing left in a dir - then there's |
| … | |
… | |
| 131 | # The meat of it - rebuilding the ebuilds |
131 | # The meat of it - rebuilding the ebuilds |
| 132 | # ALL emerges are oneshots - we don't want to mess with the world file |
132 | # ALL emerges are oneshots - we don't want to mess with the world file |
| 133 | # We first attempt to emerge the specific module that was installed last time |
133 | # We first attempt to emerge the specific module that was installed last time |
| 134 | # If that fails, we attempt to install a newer version |
134 | # If that fails, we attempt to install a newer version |
| 135 | |
135 | |
| 136 | function ebuild_rebuild() { |
136 | ebuild_rebuild() { |
| 137 | |
137 | |
| 138 | echo "" |
138 | echo "" |
| 139 | echo "$(date) : Rebuilding modules: Building list of ebuilds" | tee -a $LOG |
139 | echo "$(date) : Rebuilding modules: Building list of ebuilds" | tee -a $LOG |
| 140 | if [ -s ${MODULES_LIST} ]; then |
140 | if [ -s ${MODULES_LIST} ]; then |
| 141 | for line in $(sort -u ${MODULES_LIST}); do |
141 | for line in $(sort -u ${MODULES_LIST}); do |
| … | |
… | |
| 224 | exit |
224 | exit |
| 225 | fi |
225 | fi |
| 226 | fi |
226 | fi |
| 227 | |
227 | |
| 228 | # Cut down to one line so portage can handle ordering these appropriately |
228 | # Cut down to one line so portage can handle ordering these appropriately |
| 229 | emerge -pq --oneshot $(cat ${EBUILDS_ORDERED} ) | fgrep ebuild | sed -e 's:\([^ ]\+\):=\1:g' -e 's:.*\] \([^ ]*\) .*:\1:'>>${EBUILDS_REINSTALL} |
229 | emerge -pq --oneshot $(cat ${EBUILDS_ORDERED}) | sed -n -e 's/^\[ebuild .*\] \([^ ]*\).*/=\1/p' >>${EBUILDS_REINSTALL} |
| 230 | |
230 | |
| 231 | echo "" |
231 | echo "" |
| 232 | echo "Reinstalling ebuilds" |
232 | echo "Reinstalling ebuilds" |
| 233 | echo "$(date) : Ebuilds to reinstall: ">>$LOG |
233 | echo "$(date) : Ebuilds to reinstall: ">>$LOG |
| 234 | cat ${EBUILDS_REINSTALL}>>$LOG |
234 | cat ${EBUILDS_REINSTALL}>>$LOG |
| … | |
… | |
| 255 | |
255 | |
| 256 | # Locate .so's and binaries linked against libperl.so |
256 | # Locate .so's and binaries linked against libperl.so |
| 257 | # The coup is in ! -newer libperl.so - cut out anything that was obviously installed |
257 | # The coup is in ! -newer libperl.so - cut out anything that was obviously installed |
| 258 | # after our last install of libperl, which should cut out the false positives. |
258 | # after our last install of libperl, which should cut out the false positives. |
| 259 | |
259 | |
| 260 | function libperl_list() { |
260 | libperl_list() { |
| 261 | echo "" |
261 | echo "" |
| 262 | echo "$(date) : Locating ebuilds linked against libperl" | tee -a $LOG |
262 | echo "$(date) : Locating ebuilds linked against libperl" | tee -a $LOG |
| 263 | for i in $(find $(egrep -v "^#" /etc/ld.so.conf) -type f -name '*.so*' ! -newer /usr/lib/libperl.so 2>/dev/null) \ |
263 | for i in $(find $(egrep -v "^#" /etc/ld.so.conf) -type f -name '*.so*' ! -newer /usr/lib/libperl.so 2>/dev/null) \ |
| 264 | $(find $(echo $PATH | sed 's/:/ /g') -type f -perm +0111 ! -newer /usr/lib/libperl.so 2>/dev/null) ; |
264 | $(find $(echo $PATH | sed 's/:/ /g') -type f -perm +0111 ! -newer /usr/lib/libperl.so 2>/dev/null) ; |
| 265 | do |
265 | do |
| … | |
… | |
| 273 | done |
273 | done |
| 274 | |
274 | |
| 275 | } |
275 | } |
| 276 | |
276 | |
| 277 | # Assuming a successful module run, look to see whats left over |
277 | # Assuming a successful module run, look to see whats left over |
| 278 | function leftovers() { |
278 | leftovers() { |
| 279 | echo "" |
279 | echo "" |
| 280 | echo "$(date) : Finding left over modules" | tee -a $LOG |
280 | echo "$(date) : Finding left over modules" | tee -a $LOG |
| 281 | |
281 | |
| 282 | echo "" |
282 | echo "" |
| 283 | echo "$(date) : The following files remain. These were either installed by hand" | tee -a $LOG |
283 | echo "$(date) : The following files remain. These were either installed by hand" | tee -a $LOG |
| … | |
… | |
| 289 | for file in $(find $INC -type f 2>/dev/null |fgrep -v "${gPERL_VERSION}" ) ; do |
289 | for file in $(find $INC -type f 2>/dev/null |fgrep -v "${gPERL_VERSION}" ) ; do |
| 290 | echo "$(date) : ${file}" | tee -a $LOG |
290 | echo "$(date) : ${file}" | tee -a $LOG |
| 291 | done |
291 | done |
| 292 | } |
292 | } |
| 293 | |
293 | |
| 294 | function usage() { |
294 | usage() { |
| 295 | echo "Usage: $0 [options] [ask]" |
295 | echo "Usage: $0 [options] [ask]" |
| 296 | printf "\tmodules - rebuild perl modules for old installs of perl\n" |
296 | printf "\tmodules - rebuild perl modules for old installs of perl\n" |
| 297 | printf "\tallmodules - rebuild perl modules for any install of perl\n" |
297 | printf "\tallmodules - rebuild perl modules for any install of perl\n" |
| 298 | printf "\tlibperl - rebuild anything linked against libperl\n" |
298 | printf "\tlibperl - rebuild anything linked against libperl\n" |
| 299 | printf "\tph-clean - clean out old ph files from a previous perl\n" |
299 | printf "\tph-clean - clean out old ph files from a previous perl\n" |