Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdbf4ed7d5 | ||
|
|
bfa1d110c4 | ||
|
|
d306fe03ae | ||
|
|
319401eb51 | ||
|
|
4cd5b95d7e |
8
Makefile
8
Makefile
@@ -12,13 +12,13 @@ DEPENDS = binutils,coreutils,gzip,perl>=5.20.0,tar
|
||||
ARCH = x86_64
|
||||
URL =
|
||||
DESC = The Snaplinux package management system
|
||||
SNAPVER = 0
|
||||
|
||||
ARCHIVE := ''
|
||||
SRCDIR := $(PWD)/SRC/snap
|
||||
PATCHDIR := $(PWD)/SRC/patches
|
||||
VERSION := 0.5-0
|
||||
|
||||
MAKEINST = make install
|
||||
VERSION := $(shell grep 'VERSION =>' SRC/snap/Snap.pm| \
|
||||
sed "s/.*=> '\|',//g")-$(SNAPVER)
|
||||
|
||||
include /usr/share/snap/Makefile.snaplinux
|
||||
|
||||
@@ -29,7 +29,7 @@ $(ROOT): $(SRCDIR)/Makefile
|
||||
mkdir -v $(ROOT); \
|
||||
fi
|
||||
|
||||
@cd $(SRCDIR) && $(MAKEINST) DESTDIR=$(ROOT)
|
||||
@cd $(SRCDIR) && make install DESTDIR=$(ROOT)
|
||||
|
||||
clean:
|
||||
@rm -rvf $(ROOT) \
|
||||
|
||||
@@ -208,6 +208,11 @@ my $commands = {
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
version => {
|
||||
options => [],
|
||||
brief => 'Display version information',
|
||||
help => []
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -17,8 +17,8 @@ ROOT = $(PWD)/ROOT
|
||||
# of the package file. Added for the kernel package
|
||||
# though could be useful for others
|
||||
|
||||
ifeq ( $(SNAP), )
|
||||
SNAP = $(PACKAGE)-$(VERSION).snap
|
||||
ifndef SNAP
|
||||
SNAP := $(PACKAGE)-$(VERSION).snap
|
||||
endif
|
||||
|
||||
SNAPINFO = $(SNAPDIR)/snapinfo
|
||||
@@ -31,7 +31,7 @@ FILES = $(SNAPDIR)/files.tar.gz
|
||||
# if we find that not to be supplied we're going to
|
||||
# assume that the SRCPKG is the same as the PACKAGE
|
||||
|
||||
ifeq ( $(SRCPKG), )
|
||||
ifndef SRCPKG)
|
||||
SRCPKG := $(PACKAGE)
|
||||
endif
|
||||
|
||||
@@ -116,12 +116,15 @@ $(FILES): $(ROOT)
|
||||
type=`file -i $$file|sed 's/.*: //'`; \
|
||||
case $$type in \
|
||||
*'/x-executable; charset=binary') \
|
||||
echo "--strip-unneeded $$file"; \
|
||||
strip --strip-unneeded $$file \
|
||||
;; \
|
||||
*'/x-object; charset=binary') \
|
||||
echo "--strip-debug $$file"; \
|
||||
strip --strip-debug $$file \
|
||||
;; \
|
||||
*'/x-sharedlib; charset=binary') \
|
||||
echo "--strip-debug $$file"; \
|
||||
strip --strip-debug $$file \
|
||||
;; \
|
||||
esac; \
|
||||
|
||||
@@ -282,6 +282,87 @@ sub depends {
|
||||
$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 {
|
||||
my $self = shift;
|
||||
my $opts = shift;
|
||||
@@ -293,8 +374,13 @@ sub files {
|
||||
my $stdout;
|
||||
my $stderr;
|
||||
my $stat;
|
||||
my $pid = open3( \*CHLDIN, \*CHLDOUT, \*CHLDERR,
|
||||
my $pid;
|
||||
|
||||
eval {
|
||||
$pid = open3( \*CHLDIN, \*CHLDOUT, \*CHLDERR,
|
||||
"/usr/bin/ar p $self->{'path'} manifest" );
|
||||
} || Snap->error( int( $! ), "open3(): /usr/bin/ar:"
|
||||
. " $!" );
|
||||
|
||||
close( CHLDIN );
|
||||
|
||||
@@ -317,7 +403,12 @@ sub files {
|
||||
next;
|
||||
}
|
||||
|
||||
if ( $opts->{'quiet'} ) {
|
||||
if ( $opts->{'quiet'} &&
|
||||
$opts->{'verbose'} ) {
|
||||
push( @{$self->{'files'}}, [
|
||||
$sha, $perms, $file ] );
|
||||
}
|
||||
elsif ( $opts->{'quiet'} ) {
|
||||
push( @{$self->{'files'}},
|
||||
$file );
|
||||
}
|
||||
@@ -367,8 +458,14 @@ sub files {
|
||||
$self->{'files'} = [];
|
||||
}
|
||||
|
||||
if ( $opts->{'verbose'} ) {
|
||||
push( @{$self->{'files'}}, [
|
||||
$sha, $perms, $file ] );
|
||||
}
|
||||
else {
|
||||
push( @{$self->{'files'}}, $file );
|
||||
}
|
||||
}
|
||||
elsif ( $opts->{'verbose'} ) {
|
||||
print "$sha\t$perms\t$file\n";
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use Snap::Commands;
|
||||
use Snap::Package;
|
||||
use Snap::Sources;
|
||||
|
||||
use Fcntl;
|
||||
use Fcntl qw( :flock );
|
||||
use IPC::Open3;
|
||||
use IO::Socket::INET;
|
||||
use Digest::SHA qw( sha256_hex );
|
||||
@@ -27,6 +27,8 @@ our @EXPORT = qw(
|
||||
readconf
|
||||
refresh
|
||||
setup
|
||||
sha
|
||||
sha256
|
||||
target
|
||||
termsize
|
||||
vercmp
|
||||
@@ -87,7 +89,7 @@ use constant VERFILE => eval {
|
||||
}
|
||||
};
|
||||
use constant {
|
||||
VERSION => '0.3',
|
||||
VERSION => '0.9',
|
||||
SNAPDIR => TARGET . '/var/lib/snap',
|
||||
PKGDIR => TARGET . '/var/lib/snap/packages',
|
||||
INSTDIR => TARGET . '/var/lib/snap/installed',
|
||||
@@ -103,6 +105,7 @@ use constant SNAPVER => eval {
|
||||
|
||||
return( $version );
|
||||
};
|
||||
use constant LOCKFILE => '/var/lock/snap';
|
||||
|
||||
############################################################
|
||||
#
|
||||
@@ -112,6 +115,17 @@ use constant SNAPVER => eval {
|
||||
|
||||
$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
|
||||
@@ -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() ###############################################
|
||||
#
|
||||
# This sub returns a hex sha256 hash of a supplied file
|
||||
@@ -821,7 +844,7 @@ sub virtfs {
|
||||
my $stat = 0;
|
||||
my $pid;
|
||||
|
||||
if ( ! -f $virtfs->{$fs}{'dir'} ) {
|
||||
if ( ! -d $virtfs->{$fs}{'dir'} ) {
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ sub search {
|
||||
if ( ! @$packages ) {
|
||||
if ( $opts->{'name'} && $opts->{'version'} ) {
|
||||
Snap->error( 0, "Snap::Sources::search():"
|
||||
. " $opts->{'name'}$opts->{'version'}:"
|
||||
. " $opts->{'name'}=$opts->{'version'}:"
|
||||
. " No such package" );
|
||||
}
|
||||
elsif ( $opts->{'name'} ) {
|
||||
|
||||
135
SRC/snap/snap
135
SRC/snap/snap
@@ -6,15 +6,6 @@ use warnings;
|
||||
use Snap;
|
||||
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 $conf = readconf();
|
||||
my $commands = Snap::Commands->new();
|
||||
@@ -23,9 +14,15 @@ my $sources = Snap::Sources->new( $conf->{'sources'} );
|
||||
if ( $ARGV[0] && $ARGV[0] eq '-h' ) {
|
||||
$commands->commandhelp( $command );
|
||||
}
|
||||
elsif ( $command eq 'genpkg' ) {
|
||||
elsif ( $command eq 'dump' ) {
|
||||
print "\n";
|
||||
|
||||
foreach my $arg ( @ARGV ) {
|
||||
genpkg( $arg );
|
||||
my $package = Snap::Package->new( $arg );
|
||||
|
||||
$package->dump();
|
||||
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
elsif ( $command eq 'files' ) {
|
||||
@@ -61,11 +58,15 @@ elsif ( $command eq 'files' ) {
|
||||
|
||||
print "\n";
|
||||
}
|
||||
elsif ( $command eq 'genpkg' ) {
|
||||
foreach my $arg ( @ARGV ) {
|
||||
genpkg( $arg );
|
||||
}
|
||||
}
|
||||
elsif ( $command eq 'help' ) {
|
||||
$commands->help();
|
||||
}
|
||||
elsif ( $command eq 'info' ) {
|
||||
|
||||
print "\n";
|
||||
|
||||
foreach my $arg ( @ARGV ) {
|
||||
@@ -104,6 +105,8 @@ elsif ( $command eq 'install' ) {
|
||||
my $bytes = 0;
|
||||
my $virtfs = 0;
|
||||
|
||||
setup();
|
||||
|
||||
foreach my $attrib ( @attribs ) {
|
||||
if ( $string =~ /$attrib\s*:\s*(\S+)/ ) {
|
||||
$opts->{$attrib} = $1;
|
||||
@@ -303,13 +306,13 @@ elsif ( $command eq 'install' ) {
|
||||
|
||||
chkyes();
|
||||
|
||||
print "\n";
|
||||
|
||||
foreach my $package ( @$packages ) {
|
||||
if ( ! $virtfs ) {
|
||||
$virtfs = virtfs( 'mount' );
|
||||
}
|
||||
|
||||
print "\n";
|
||||
|
||||
$package->install( $sources );
|
||||
}
|
||||
|
||||
@@ -331,6 +334,8 @@ elsif ( $command eq 'list' ) {
|
||||
print "\n";
|
||||
}
|
||||
elsif ( $command eq 'refresh' ) {
|
||||
setup();
|
||||
|
||||
print "\n";
|
||||
|
||||
$sources->refresh();
|
||||
@@ -346,6 +351,105 @@ 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;
|
||||
|
||||
setup();
|
||||
|
||||
$sources->readpkgs();
|
||||
|
||||
print "\n";
|
||||
|
||||
foreach my $pkgname ( @ARGV ) {
|
||||
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 ) {
|
||||
print STDERR "Package '$pkgname' not installed\n";
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -522,6 +626,9 @@ elsif ( $command eq 'verify' ) {
|
||||
print Dumper( $package );
|
||||
}
|
||||
}
|
||||
elsif ( $command eq 'version' ) {
|
||||
print "\n" . Snap->VERSION . "\n\n";
|
||||
}
|
||||
elsif ( $command ) {
|
||||
print "\n";
|
||||
|
||||
|
||||
0
SRC/snapinstall → SRC/snap/snapinstall
Executable file → Normal file
0
SRC/snapinstall → SRC/snap/snapinstall
Executable file → Normal file
Reference in New Issue
Block a user