diff --git a/Makefile b/Makefile index 59955c7..72cb4c8 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ DESC = The Snaplinux package management system ARCHIVE := '' SRCDIR := $(PWD)/SRC/snap PATCHDIR := $(PWD)/SRC/patches -VERSION := 0.5-0 +VERSION := 0.6-0 MAKEINST = make install diff --git a/SRC/snap/Makefile b/SRC/snap/Makefile index 4c74d5b..8b53de4 100644 --- a/SRC/snap/Makefile +++ b/SRC/snap/Makefile @@ -5,6 +5,7 @@ dirs: files: install -v -m 755 snap $(DESTDIR)/usr/bin/snap + install -v -m 755 snapinstall $(DESTDIR)/usr/bin/snapinstall install -v -m 644 Makefile.skel \ $(DESTDIR)/usr/share/snap/Makefile.skel install -v -m 644 Makefile.snaplinux \ diff --git a/SRC/snap/snap b/SRC/snap/snap index 97b9a83..64a7ab2 100755 --- a/SRC/snap/snap +++ b/SRC/snap/snap @@ -303,13 +303,13 @@ elsif ( $command eq 'install' ) { chkyes(); - print "\n"; - foreach my $package ( @$packages ) { if ( ! $virtfs ) { $virtfs = virtfs( 'mount' ); } + print "\n"; + $package->install( $sources ); } @@ -346,6 +346,97 @@ elsif ( $command eq 'refresh' ) { print "\n"; } } +elsif ( $command eq 'reinstall' ) { + my $opts = { + yes => eval { + for ( my $i = 0; $i <= $#ARGV; $i++ ) { + if ( $ARGV[$i] eq '-y' ) { + splice( @ARGV, $i, 1 ); + + return( 1 ); + } + } + } + }; + my $packages = []; + my $virtfs = 0; + + $sources->readpkgs(); + + print "\n"; + + foreach my $pkgname ( @ARGV ) { + my $package = $sources->{'installed'}{$pkgname}; + + if ( ! $package ) { + print STDERR "Package '$pkgname' not installed\n"; + + next; + } + + $package = $sources->search( { + name => $package->{'name'}, + version => $package->{'version'}, + quiet => 1 + } ); + + if ( $package->{'path'} =~ /https*:\/\// ) { + ( my $filename = $package->{'path'} ) =~ s/.*\///; + + if ( ! -f Snap->PKGDIR . "/$filename" ) { + Snap->httpget( $package->{'path'}, + Snap->PKGDIR . "/$filename", 0644 ); + } + + $package->{'path'} = Snap->PKGDIR . "/$filename"; + } + + push( @$packages, $package ); + } + + foreach my $package ( @$packages ) { + my $termsize = Snap->termsize(); + my $cnt = 0; + + foreach my $package ( sort { $a->{'name'} cmp $b->{'name'} } + ( @$packages ) ) { + if ( ! $cnt ) { + print "The following packages will be" + . " reinstalled:\n "; + } + + if ( $termsize->{'col'} - ( length( + $package->{'name'} ) + 3 ) <= 0 ) { + print "\n "; + + $termsize = Snap->termsize(); + } + + print "$package->{'name'} "; + + $termsize->{'col'} -= length( $package->{'name'} ) + 1; + $cnt++; + } + } + + print "\n\nContinue? (y/n): "; + + chkyes(); + + foreach my $package ( @$packages ) { + if ( ! $virtfs ) { + $virtfs = virtfs( 'mount' ); + } + + print "\n"; + + $package->install(); + } + + virtfs( 'umount' ); + + print "\n"; + } elsif ( $command eq 'remove' ) { my $opts = { nodeps => eval { diff --git a/SRC/snap/snapinstall b/SRC/snap/snapinstall new file mode 100755 index 0000000..d1bda7f --- /dev/null +++ b/SRC/snap/snapinstall @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Snap; +use Data::Dumper; + +setup(); + +my $conf = readconf(); +my $sources = Snap::Sources->new( $conf->{'sources'} ); + +my $opts = { + repo => 'core', + quiet => 1 + }; +my $corepkgs; +my $packages; +my $virtfs = 0; +my $prepkgs = {}; +my $prelist = [ 'snap-base', 'bash', 'coreutils', 'glibc', + 'libacl', 'libattr', 'libcap', 'ncurses', 'readline', + 'tzdata', 'perl', 'initscripts' ]; + +print "\n"; + +if ( ! Snap->TARGET ) { + Snap->error( -1, 'A target must be specified with -t' ); + } + +$sources->readpkgs(); +$corepkgs = $sources->search( $opts ); + +for ( my $i = 0; $i <= $#$corepkgs; $i++ ) { + if ( ! $opts->{'nodeps'} ) { + print "Resolving dependencies for" + . " $corepkgs->[$i]{'name'}\n"; + + $corepkgs->[$i]->depends( $sources, $packages ); + } + else { + print "Ignoring dependencies for" + . " $corepkgs->[$i]{'name'}\n"; + } + + push( @$packages, $corepkgs->[$i] ); + } + +for ( my $i = 0; $i <= $#$packages; $i++ ) { + if ( $packages->[$i]{'path'} =~ /https*:\/\// ) { + ( my $filename = $packages->[$i]{'path'} ) =~ s/.*\///; + + if ( ! -f Snap->PKGDIR . "/$filename" ) { + Snap->httpget( $packages->[$i]{'path'}, + Snap->PKGDIR . "/$filename", 0644 ); + } + + $packages->[$i]{'path'} = Snap->PKGDIR . "/$filename"; + } + + + if ( grep( $_ eq $packages->[$i]{'name'}, @$prelist ) ) { + $prepkgs->{$packages->[$i]{'name'}} = $packages->[$i]; + + splice( @$packages, $i, 1 ); + $i--; + } + } + +foreach my $package ( @$prelist ) { + print "\n"; + + $prepkgs->{$package}->install(); + } + +foreach my $package ( @$packages ) { + if ( ! $virtfs ) { + $virtfs = virtfs( 'mount' ); + } + + print "\n"; + + $package->install(); + } + +virtfs( 'umount' ); + +print "\n";