4 Commits

Author SHA1 Message Date
Jay Larson
98c0ab336f The following changes were made:
* Updated Makefile.snaplinux to be more flexible with package names
  * Added bit to set root password in snapinstall
2017-06-02 18:49:47 -05:00
Jay Larson
cdbf4ed7d5 The following changes were made:
* Added ability to dump contents of package
  * Wrapped open3 in eval in Package.pm files()
  * Added :flock to Fcntl in Snap.pm
  * Added lock file to Snap.pm
  * Moved setup() under conditionals where appropriate in snap
2017-06-01 10:39:51 -05:00
Jay Larson
bfa1d110c4 The following changes were made
* Updated Makefile to get version from Snap.pm
  * Updated virtfs() in Snap.pm to properly check for dir with -d
2017-05-31 10:54:33 -05:00
Jay Larson
d306fe03ae The following changes were made:
* corrected issue in reinstall that prevented reinstall of package files
  * added version command
  * updated files() in Package.pm to accept both quiet and verbose options
  * added sha() to Snap.pm which will be used for verify function in future
  * corrected missing '=' in output for search() in Sources.pm
  * removed duplicate file (SRC/snapinstall)
2017-05-26 15:48:52 -05:00
9 changed files with 199 additions and 131 deletions

View File

@@ -12,11 +12,13 @@ DEPENDS = binutils,coreutils,gzip,perl>=5.20.0,tar
ARCH = x86_64 ARCH = x86_64
URL = URL =
DESC = The Snaplinux package management system DESC = The Snaplinux package management system
SNAPVER = 0
ARCHIVE := '' ARCHIVE := ''
SRCDIR := $(PWD)/SRC/snap SRCDIR := $(PWD)/SRC/snap
PATCHDIR := $(PWD)/SRC/patches PATCHDIR := $(PWD)/SRC/patches
VERSION := 0.6-0 VERSION := $(shell grep 'VERSION =>' SRC/snap/Snap.pm| \
sed "s/.*=> '\|',//g")-$(SNAPVER)
include /usr/share/snap/Makefile.snaplinux include /usr/share/snap/Makefile.snaplinux

View File

@@ -208,6 +208,11 @@ my $commands = {
. " separate\n\t\t\t\tdirectory/file system\n", . " separate\n\t\t\t\tdirectory/file system\n",
"\t\t\t\tProceed without prompting" "\t\t\t\tProceed without prompting"
] ]
},
version => {
options => [],
brief => 'Display version information',
help => []
} }
}; };

View File

@@ -9,16 +9,21 @@
# GNU General Public License for more details. # GNU General Public License for more details.
PWD := $(shell pwd) PWD := $(shell pwd)
PACKAGE := $(shell echo $(PWD)|sed 's/.*\///')
SNAPDIR = $(PWD)/SNAP SNAPDIR = $(PWD)/SNAP
ROOT = $(PWD)/ROOT ROOT = $(PWD)/ROOT
# This allows the package Makefile to override the name # This will set PACKAGE only if the package itself has
# of the package file. Added for the kernel package # not provided a package name
# though could be useful for others
ifndef SNAP ifndef PACKAGE
SNAP := $(PACKAGE)-$(VERSION).snap PACKAGE := $(shell echo $(PWD)|sed 's/.*\///')
endif
# This defines the name of the package file unless
# specified
ifndef PKGFILE
PKGFILE := $(PACKAGE)-$(VERSION).snap
endif endif
SNAPINFO = $(SNAPDIR)/snapinfo SNAPINFO = $(SNAPDIR)/snapinfo
@@ -31,7 +36,7 @@ FILES = $(SNAPDIR)/files.tar.gz
# if we find that not to be supplied we're going to # if we find that not to be supplied we're going to
# assume that the SRCPKG is the same as the PACKAGE # assume that the SRCPKG is the same as the PACKAGE
ifndef SRCPKG) ifndef SRCPKG
SRCPKG := $(PACKAGE) SRCPKG := $(PACKAGE)
endif endif
@@ -41,19 +46,19 @@ ifndef VERSION
$(error VERSION is not set) $(error VERSION is not set)
endif endif
$(SNAP): $(SNAPINFO) $(FILES) $(PKGFILE): $(SNAPINFO) $(FILES)
@if [ -f $(SNAP) ]; then \ @if [ -f $(PKGFILE) ]; then \
rm -v $(SNAP); \ rm -v $(PKGFILE); \
fi fi
@ar cvr $(SNAP) $(SNAPINFO) $(MANIFEST); \ @ar cvr $(PKGFILE) $(SNAPINFO) $(MANIFEST); \
if [ -f $(USHER) ]; then \ if [ -f $(USHER) ]; then \
chmod +x $(USHER); \ chmod +x $(USHER); \
ar cvr $(SNAP) $(USHER); \ ar cvr $(PKGFILE) $(USHER); \
fi; \ fi; \
ar cvr $(SNAP) $(FILES) ar cvr $(PKGFILE) $(FILES)
@echo "Successfully built $(SNAP)" @echo "Successfully built $(PKGFILE)"
$(SNAPINFO): $(MANIFEST) $(SNAPINFO): $(MANIFEST)
@>$(SNAPINFO) @>$(SNAPINFO)

View File

@@ -282,6 +282,87 @@ sub depends {
$self->revdeps( $sources, $dependencies ); $self->revdeps( $sources, $dependencies );
} }
sub dump {
my $self = shift;
my $pid;
my $sel;
my $cnt;
my $stderr;
my $stat;
local $| = 1;
if ( $self->{'path'} =~ /^https*:\/\// ) {
( my $filename = $self->{'path'} ) =~ s/.*\///;
Snap->httpget( $self->{'path'}, Snap->PKGDIR
. "/$filename", 0644 );
$self->{'path'} = Snap->PKGDIR . "/$filename";
}
print "Dumping $self->{'name'}=$self->{'version'}\n";
print "\e[?25l\r";
eval {
my $target = Snap->TARGET ||
"$self->{'name'}-$self->{'version'}";
if ( ! -d $target ) {
mkdir( $target );
}
$pid = open3( \*CHLDIN, \*CHLDOUT, \*CHLDERR,
"/usr/bin/ar p $self->{'path'} files.tar.gz|"
. "tar --no-overwrite-dir --keep-directory-symlink"
. " -hzvxf - -C $target" );
} || Snap->error( int( $! ), "open3(): /usr/bin/ar: $!" );
close( CHLDIN );
$sel = IO::Select->new();
$sel->add( *CHLDOUT, *CHLDERR );
while ( my @fhs = $sel->can_read ) {
foreach my $fh ( @fhs ) {
if ( eof( $fh ) ) {
$sel->remove( $fh );
next;
}
if ( fileno( $fh ) == fileno( *CHLDOUT ) ) {
my $line = <$fh>;
( my $file = $line ) =~ s/.*\/|\n$//;
chomp( $line );
chomp( $file );
if ( $file ) {
$cnt++;
print "\e[K$file\r";
}
}
elsif ( fileno( $fh ) == fileno( *CHLDERR ) ) {
$stderr .= <$fh>;
}
}
}
close( CHLDOUT );
close( CHLDERR );
waitpid( $pid, 0 );
$stat = $? >> 8;
if ( $stat ) {
Snap->error( $stat, "Failed dumping $self->{'name'}:"
. " $stderr\e[?25h" );
}
print "\e[K$cnt files extracted\e[?25h\n";
}
sub files { sub files {
my $self = shift; my $self = shift;
my $opts = shift; my $opts = shift;
@@ -293,8 +374,13 @@ sub files {
my $stdout; my $stdout;
my $stderr; my $stderr;
my $stat; my $stat;
my $pid = open3( \*CHLDIN, \*CHLDOUT, \*CHLDERR, my $pid;
"/usr/bin/ar p $self->{'path'} manifest" );
eval {
$pid = open3( \*CHLDIN, \*CHLDOUT, \*CHLDERR,
"/usr/bin/ar p $self->{'path'} manifest" );
} || Snap->error( int( $! ), "open3(): /usr/bin/ar:"
. " $!" );
close( CHLDIN ); close( CHLDIN );
@@ -317,7 +403,12 @@ sub files {
next; next;
} }
if ( $opts->{'quiet'} ) { if ( $opts->{'quiet'} &&
$opts->{'verbose'} ) {
push( @{$self->{'files'}}, [
$sha, $perms, $file ] );
}
elsif ( $opts->{'quiet'} ) {
push( @{$self->{'files'}}, push( @{$self->{'files'}},
$file ); $file );
} }
@@ -367,7 +458,13 @@ sub files {
$self->{'files'} = []; $self->{'files'} = [];
} }
push( @{$self->{'files'}}, $file ); if ( $opts->{'verbose'} ) {
push( @{$self->{'files'}}, [
$sha, $perms, $file ] );
}
else {
push( @{$self->{'files'}}, $file );
}
} }
elsif ( $opts->{'verbose'} ) { elsif ( $opts->{'verbose'} ) {
print "$sha\t$perms\t$file\n"; print "$sha\t$perms\t$file\n";

View File

@@ -7,7 +7,7 @@ use Snap::Commands;
use Snap::Package; use Snap::Package;
use Snap::Sources; use Snap::Sources;
use Fcntl; use Fcntl qw( :flock );
use IPC::Open3; use IPC::Open3;
use IO::Socket::INET; use IO::Socket::INET;
use Digest::SHA qw( sha256_hex ); use Digest::SHA qw( sha256_hex );
@@ -27,6 +27,8 @@ our @EXPORT = qw(
readconf readconf
refresh refresh
setup setup
sha
sha256
target target
termsize termsize
vercmp vercmp
@@ -87,7 +89,7 @@ use constant VERFILE => eval {
} }
}; };
use constant { use constant {
VERSION => '0.3', VERSION => '0.10',
SNAPDIR => TARGET . '/var/lib/snap', SNAPDIR => TARGET . '/var/lib/snap',
PKGDIR => TARGET . '/var/lib/snap/packages', PKGDIR => TARGET . '/var/lib/snap/packages',
INSTDIR => TARGET . '/var/lib/snap/installed', INSTDIR => TARGET . '/var/lib/snap/installed',
@@ -103,6 +105,7 @@ use constant SNAPVER => eval {
return( $version ); return( $version );
}; };
use constant LOCKFILE => '/var/lock/snap';
############################################################ ############################################################
# #
@@ -112,6 +115,17 @@ use constant SNAPVER => eval {
$0 =~ s/.*\///; $0 =~ s/.*\///;
############################################################
#
# Exit unless we can get exclusive lock
#
############################################################
open( LOCK, '>', LOCKFILE ) || Snap->error( int( $! ), "open(): "
. LOCKFILE . ": Unable to open lock file" );
flock( LOCK, LOCK_EX|LOCK_NB ) || Snap->error( int( $! ), "flock(): "
. LOCKFILE . ": Unable to lock file" );
############################################################ ############################################################
# #
# Make sure we bring back the cursor if we're killed # Make sure we bring back the cursor if we're killed
@@ -648,6 +662,15 @@ sub setup {
} }
} }
sub sha {
my $file = shift;
my $digest = eval {
Digest::SHA->new( 1 )->addfile( $file );
} || Snap->error( -1, "sha(): $file: $!\n" );
return( $digest->hexdigest );
}
### sha256() ############################################### ### sha256() ###############################################
# #
# This sub returns a hex sha256 hash of a supplied file # This sub returns a hex sha256 hash of a supplied file
@@ -821,7 +844,7 @@ sub virtfs {
my $stat = 0; my $stat = 0;
my $pid; my $pid;
if ( ! -f $virtfs->{$fs}{'dir'} ) { if ( ! -d $virtfs->{$fs}{'dir'} ) {
next; next;
} }

View File

@@ -219,7 +219,7 @@ sub search {
if ( ! @$packages ) { if ( ! @$packages ) {
if ( $opts->{'name'} && $opts->{'version'} ) { if ( $opts->{'name'} && $opts->{'version'} ) {
Snap->error( 0, "Snap::Sources::search():" Snap->error( 0, "Snap::Sources::search():"
. " $opts->{'name'}$opts->{'version'}:" . " $opts->{'name'}=$opts->{'version'}:"
. " No such package" ); . " No such package" );
} }
elsif ( $opts->{'name'} ) { elsif ( $opts->{'name'} ) {

View File

@@ -6,15 +6,6 @@ use warnings;
use Snap; use Snap;
use Data::Dumper; use Data::Dumper;
############################################################
#
# setup() will give the user the option to create the files
# and directories needed for snap to function
#
############################################################
setup();
my $command = shift( @ARGV ); my $command = shift( @ARGV );
my $conf = readconf(); my $conf = readconf();
my $commands = Snap::Commands->new(); my $commands = Snap::Commands->new();
@@ -23,9 +14,15 @@ my $sources = Snap::Sources->new( $conf->{'sources'} );
if ( $ARGV[0] && $ARGV[0] eq '-h' ) { if ( $ARGV[0] && $ARGV[0] eq '-h' ) {
$commands->commandhelp( $command ); $commands->commandhelp( $command );
} }
elsif ( $command eq 'genpkg' ) { elsif ( $command eq 'dump' ) {
print "\n";
foreach my $arg ( @ARGV ) { foreach my $arg ( @ARGV ) {
genpkg( $arg ); my $package = Snap::Package->new( $arg );
$package->dump();
print "\n";
} }
} }
elsif ( $command eq 'files' ) { elsif ( $command eq 'files' ) {
@@ -61,11 +58,15 @@ elsif ( $command eq 'files' ) {
print "\n"; print "\n";
} }
elsif ( $command eq 'genpkg' ) {
foreach my $arg ( @ARGV ) {
genpkg( $arg );
}
}
elsif ( $command eq 'help' ) { elsif ( $command eq 'help' ) {
$commands->help(); $commands->help();
} }
elsif ( $command eq 'info' ) { elsif ( $command eq 'info' ) {
print "\n"; print "\n";
foreach my $arg ( @ARGV ) { foreach my $arg ( @ARGV ) {
@@ -104,6 +105,8 @@ elsif ( $command eq 'install' ) {
my $bytes = 0; my $bytes = 0;
my $virtfs = 0; my $virtfs = 0;
setup();
foreach my $attrib ( @attribs ) { foreach my $attrib ( @attribs ) {
if ( $string =~ /$attrib\s*:\s*(\S+)/ ) { if ( $string =~ /$attrib\s*:\s*(\S+)/ ) {
$opts->{$attrib} = $1; $opts->{$attrib} = $1;
@@ -331,6 +334,8 @@ elsif ( $command eq 'list' ) {
print "\n"; print "\n";
} }
elsif ( $command eq 'refresh' ) { elsif ( $command eq 'refresh' ) {
setup();
print "\n"; print "\n";
$sources->refresh(); $sources->refresh();
@@ -361,12 +366,26 @@ elsif ( $command eq 'reinstall' ) {
my $packages = []; my $packages = [];
my $virtfs = 0; my $virtfs = 0;
setup();
$sources->readpkgs(); $sources->readpkgs();
print "\n"; print "\n";
foreach my $pkgname ( @ARGV ) { foreach my $pkgname ( @ARGV ) {
my $package = $sources->{'installed'}{$pkgname}; my $package;
if ( -f $pkgname ) {
$package = Snap::Package->new( $pkgname );
}
else {
$package = $sources->{'installed'}{$pkgname};
$package = $sources->search( {
name => $package->{'name'},
version => $package->{'version'},
quiet => 1
} );
}
if ( ! $package ) { if ( ! $package ) {
print STDERR "Package '$pkgname' not installed\n"; print STDERR "Package '$pkgname' not installed\n";
@@ -374,12 +393,6 @@ elsif ( $command eq 'reinstall' ) {
next; next;
} }
$package = $sources->search( {
name => $package->{'name'},
version => $package->{'version'},
quiet => 1
} );
if ( $package->{'path'} =~ /https*:\/\// ) { if ( $package->{'path'} =~ /https*:\/\// ) {
( my $filename = $package->{'path'} ) =~ s/.*\///; ( my $filename = $package->{'path'} ) =~ s/.*\///;
@@ -613,6 +626,9 @@ elsif ( $command eq 'verify' ) {
print Dumper( $package ); print Dumper( $package );
} }
} }
elsif ( $command eq 'version' ) {
print "\n" . Snap->VERSION . "\n\n";
}
elsif ( $command ) { elsif ( $command ) {
print "\n"; print "\n";

9
SRC/snap/snapinstall Executable file → Normal file
View File

@@ -84,6 +84,15 @@ foreach my $package ( @$packages ) {
$package->install(); $package->install();
} }
if ( $virtfs ) {
if ( $pid = fork() ) {
waitpid( $pid, 0 );
}
else {
exec( "chroot " . Snap->TARGET . " passwd" );
}
}
virtfs( 'umount' ); virtfs( 'umount' );
print "\n"; print "\n";

View File

@@ -1,89 +0,0 @@
#!/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";