Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, you have asked for it. Here is the script I update my gentoo box with for some months now. It is a smarter replacement of the bash alias in the first comment. I procrastinate finishing it since as it just does what I need though. No guarantees if you dare to try it!
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; # alias update='emerge sync; emerge -fuND world >&/dev/null & emerge - +puND world | genlop --pretend; emerge -autND world && etc-update && / +home/jonix/yacleaner-0.3 -a -v all' ########### Initialisiere CLI-Optionen Getopt::Long::Configure ("bundling"); my $help = ''; my $config = ''; my $verbose = ''; my $configdir = glob('~/.update/'); my $configfile = $configdir . 'update.conf'; my $syncfile = $configdir . 'lastsync'; if (!(opendir my $dir, $configdir)){ mkdir $configdir or die "Error: Can not create directory: $!\n"; print "creating new directory $configdir\n"; } else { print "using existing directory $configdir\n"; closedir $dir; } open my $conf, "< $configfile" or die "Error: Can not open $configfile +: $!\n"; print "$configfile opened successfully\n"; # read config open my $snctime, "< $syncfile" or die "Error: Can not open: $syncfile +: $!\n"; print "checking $syncfile for last sync...\n"; my $lastsync; while (<$snctime>){ $lastsync = int($_); } close $snctime; my $ntime = time; my $dtime = $ntime - $lastsync; # 0 1 2 3 4 5 6 7 my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($dtime); my $years = $year-70; my $delta; if ($years > 1){ $delta .= ", $years years" } elsif ($years > 0) { $delta .= ", $years year" } if ($mon > 1){ $delta .= ", $mon months" }elsif ($mon > 0){ $delta .= ", $mon month" } if ($yday > 1){ $delta .= ", $yday days" } elsif ($yday > 0){ $delta .= ", $yday day" } if ($hour > 1){ $delta .= ", $hour hours" }elsif ($hour > 0){ $delta .= ", $hour hour" } if ($min > 1){ $delta .= ", $min minutes and" }elsif ($min > 0){ $delta .= ", $min minute and" } $delta .= " $sec seconds"; #getting rid of first comma and whitespace $delta = substr($delta,1) if ($years+$mon+$yday+$hour+$min > 0); $delta = substr($delta,1); print "last sync:\n" . gmtime($lastsync) . "\n"; print "now:\n" . gmtime($ntime) . "\n"; my $cmd = 'emerge sync && gensync -a'; #my $cmd = 'emerge info'; my $wantsync = 0; my $synclimit = 86400; # 86400 sec = 1 day if ($dtime < $synclimit){ print "portage tree updated just $delta ago (according to Mr. Data +), sync anyway?\n"; vec (my $readin="", fileno(STDIN),1) = 1; # following line gives user a chance to type! $|=1; print "5 seconds to type [yes]\n"; sleep 5; # see if there's any data waiting so far - waits for a whole line my $nfound = select ((my $r=$readin),undef,undef,0); unless (!($nfound)) { my $fromkb = <STDIN>; # case-insensitive check for y or yes if ($fromkb =~ m/^y(es|)$/oi){ $wantsync = 1; print "OK, starting sync...\n"; } elsif ($fromkb){ chomp $fromkb; print "'$fromkb' not understood!\n"; } } } else { $wantsync = 1; } #if ($wantsync){ # print "\$wantsync = $wantsync\n"; #} #exit; if ($wantsync){ print "last sync was $delta ago, time to update the portage tree : +)\n"; system($cmd)==0 or die "Error: $? $!: could not '$cmd'"; open $snctime, "> $syncfile" or die "Error: Can not open: $!\n"; my $now_string = time; #my $now_string = time - 86400; # 86400 sec = 1 day, do this to sy +nc always... #print "$now_string\n"; print $snctime $now_string; close $snctime; } else { print "continuing without sync...\n"; } my $muster = 'x11-base/xorg-x11'; my $mergetime = `emerge -puND world | genlop --pretend`; my $nvidia = ''; if ($mergetime =~ m/$muster/){ print $mergetime; print "$muster found in update list, merging nvidia-kernel too...\ +n"; $nvidia = '&& emerge nvidia-kernel'; } else { print $mergetime; } my $eupdatedb = ''; if ($wantsync){ $eupdatedb = 'eupdatedb >&/dev/null; '; } unless (fork){ print "forking silently into the background: $eupdatedb emerge -fu +ND world >\&/dev/null\n"; exec($eupdatedb . 'emerge -fuND world >&/dev/null'); } # interactive mode $cmd = 'emerge -autND world ' . $nvidia . '&& etc-update && /home/joni +x/yacleaner-0.3 -a -v all'; # automatic mode - update without questions #$cmd = $eupdatedb . 'emerge -fuND world >&/dev/null; emerge -uND worl +d ' . $nvidia . '&& etc-update && updatedb >&/dev/null; /home/jonix/y +acleaner-0.3 -a -v all'; print "executing: $cmd\n"; if (!(system($cmd)==0)){ print "Error: $? $!: could not '$cmd'\nTrying to resume...\n"; $cmd = 'emerge --resume && etc-update && /home/jonix/yacleaner-0.3 + -a -v all'; print $cmd . "\n"; if (!(system($cmd)==0)){ print "Error: $? $!: could not '$cmd'\nTrying to resume, skipp +ing failed package..."; $cmd = 'emerge --resume --skipfirst && etc-update && /home/jon +ix/yacleaner-0.3 -a -v all'; print $cmd . "\n"; system($cmd)==0 or die "Error: $? $!: could not '$cmd'\nCould +not merge, it is up to you now to seek for help...\n"; } } unless (fork){ print "executing: updatedb >&/dev/null\n"; exec('updatedb >&/dev/null'); }
I know there are sweet modules for written english time - I reinvented a wheel before finding out. Your Mother has warned you certainly :)

In reply to Re: Private Utilities by jonix
in thread Private Utilities by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found