Skip to content
Merged
12 changes: 7 additions & 5 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,13 @@ sub _update_isos {
,options => { machine => 'pc-q35'}
}
,parrot_xfce_amd64 => {
name => 'Parrot Home Edition XFCE 7.1'
,description => 'Parrot Home Edition XFCE 7.1 64 Bits'
name => 'Parrot Home Edition XFCE 7.3'
,description => 'Parrot Home Edition XFCE 7.3 64 Bits'
,arch => 'x86_64'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,url => 'https://download.parrot.sh/parrot/iso/7.1/'
,file_re => 'Parrot-home-7\.1.*_amd64\.iso'
,url => 'https://download.parrot.sh/parrot/iso/7.3/'
,file_re => 'Parrot-home-7\.3.*_amd64\.iso'
,sha256_url => '$url/signed-hashes.txt'
,min_disk_size => '15'
}
Expand Down Expand Up @@ -1584,7 +1584,9 @@ sub _update_table($self, $table, $field, $data, $verbose=0) {
sub _remove_old_isos {
my $self = shift;
for my $sql (
"DELETE FROM iso_images "
"Delete FROM iso_images "
."WHERE url like 'https://download.parrot.sh/parrot/iso/7.1/'"
,"DELETE FROM iso_images "
Comment on lines +1598 to +1600
." WHERE url like '%debian-9.0%iso'"
,"DELETE FROM iso_images"
." WHERE name like 'Debian%' "
Expand Down
87 changes: 87 additions & 0 deletions script/rvd_back
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ my $HIBERNATE_DOMAIN;
my $START_DOMAIN;
my $SHUTDOWN_DOMAIN;
my $REMOVE_DOMAIN;
my $REMOVE_CLONES;
my $RECURSIVE;
my $REBASE;
my $RUN_REQUEST;
my $MIGRATE;
Expand Down Expand Up @@ -167,6 +169,8 @@ GetOptions ( help => \$help
,'shutdown'=> \$SHUTDOWN_DOMAIN
,'hibernate'=> \$HIBERNATE_DOMAIN
,'remove:s'=> \$REMOVE_DOMAIN
,'remove-clones=s' => \$REMOVE_CLONES
,'recursive' => \$RECURSIVE
Comment on lines 172 to +174
,'disconnected'=> \$DISCONNECTED
,'remove-user=s'=> \$REMOVE_USER
,'make-admin=s' => \$MAKE_ADMIN_USER
Expand Down Expand Up @@ -365,6 +369,23 @@ sub add_user {

my $ravada = Ravada->new( %CONFIG);

my $sth_check = $ravada->_dbh->prepare(
"SELECT name ".
"FROM users ".
"WHERE name = ?"
);
$sth_check->execute($login);
my $usern = $sth_check->fetchrow();
while ($usern){
$usern = undef;
print "There is already a user with that username \n";
print "Try using another username \n";
$login = <STDIN>;
chomp $login;
$sth_check->execute($login);
$usern = $sth_check->fetchrow();
Comment on lines +382 to +389
}

print "$login password: ";
ReadMode('noecho');
my $password = <STDIN>;
Expand Down Expand Up @@ -735,6 +756,71 @@ sub hibernate(@domains) {
exit;
}

sub remove_clones($REMOVE_CLONES) {
$RECURSIVE //= 0;
my $ravada = Ravada->new(%CONFIG);
my $sth_getinfo = $ravada->_dbh->prepare(
"SELECT id, is_base ".
"FROM domains ".
"WHERE name = ?"
);

$sth_getinfo->execute($REMOVE_CLONES);
my ($domainid, $isbase) = $sth_getinfo->fetchrow();

if(!$domainid) {
print "Domain not found.\n";
return;
}

if ($isbase == 1) {
remove_clones_rec($domainid, $ravada);
}

else {
print "The domain '$REMOVE_CLONES' is not a base, there are no clones to delete.\n";
}

}

sub remove_clones_rec($id_parent, $ravada) {

my $sth_getclones = $ravada->_dbh->prepare(
"SELECT id, name, is_base ".
"FROM domains ".
"WHERE id_base = ?"
);
$sth_getclones->execute($id_parent);

my @clones;
while (my $row = $sth_getclones->fetchrow_hashref()) {
push @clones, $row;
}
$sth_getclones->finish();


for my $clone (@clones) {
my $clone_id = $clone->{id};
my $clone_name = $clone->{name};
my $isbase = $clone->{is_base};

if ($isbase) {
if($RECURSIVE) {
remove_clones_rec($clone_id, $ravada);
}
}
else {
print "Deleting clone '$clone_name'.\n";
#hacerlo con el request en vez de hacer un delete de base de datos
Ravada::Request->remove_domain(
Comment thread
frankiejol marked this conversation as resolved.
uid => Ravada::Utils::user_daemon()->id
,name => $clone_name
);
}
}

}

sub remove_domain {
my $domain_name = shift;

Expand Down Expand Up @@ -1436,6 +1522,7 @@ rebase() if $REBASE;

list($ALL) if $LIST;
remove_domain($REMOVE_DOMAIN) if defined $REMOVE_DOMAIN;
remove_clones($REMOVE_CLONES, $RECURSIVE) if defined $REMOVE_CLONES;
start_domain($START_DOMAIN) if $START_DOMAIN;

shutdown_domain(@domains) if defined $SHUTDOWN_DOMAIN;
Expand Down
Loading