Public
Snippet $1655250 authored by Jesse

Perl script to execute "xbps-remove -o" and "xbps-remove -O"

Edited
xbps-cleanup.pl
#!/usr/bin/env perl

#####################################
# File: xbps-cleanup
# Language: Perl
# Version: 1
# Author: culb (nightfrog)
# Contact: the01culb[at]gmail[dot]com
# Usage: sudo xbps-cleanup
# Purpose:Run xbps-remove (-o && -O)
#####################################

use strict;
use warnings;

# Sleep is used between commands but it's not needed after the last command
# The following variable is to keep track of what iteration
my $i = 0;

for my $command ( 'xbps-remove -o', 'xbps-remove -O' )
{
    print "\e[34m### Beginning of $command ###\033[0m\n";

    if( system( $command ) != 0 )
    {
        if( $? == -1 )
        {
            print "\e[31m Failed to execute: $!\033[0m\n";
        }
        elsif( $? & 127 )
        {
            printf "\e[31mChild died with signal %d, %s coredump\033[0m\n",
                   ( $? & 127 ),  ( $? & 128 ) ? 'with' : 'without';
        }
        else
        {
            printf "\e32m Child exited with value %d\033[0m \n", $? >> 8;
        }
    }

    print "\e[34m### End of $command ###\033[0m\n";
    last if $i == 1;# Last round, no need to sleep or increment
    sleep 1;# Just because
    ++$i;
}

print "\e[32m### xbps-remove has completed ###\033[0m\n";
1;