/[gentoo-perl]/perl-cleaner/trunk/bin/perl-cleaner
Gentoo

Diff of /perl-cleaner/trunk/bin/perl-cleaner

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 8 Revision 9
26MODULES_LIST=$(mktemp ${TMPDIR}/modules.list.XXXXXXXXXX) 26MODULES_LIST=$(mktemp ${TMPDIR}/modules.list.XXXXXXXXXX)
27EBUILDS_PREINSTALL=$(mktemp ${TMPDIR}/ebuilds.preinstall.XXXXXXXXXX) 27EBUILDS_PREINSTALL=$(mktemp ${TMPDIR}/ebuilds.preinstall.XXXXXXXXXX)
28EBUILDS_ORDERED=$(mktemp ${TMPDIR}/ebuilds.ordered.XXXXXXXXXX) 28EBUILDS_ORDERED=$(mktemp ${TMPDIR}/ebuilds.ordered.XXXXXXXXXX)
29EBUILDS_REINSTALL=$(mktemp ${TMPDIR}/ebuilds.reinstall.XXXXXXXXXX) 29EBUILDS_REINSTALL=$(mktemp ${TMPDIR}/ebuilds.reinstall.XXXXXXXXXX)
30 30
31ASK=""
32
33if [ ! -z $2 ]; then
34 ASK="--ask"
35fi
36
37
38
39function postclean { 31function postclean {
40 for FILE in ${MODULES_LIST} ${EBUILDS_PREINSTALL} ${EBUILDS_ORDERED} ${EBUILDS_REINSTALL}; do 32 for FILE in ${MODULES_LIST} ${EBUILDS_PREINSTALL} ${EBUILDS_ORDERED} ${EBUILDS_REINSTALL}; do
41 33
42 if [ -f $FILE ]; then 34 if [ -f $FILE ]; then
43 rm -f $FILE 35 rm -f $FILE
44 fi 36 fi
45 37
46 done 38 done
47 39
48 if [ -s $LOG ]; then 40 if [ -s $LOG ]; then
49 echo 41 echo
50 echo "For a complete log, please read $LOG" 42 echo "For a complete log, please read $LOG"
51 echo 43 echo
52 else 44 else
53 if [ -f $LOG ]; then 45 if [ -f $LOG ]; then
54 rm -f $LOG 46 rm -f $LOG
55 fi 47 fi
56 fi 48 fi
57} 49}
58 50
59# This is to clean out the old .ph files generated in our last perl install 51# This is to clean out the old .ph files generated in our last perl install
61 echo "$(date) : Beginning a clean up of .ph files" | tee -a $LOG 53 echo "$(date) : Beginning a clean up of .ph files" | tee -a $LOG
62 54
63 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }') 55 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }')
64 56
65 echo "Locating ph files for removal" 57 echo "Locating ph files for removal"
66 for DIR in $INC; do
67 if [ -d $DIR ]; then
68 for file in $(find $DIR -name "*.ph" -type f); do 58 for file in $(find $INC -name "*.ph" -type f 2>/dev/null); do
69 if [ ! $(echo "$file"|grep $PERL_VERSION) ]; then 59 if [ ! $(echo "$file"|grep $PERL_VERSION) ]; then
70 echo "$(date) : Removing old ph file: $file" | tee -a $LOG 60 echo "$(date) : Removing old ph file: $file" | tee -a $LOG
71 rm $file 61 rm $file
72 fi 62 fi
73 done
74 fi
75 done 63 done
76 for DIR in $INC; do 64
77 for empty in $(find $DIR -type d); do
78 # Silently remove those dirs that we just emptied 65 # Silently remove those dirs that we just emptied
79 find ${ROOT}/$DIR -depth -type d | xargs -r rmdir &> /dev/null 66 find $INC -depth -type d 2>/dev/null | xargs -r rmdir 2>/dev/null
80 done
81 done
82} 67}
83 68
84# Generate ph files; this is useful if we've upgraded packages with headers so that perl knows the new info 69# Generate ph files; this is useful if we've upgraded packages with headers so that perl knows the new info
85function ph_update() { 70function ph_update() {
86 echo "$(date) : Updating ph files" | tee -a $LOG 71 echo "$(date) : Updating ph files" | tee -a $LOG
95# no sense in revisiting that dir 80# no sense in revisiting that dir
96 echo "$(date) : Building list of modules for reinstall" | tee -a $LOG 81 echo "$(date) : Building list of modules for reinstall" | tee -a $LOG
97 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }') 82 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }')
98 MODFIND=$(mktemp ${TMPDIR}/modules.found.XXXXXXXXXX) 83 MODFIND=$(mktemp ${TMPDIR}/modules.found.XXXXXXXXXX)
99 echo "Locating modules for reinstall" 84 echo "Locating modules for reinstall"
100 for DIR in $INC; do
101 if [ -d $DIR ]; then
102 for file in $(find $DIR -iname "*.pm" -type f|grep -v "${PERL_VERSION}"); do 85 for file in $(find $INC -iname "*.pm" -type f 2>/dev/null | grep -v "${PERL_VERSION}"); do
103 echo "$file" >>$MODFIND 86 echo "$file" >>$MODFIND
104 done
105 fi
106 done 87 done
107 grep -f $MODFIND -l $PKGDIR/*/*/CONTENTS >${MODULES_LIST} 88 grep -f $MODFIND -l $PKGDIR/*/*/CONTENTS >${MODULES_LIST}
108 rm $MODFIND 89 rm $MODFIND
90}
91
92function alternate_module_list() {
93 # Takes longer to run, but identifes modules not associated with
94 # an ebuild.
95 #
96 # Reset INC - INC is dynamically generated, and if we removed any ph
97 # files - and they were the only thing left in a dir - then there's
98 # no sense in revisiting that dir
99 echo "$(date) : Building list of modules for reinstall" | tee -a $LOG
100 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }')
101 INSTALLED_EBUILDS=$(find $PKGDIR -name CONTENTS)
102 echo "Locating modules for reinstall"
103 for file in $(find $INC -iname "*.pm" \! -type f 2>/dev/null | grep -v "${PERL_VERSION}"| sort -u); do
104 PKG=$(for ebuild in $INSTALLED_EBUILDS; do if grep -l $file $ebuild; then break; fi; done)
105 if [ -z "$PKG" ] ; then
106 echo "Warning: $file is not owned by a currently installed ebuild"
107 else
108 echo "$PKG" >>${MODULES_LIST}
109 fi
110 done
109} 111}
110 112
111# The meat of it - rebuilding the ebuilds 113# The meat of it - rebuilding the ebuilds
112# ALL emerges are oneshots - we don't want to mess with the world file 114# ALL emerges are oneshots - we don't want to mess with the world file
113# We first attempt to emerge the specific module that was installed last time 115# We first attempt to emerge the specific module that was installed last time
120 for line in $(sort -u ${MODULES_LIST}); do 122 for line in $(sort -u ${MODULES_LIST}); do
121 echo "$line"|sed -e 's|.*pkg/||' -e 's|/CONTENTS||'|grep -v "dev-lang/perl" >>${EBUILDS_PREINSTALL} 123 echo "$line"|sed -e 's|.*pkg/||' -e 's|/CONTENTS||'|grep -v "dev-lang/perl" >>${EBUILDS_PREINSTALL}
122 done 124 done
123 fi 125 fi
124 126
125
126# If they asked for interactive, let them see what will be reinstalled 127 # If they asked for interactive, let them see what will be reinstalled
127 if [ -s ${EBUILDS_PREINSTALL} ]; then 128 if [ -s ${EBUILDS_PREINSTALL} ]; then
128 129
129 if [ ! -z $ASK ]; then 130 if [ ! -z $ASK ]; then
130 echo "Press Enter to see the list of ebuilds we'll be evaluating" 131 echo "Press Enter to see the list of ebuilds we'll be evaluating"
131 read key 132 read key
132 $PAGER ${EBUILDS_PREINSTALL} 133 $PAGER ${EBUILDS_PREINSTALL}
133 printf "Continue? (Y/N) " 134 printf "Continue? (Y/N) "
134 read ANSWER 135 read ANSWER
135 if [ $(echo "${ANSWER}" | egrep -e "^n|N" ) ]; then 136 if [ $(echo "${ANSWER}" | egrep -e "^n|N" ) ]; then
136 echo "$(date) : USER ABORTED REBUILD">>$LOG 137 echo "$(date) : USER ABORTED REBUILD">>$LOG
137 exit 138 exit
138 fi 139 fi
139 fi 140 fi
140 141
141 for EBUILD in $(cat ${EBUILDS_PREINSTALL} ); do 142 for EBUILD in $(cat ${EBUILDS_PREINSTALL} ); do
142 if emerge --oneshot -p "=$EBUILD"|egrep -q ".*ebuilds.*satisfy"; then 143 if emerge --oneshot -p "=$EBUILD"|egrep -q ".*ebuilds.*satisfy"; then
143 if emerge --oneshot -p ">=$EBUILD"|egrep -q ".*ebuilds.*satisfy"; then 144 if emerge --oneshot -p ">=$EBUILD"|egrep -q ".*ebuilds.*satisfy"; then
144 echo "$(date) : There are no unmasked ebuilds to satisfy $EBUILD. Skipping" | tee -a $LOG 145 echo "$(date) : There are no unmasked ebuilds to satisfy $EBUILD. Skipping" | tee -a $LOG
145 sleep 2 146 sleep 2
146 else 147 else
147 if [ ! -z $ASK ]; then 148 if [ ! -z $ASK ]; then
148 printf "${EBUILD} isn't available, but a new version is. Install? (Y/N) " 149 printf "${EBUILD} isn't available, but a new version is. Install? (Y/N) "
149 read ANSWER 150 read ANSWER
150 if [ $(echo "${ANSWER}" | egrep -e "^y|Y" ) ]; then 151 if [ $(echo "${ANSWER}" | egrep -e "^y|Y" ) ]; then
151 echo ">=$EBUILD" >> ${EBUILDS_ORDERED} 152 echo ">=$EBUILD" >> ${EBUILDS_ORDERED}
152 echo "$(date) : User chose to install >=${EBUILD}">>$LOG 153 echo "$(date) : User chose to install >=${EBUILD}">>$LOG
153 fi 154 fi
154 else 155 else
155 echo ">=$EBUILD" >>${EBUILDS_ORDERED} 156 echo ">=$EBUILD" >>${EBUILDS_ORDERED}
156 fi 157 fi
157 fi 158 fi
158 else 159 else
159 echo "=$EBUILD">>${EBUILDS_ORDERED} 160 echo "=$EBUILD">>${EBUILDS_ORDERED}
160 fi 161 fi
161 done 162 done
162 163
163 if [ -s ${EBUILDS_ORDERED} ]; then 164 if [ -s ${EBUILDS_ORDERED} ]; then
164 if [ ! -z $ASK ]; then 165 if [ ! -z $ASK ]; then
165 echo "Press Enter to see the final list of ebuilds to install" 166 echo "Press Enter to see the final list of ebuilds to install"
166 read key 167 read key
167 $PAGER ${EBUILDS_ORDERED} 168 $PAGER ${EBUILDS_ORDERED}
168 printf "Continue? (Y/N) " 169 printf "Continue? (Y/N) "
169 read ANSWER 170 read ANSWER
170 if [ $(echo "${ANSWER}" | egrep -e "^n|N" ) ]; then 171 if [ $(echo "${ANSWER}" | egrep -e "^n|N" ) ]; then
171 echo "$(date) : USER ABORTED REBUILD">>$LOG 172 echo "$(date) : USER ABORTED REBUILD">>$LOG
172 exit 173 exit
174 fi
173 fi 175 fi
174 fi
175 176
176# Cut down to one line so portage can handle ordering these appropriately 177 # Cut down to one line so portage can handle ordering these appropriately
177 emerge -p --oneshot $(cat ${EBUILDS_ORDERED} ) | grep ebuild | sed -e 's:\([^ ]\+\):=\1:g' -e 's:.*\] \([^ ]*\) .*:\1:'>>${EBUILDS_REINSTALL} 178 emerge -p --oneshot $(cat ${EBUILDS_ORDERED} ) | grep ebuild | sed -e 's:\([^ ]\+\):=\1:g' -e 's:.*\] \([^ ]*\) .*:\1:'>>${EBUILDS_REINSTALL}
178 179
179 echo "Reinstalling ebuilds" 180 echo "Reinstalling ebuilds"
180 echo "$(date) : Ebuilds to reinstall: ">>$LOG 181 echo "$(date) : Ebuilds to reinstall: ">>$LOG
181 cat ${EBUILDS_REINSTALL}>>$LOG 182 cat ${EBUILDS_REINSTALL}>>$LOG
182 echo >>$LOG 183 echo >>$LOG
183 184
184# Now that we have them in the right order, emerge them one at a time 185 # Now that we have them in the right order, emerge them one at a time
185# This is to avoid problems if one doesn't emerge correctly 186 # This is to avoid problems if one doesn't emerge correctly
186 187
187 for EBUILD in $(cat ${EBUILDS_REINSTALL}); do 188 for EBUILD in $(cat ${EBUILDS_REINSTALL}); do
188 emerge --oneshot ${ASK} "$EBUILD" 189 emerge --oneshot ${EMERGE_OPTIONS} "$EBUILD"
189 done 190 done
190 else 191 else
191 echo 192 echo
192 echo "Nothing to reinstall!" 193 echo "Nothing to reinstall!"
193 echo 194 echo
194 fi 195 fi
195 else 196 else
196 echo 197 echo
197 echo "Nothing to reinstall!" 198 echo "Nothing to reinstall!"
198 echo 199 echo
199 fi 200 fi
200 201
201} 202}
202 203
203# Locate .so's and binaries linked against libperl.so 204# Locate .so's and binaries linked against libperl.so
204# The coup is in ! -newer libperl.so - cut out anything that was obviously installed 205# The coup is in ! -newer libperl.so - cut out anything that was obviously installed
205# after our last install of libperl, which should cut out the false positives. 206# after our last install of libperl, which should cut out the false positives.
206 207
207function libperl_list() { 208function libperl_list() {
208 echo "$(date) : Locating ebuilds linked against libperl" | tee -a $LOG 209 echo "$(date) : Locating ebuilds linked against libperl" | tee -a $LOG
209 for i in $(find $(egrep -v ^# /etc/ld.so.conf) -type f -name '*.so*' ! -newer /usr/lib/libperl.so 2>/dev/null) \ 210 for i in $(find $(egrep -v "^#" /etc/ld.so.conf) -type f -name '*.so*' ! -newer /usr/lib/libperl.so 2>/dev/null) \
210 $(find $(echo $PATH | sed 's/:/ /g') -type f -perm +0111 ! -newer /usr/lib/libperl.so 2>/dev/null) ; 211 $(find $(echo $PATH | sed 's/:/ /g') -type f -perm +0111 ! -newer /usr/lib/libperl.so 2>/dev/null) ;
211 do 212 do
212 if [ -f ${i} ]; then 213 if [ -f ${i} ]; then
213 ldd ${i} 2>&1 | grep "libperl" - >/dev/null && grep -l " $i " $PKGDIR/*/*/CONTENTS>>${MODULES_LIST}; 214 ldd ${i} 2>&1 | grep "libperl" - >/dev/null && grep -l " $i " $PKGDIR/*/*/CONTENTS>>${MODULES_LIST};
214 fi 215 fi
215 done 216 done
216 217
217} 218}
218 219
219# Assuming a successful module run, look to see whats left over 220# Assuming a successful module run, look to see whats left over
224 echo "$(date) : or edited. This script cannot deal with them." | tee -a $LOG 225 echo "$(date) : or edited. This script cannot deal with them." | tee -a $LOG
225 echo | tee -a $LOG 226 echo | tee -a $LOG
226 227
227 228
228 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }') 229 INC=$(perl -e 'for $line (@INC) { next if $line eq "."; next if $line =~ m/'${PERL_VERSION}'/; print "$line\n" }')
229 for DIR in $INC; do
230 if [ -d $DIR ]; then
231 for file in $(find $DIR -type f |grep -v "${PERL_VERSION}" ) ; do 230 for file in $(find $INC -type f 2>/dev/null |grep -v "${PERL_VERSION}" ) ; do
232 echo "$(date) : ${file}" | tee -a $LOG 231 echo "$(date) : ${file}" | tee -a $LOG
233 done
234 fi
235 done 232 done
236} 233}
237 234
238 235function usage() {
239case "$1" in
240 leftovers)
241 leftovers
242 ;;
243 allmodules)
244 PERL_VERSION="0.0.0"
245 module_list
246 ebuild_rebuild
247 leftovers
248 ;;
249 modules)
250 module_list
251 ebuild_rebuild
252 leftovers
253 ;;
254 libperl)
255 libperl_list
256 ebuild_rebuild
257 ;;
258 ph-clean)
259 ph_clean
260 ;;
261 phupdate)
262 ph_update
263 ;;
264 phall)
265 ph_clean
266 ph_update
267 ;;
268 all)
269 ph_clean
270 ph_update
271 module_list
272 libperl_list
273 ebuild_rebuild
274 leftovers
275 ;;
276 reallyall)
277 PERL_VERSION="0.0.0"
278 ph_clean
279 ph_update
280 module_list
281 libperl_list
282 ebuild_rebuild
283 leftovers
284 ;;
285 *)
286 echo "Usage: $0 [options] [ask]" 236 echo "Usage: $0 [options] [ask]"
287 printf "\tmodules - rebuild perl modules for old installs of perl\n" 237 printf "\tmodules - rebuild perl modules for old installs of perl\n"
288 printf "\tallmodules - rebuild perl modules for any install of perl\n" 238 printf "\tallmodules - rebuild perl modules for any install of perl\n"
289 printf "\tlibperl - rebuild anything linked against libperl\n" 239 printf "\tlibperl - rebuild anything linked against libperl\n"
290 printf "\tph-clean - clean out old ph files from a previous perl\n" 240 printf "\tph-clean - clean out old ph files from a previous perl\n"
293 printf "\tall - rebuild modules, libperl linkages, clean ph files, and rebuild them\n" 243 printf "\tall - rebuild modules, libperl linkages, clean ph files, and rebuild them\n"
294 printf "\treallyall - rebuild modules for any install of perl, libperl linkages, clean ph files, and rebuild them\n" 244 printf "\treallyall - rebuild modules for any install of perl, libperl linkages, clean ph files, and rebuild them\n"
295 printf "\n" 245 printf "\n"
296 printf "\task - ask for confirmation on each emerge" 246 printf "\task - ask for confirmation on each emerge"
297 printf "\n\n" 247 printf "\n\n"
298 248 exit 0
249}
250
251if [ -z "$1" ]; then
252 usage
253fi
254
255EMERGE_OPTIONS=""
256ASK=""
257MODULES=false
258LIBPERL=false
259PHCLEAN=false
260PHUPDATE=false
261FORCE=false
262LEFTOVERS=false
263while [ ! -z "$1" ] ; do
264 case "$1" in
265 help | --help | -h )
266 usage
299 ;; 267 ;;
300esac 268 leftovers )
269 LEFTOVERS=true
270 shift
271 ;;
272 modules )
273 MODULES=true
274# LEFTOVERS=true
275 shift
276 ;;
277 allmodules )
278 MODULES=true
279 FORCE=true
280 shift
281 ;;
282 libperl )
283 LIBPERL=true
284 shift
285 ;;
286 ph-clean )
287 PHCLEAN=true
288 shift
289 ;;
290 phupdate )
291 PHUPDATE=true
292 shift
293 ;;
294 phall )
295 PHCLEAN=true
296 PHUPDATE=true
297 shift
298 ;;
299 all )
300 MODULES=true
301 LIBPERL=true
302 PHCLEAN=true
303 PHUPDATE=true
304 LEFTOVERS=true
305 shift
306 ;;
307 reallyall )
308 MODULES=true
309 LIBPERL=true
310 PHCLEAN=true
311 PHUPDATE=true
312 FORCE=true
313 shift
314 ;;
315 ask )
316 ASK="true"
317 EMERGE_OPTIONS="${EMERGE_OPTIONS} --ask"
318 shift
319 ;;
320 force )
321 FORCE=true
322 shift
323 ;;
324 * )
325 EMERGE_OPTIONS="${EMERGE_OPTIONS} $1"
326 shift
327 ;;
328 esac
329done
301 330
331$FORCE && PERL_VERSION="0.0.0"
332$PHCLEAN && ph_clean
333$PHUPDATE && ph_update
334$MODULES && module_list
335$LIBPERL && libperl_list
336($MODULES || $LIBPERL) && ebuild_rebuild
337$LEFTOVERS && leftovers
338
302postclean 339#postclean
303 340
304exit 341exit

Legend:
Removed from v.8  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.20