Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
915fb3e1f0 | ||
|
|
6b62f87bf6 | ||
|
|
d4baa191d6 | ||
|
|
98c0ab336f | ||
|
|
cdbf4ed7d5 | ||
|
|
bfa1d110c4 |
8
Makefile
8
Makefile
@@ -10,13 +10,17 @@
|
|||||||
|
|
||||||
DEPENDS = binutils,coreutils,gzip,perl>=5.20.0,tar
|
DEPENDS = binutils,coreutils,gzip,perl>=5.20.0,tar
|
||||||
ARCH = x86_64
|
ARCH = x86_64
|
||||||
URL =
|
URL = http://snaplinux.org
|
||||||
|
REPO = core
|
||||||
|
BRIEF = The Snaplinux package management system
|
||||||
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.7-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
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ my $commands = {
|
|||||||
],
|
],
|
||||||
brief => 'List package info',
|
brief => 'List package info',
|
||||||
help => [
|
help => [
|
||||||
"\t\tPKGNAME or FILE is required."
|
"\t\tOne or more PKGNAME or FILE is required.\n"
|
||||||
. " A version string\n\t\t\t\tcan optionally"
|
. "\t\t\t\tA version string can optionally"
|
||||||
. " be provided with the PKGNAME\n"
|
. " be provided\n\t\t\t\twith PKGNAME"
|
||||||
. "\t\t\t\tas packagename=x.x.x\n",
|
. " as packagename=x.x.x\n",
|
||||||
"\t\t\tAn optional target may be specified"
|
"\t\t\tAn optional target may be specified"
|
||||||
. " to\n\t\t\t\tquery a separate directory"
|
. " to\n\t\t\t\tquery a separate directory"
|
||||||
. "/file system"
|
. "/file system"
|
||||||
@@ -92,6 +92,10 @@ my $commands = {
|
|||||||
. "/file system"
|
. "/file system"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
provides => {
|
||||||
|
options => [],
|
||||||
|
brief => 'List packages that provide a file'
|
||||||
|
},
|
||||||
purge => {
|
purge => {
|
||||||
options => [
|
options => [
|
||||||
'<PKGNAME>',
|
'<PKGNAME>',
|
||||||
@@ -150,6 +154,17 @@ my $commands = {
|
|||||||
"\t\t\t\tProceed without prompting"
|
"\t\t\t\tProceed without prompting"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
revdep => {
|
||||||
|
options => [
|
||||||
|
'<PKGNAME>',
|
||||||
|
'[-t TARGET]'
|
||||||
|
],
|
||||||
|
brief => 'List installed packages that depend on <PKGNAME>',
|
||||||
|
help => [
|
||||||
|
"\t\t\tPKGNAME is required\n",
|
||||||
|
"\t\t\tAn optional target may be specified"
|
||||||
|
]
|
||||||
|
},
|
||||||
search => {
|
search => {
|
||||||
options => [
|
options => [
|
||||||
'[STRING[=VER]]',
|
'[STRING[=VER]]',
|
||||||
@@ -167,14 +182,16 @@ my $commands = {
|
|||||||
},
|
},
|
||||||
source => {
|
source => {
|
||||||
options => [
|
options => [
|
||||||
'<PKGNAME[=VER]>'
|
'<PKGNAME[=VER]>',
|
||||||
|
'[-l]'
|
||||||
],
|
],
|
||||||
brief => 'Retrieve package source',
|
brief => 'Retrieve package source',
|
||||||
help => [
|
help => [
|
||||||
"\t\tPKGNAME is required."
|
"\t\tPKGNAME is required."
|
||||||
. " A version string\n\t\t\t\tcan optionally"
|
. " A version string\n\t\t\t\tcan optionally"
|
||||||
. " be provided with the PKGNAME\n"
|
. " be provided with the PKGNAME\n"
|
||||||
. "\t\t\t\tas packagename=x.x.x"
|
. "\t\t\t\tas packagename=x.x.x\n",
|
||||||
|
"\t\t\t\tRetrieve the latest version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
upgrade => {
|
upgrade => {
|
||||||
@@ -227,15 +244,17 @@ sub commandhelp {
|
|||||||
my $options = $commands->{$command}{'options'};
|
my $options = $commands->{$command}{'options'};
|
||||||
my $help = $commands->{$command}{'help'};
|
my $help = $commands->{$command}{'help'};
|
||||||
|
|
||||||
print "\nsnap $command @{$commands->{$command}{'options'}}\n\n";
|
print "snap $command @{$commands->{$command}{'options'}}\n\n";
|
||||||
print "$commands->{$command}{'brief'}\n\n";
|
print "$commands->{$command}{'brief'}\n";
|
||||||
|
|
||||||
for ( my $i = 0; $i <= $#{$options}; $i++ ) {
|
for ( my $i = 0; $i <= $#{$options}; $i++ ) {
|
||||||
print " $options->[$i]$help->[$i]\n";
|
print "\n $options->[$i]$help->[$i]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( @$options ) {
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
@@ -248,7 +267,7 @@ sub help {
|
|||||||
Snap->error( -1, "usage(): Invalid option '$ARGV[0]'" );
|
Snap->error( -1, "usage(): Invalid option '$ARGV[0]'" );
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\nUsage: $0 <COMMAND> <ARGS>\n\n"
|
print "Usage: $0 <COMMAND> <ARGS>\n\n"
|
||||||
. "snap is the Snaplinux package management utility\n\n"
|
. "snap is the Snaplinux package management utility\n\n"
|
||||||
. "COMMANDS\n\n";
|
. "COMMANDS\n\n";
|
||||||
|
|
||||||
@@ -257,7 +276,7 @@ sub help {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print "\nTo view more information for commands run:\n"
|
print "\nTo view more information for commands run:\n"
|
||||||
. "snap <COMMAND> -h\n\n";
|
. "snap <COMMAND> -h\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
dirs:
|
dirs:
|
||||||
install -d -v -m 755 $(DESTDIR)/etc
|
install -d -v -m 755 $(DESTDIR)/etc/snap.d/templates
|
||||||
install -d -v -m 755 $(DESTDIR)/usr/{bin,share/snap}
|
install -d -v -m 755 $(DESTDIR)/usr/bin
|
||||||
|
install -d -v -m 755 $(DESTDIR)/usr/share/snap
|
||||||
install -d -v -m 755 $(DESTDIR)/usr/lib/perl5/vendor_perl/5.24.0/Snap
|
install -d -v -m 755 $(DESTDIR)/usr/lib/perl5/vendor_perl/5.24.0/Snap
|
||||||
|
|
||||||
files:
|
files:
|
||||||
@@ -18,5 +19,9 @@ files:
|
|||||||
$(DESTDIR)/usr/lib/perl5/vendor_perl/5.24.0/Snap/Sources.pm
|
$(DESTDIR)/usr/lib/perl5/vendor_perl/5.24.0/Snap/Sources.pm
|
||||||
install -v -m 644 Snap.pm \
|
install -v -m 644 Snap.pm \
|
||||||
$(DESTDIR)/usr/lib/perl5/vendor_perl/5.24.0/Snap.pm
|
$(DESTDIR)/usr/lib/perl5/vendor_perl/5.24.0/Snap.pm
|
||||||
|
@find templates -type d -exec install {} -d -v -m 755 \
|
||||||
|
$(DESTDIR)/etc/snap.d/templates/{} \; && \
|
||||||
|
find templates -type f -exec install {} -v -m 644 \
|
||||||
|
$(DESTDIR)/etc/snap.d/templates/{} \;
|
||||||
|
|
||||||
install: dirs files
|
install: dirs files
|
||||||
|
|||||||
@@ -8,9 +8,65 @@
|
|||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
DEPENDS =
|
# Some, but not all of variables are required. The following list
|
||||||
|
# describes the required variables:
|
||||||
|
#
|
||||||
|
# * URL: The main website of the upstream project
|
||||||
|
# * REPO: The location of the package on the source pacakge
|
||||||
|
# server. This might be one of core, main, dev, or
|
||||||
|
# perhaps others.
|
||||||
|
# * BRIEF: Short description, should be 50 chars or less
|
||||||
|
# * SNAPVER: This is the package version. When a package is
|
||||||
|
# changed, but no changes are made to the source code
|
||||||
|
# this value should be increased. This would include
|
||||||
|
# things like usher being modified, changes to default
|
||||||
|
# configuration files, file permissions, etc.
|
||||||
|
# * ARCHIVE: The default commands that set this variable should
|
||||||
|
# work in most cases, but in some cases it may need
|
||||||
|
# to be modified. This variable should contain the
|
||||||
|
# path to the source of the package (./SRC/filename)
|
||||||
|
# * TYPE: This is probably not really needed due to the
|
||||||
|
# ability of gnu tar to figure it out on its own.
|
||||||
|
# Should probably be removed at some point.
|
||||||
|
# * SRCDIR: This is the name of the source directory after the
|
||||||
|
# package source is extracted. The default command
|
||||||
|
# should in most cases set this automatically.
|
||||||
|
# * PATCHDIR: This directory should be ./SRC/patches and is
|
||||||
|
# required, whether or not patches are used.
|
||||||
|
# * VERSION: This should be set automatically based on the
|
||||||
|
# version string in the source directory and SNAPVER.
|
||||||
|
# The default command here should work in many cases,
|
||||||
|
# but certain packages may need to use a different
|
||||||
|
# method.
|
||||||
|
#
|
||||||
|
# Variables that aren't required:
|
||||||
|
#
|
||||||
|
# * ARCH: This should be populated for packages which contain
|
||||||
|
# compiled binaries. If it is not populated the ARCH
|
||||||
|
# will be set to 'noarch'.
|
||||||
|
# * DEPENDS: If any other packages are required for this package
|
||||||
|
# to function then they need to be listed here,
|
||||||
|
# preferably in alphabetical order.
|
||||||
|
# * BUILDDEPS: Any package beyond packages from the core repo
|
||||||
|
# need to be listed here. The idea is that we
|
||||||
|
# can automate building and testing packages
|
||||||
|
# from clean core systems. The core repo is
|
||||||
|
# intended to include only the base minimum
|
||||||
|
# packages which provide a functional system.
|
||||||
|
# * SRCPKG: By default this is populated automatically with
|
||||||
|
# the name of the package (current directory). If
|
||||||
|
# the source package is used to generate multiple
|
||||||
|
# packages then this variable should contain the
|
||||||
|
# name of the git repo that tracks the source.
|
||||||
|
# * DESC: This is to be used to provide a longer description
|
||||||
|
# of the package.
|
||||||
|
|
||||||
ARCH =
|
ARCH =
|
||||||
|
DEPENDS =
|
||||||
|
BUILDDEPS =
|
||||||
|
SRCPKG =
|
||||||
URL =
|
URL =
|
||||||
|
REPO =
|
||||||
BRIEF =
|
BRIEF =
|
||||||
DESC =
|
DESC =
|
||||||
SNAPVER =
|
SNAPVER =
|
||||||
@@ -50,6 +106,11 @@ $(SRCDIR)/config.log: $(SRCDIR)/configure
|
|||||||
--host=x86_64-snap-linux-gnu \
|
--host=x86_64-snap-linux-gnu \
|
||||||
--target=x86_64-snap-linux-gnu
|
--target=x86_64-snap-linux-gnu
|
||||||
|
|
||||||
|
# binfile should be replaced with a file generated by the
|
||||||
|
# make process. It won't really break anything if not
|
||||||
|
# set to a valid file, but the source make process will
|
||||||
|
# be re-executed even if it isn't necessary
|
||||||
|
|
||||||
$(SRCDIR)/binfile: $(SRCDIR)/config.log
|
$(SRCDIR)/binfile: $(SRCDIR)/config.log
|
||||||
@cd $(SRCDIR) && make
|
@cd $(SRCDIR) && make
|
||||||
|
|
||||||
|
|||||||
@@ -8,17 +8,58 @@
|
|||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
export SHELL := /bin/bash
|
||||||
|
|
||||||
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 to the name of the current working directory
|
||||||
# of the package file. Added for the kernel package
|
# if the package itself has 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
|
||||||
|
|
||||||
|
# If VERSION is not set then we must fail
|
||||||
|
|
||||||
|
ifndef VERSION
|
||||||
|
$(error VERSION is not set)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# This defines the name of the package file unless
|
||||||
|
# it is already specified in the package Makefile
|
||||||
|
|
||||||
|
ifndef PKGFILE
|
||||||
|
PKGFILE := $(PACKAGE)-$(VERSION).snap
|
||||||
|
endif
|
||||||
|
|
||||||
|
# If ARCH is not set we will assume noarch
|
||||||
|
|
||||||
|
ifndef ARCH
|
||||||
|
ARCH := noarch
|
||||||
|
endif
|
||||||
|
|
||||||
|
# SRCPKG defines the git repo name from which the package
|
||||||
|
# is built. In many cases it should be the same as the
|
||||||
|
# package name, but in cases where multiple packages are
|
||||||
|
# built from the same source this is especially relevant.
|
||||||
|
|
||||||
|
ifndef SRCPKG
|
||||||
|
SRCPKG := $(PACKAGE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# URL is required - this should point to the upstream project
|
||||||
|
|
||||||
|
ifndef URL
|
||||||
|
$(error URL is not set)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# REPO is required. This value is used to determine the
|
||||||
|
# location of the package on the package source server
|
||||||
|
|
||||||
|
ifndef REPO
|
||||||
|
$(error REPO is not set)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SNAPINFO = $(SNAPDIR)/snapinfo
|
SNAPINFO = $(SNAPDIR)/snapinfo
|
||||||
@@ -26,45 +67,48 @@ MANIFEST = $(SNAPDIR)/manifest
|
|||||||
USHER = $(SNAPDIR)/usher
|
USHER = $(SNAPDIR)/usher
|
||||||
FILES = $(SNAPDIR)/files.tar.gz
|
FILES = $(SNAPDIR)/files.tar.gz
|
||||||
|
|
||||||
# If multiple packages are pulled from a single source
|
# BRIEF is required.
|
||||||
# then that source needs to be specified in SRCPKG, but
|
|
||||||
# if we find that not to be supplied we're going to
|
|
||||||
# assume that the SRCPKG is the same as the PACKAGE
|
|
||||||
|
|
||||||
ifndef SRCPKG)
|
ifndef BRIEF
|
||||||
SRCPKG := $(PACKAGE)
|
$(error BRIEF is not set)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# The following values must be set in the Makefile for the package
|
$(PKGFILE): $(SNAPINFO) $(FILES)
|
||||||
|
@if [ -f $(PKGFILE) ]; then \
|
||||||
ifndef VERSION
|
rm -v $(PKGFILE); \
|
||||||
$(error VERSION is not set)
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(SNAP): $(SNAPINFO) $(FILES)
|
|
||||||
@if [ -f $(SNAP) ]; then \
|
|
||||||
rm -v $(SNAP); \
|
|
||||||
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)
|
||||||
$(eval BYTES := $(shell gzip -l $(FILES)|tail -1|awk '{print $$2}'))
|
$(eval BYTES := $(shell gzip -l $(FILES)|tail -1|awk '{print $$2}'))
|
||||||
$(eval SHA256MAN := $(shell sha256sum $(MANIFEST)|awk '{print $$1}'))
|
$(eval SHA256MAN := $(shell sha256sum $(MANIFEST)|awk '{print $$1}'))
|
||||||
|
|
||||||
@printf "name: $(PACKAGE)\nversion: $(VERSION)\n" > $(SNAPINFO) && \
|
@fields=( \
|
||||||
printf "depends: $(DEPENDS)\narch: $(ARCH)\n" >> $(SNAPINFO) && \
|
"name: $(PACKAGE)" \
|
||||||
printf "srcpkg: $(SRCPKG)\nbytes: $(BYTES)\n" >> $(SNAPINFO) && \
|
"version: $(VERSION)" \
|
||||||
printf "url: $(URL)\nsha256man: $(SHA256MAN)\n" >> $(SNAPINFO) && \
|
"arch: $(ARCH)" \
|
||||||
printf "brief: $(BRIEF)\ndescription: $(DESC)" >> $(SNAPINFO)
|
"depends: $(DEPENDS)" \
|
||||||
|
"builddeps: $(BUILDDEPS)" \
|
||||||
|
"srcpkg: $(SRCPKG)" \
|
||||||
|
"bytes: $(BYTES)" \
|
||||||
|
"url: $(URL)" \
|
||||||
|
"repo: $(REPO)" \
|
||||||
|
"sha256man: $(SHA256MAN)" \
|
||||||
|
"brief: $(BRIEF)" \
|
||||||
|
"description: $(DESC)" \
|
||||||
|
) && \
|
||||||
|
for field in "$${fields[@]}"; do \
|
||||||
|
printf "$$field\n"; \
|
||||||
|
done > $(SNAPINFO)
|
||||||
|
|
||||||
$(MANIFEST): $(FILES)
|
$(MANIFEST): $(FILES)
|
||||||
@>$(MANIFEST)
|
@>$(MANIFEST)
|
||||||
@@ -106,10 +150,13 @@ $(FILES): $(ROOT)
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
@if [ -d $(ROOT)/usr/share/info ]; then \
|
@if [ -d $(ROOT)/usr/share/info ]; then \
|
||||||
find $(ROOT)/usr/share/info -type f -name \*.info| \
|
find $(ROOT)/usr/share/info -name '*.info' -o \
|
||||||
while read -r file; do \
|
-name '*.info-[0-9]*'|while read -r file; do \
|
||||||
gzip $$file; \
|
gzip $$file; \
|
||||||
done; \
|
done; \
|
||||||
|
if [ -f $(ROOT)/usr/share/info/dir ]; then \
|
||||||
|
rm -v $(ROOT)/usr/share/info/dir; \
|
||||||
|
fi; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@find $(ROOT) -type f | while read -r file; do \
|
@find $(ROOT) -type f | while read -r file; do \
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
298
SRC/snap/Snap.pm
298
SRC/snap/Snap.pm
@@ -7,12 +7,11 @@ 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( sha1_hex sha256_hex );
|
||||||
use POSIX;
|
use POSIX;
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
use parent 'Exporter';
|
use parent 'Exporter';
|
||||||
our @EXPORT = qw(
|
our @EXPORT = qw(
|
||||||
@@ -21,6 +20,7 @@ our @EXPORT = qw(
|
|||||||
genpkg
|
genpkg
|
||||||
httpget
|
httpget
|
||||||
human
|
human
|
||||||
|
kernver
|
||||||
list
|
list
|
||||||
listfiles
|
listfiles
|
||||||
virtfs
|
virtfs
|
||||||
@@ -30,6 +30,7 @@ our @EXPORT = qw(
|
|||||||
sha
|
sha
|
||||||
sha256
|
sha256
|
||||||
target
|
target
|
||||||
|
templates
|
||||||
termsize
|
termsize
|
||||||
vercmp
|
vercmp
|
||||||
);
|
);
|
||||||
@@ -89,7 +90,7 @@ use constant VERFILE => eval {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
use constant {
|
use constant {
|
||||||
VERSION => '0.7',
|
VERSION => '0.13',
|
||||||
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',
|
||||||
@@ -105,6 +106,17 @@ use constant SNAPVER => eval {
|
|||||||
|
|
||||||
return( $version );
|
return( $version );
|
||||||
};
|
};
|
||||||
|
use constant LOCKFILE => TARGET . '/.snap';
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
#
|
||||||
|
# Verify TARGET is a valid directory
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
if ( TARGET && ! -d TARGET ) {
|
||||||
|
Snap->error( -1, TARGET . ": invalid target directory" );
|
||||||
|
}
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
#
|
#
|
||||||
@@ -121,7 +133,9 @@ $0 =~ s/.*\///;
|
|||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
$SIG{INT} = sub{
|
$SIG{INT} = sub{
|
||||||
|
if ( TARGET ) {
|
||||||
virtfs( 'umount' );
|
virtfs( 'umount' );
|
||||||
|
}
|
||||||
|
|
||||||
print "\e[?25h\n";
|
print "\e[?25h\n";
|
||||||
|
|
||||||
@@ -170,9 +184,9 @@ sub chkyes {
|
|||||||
chomp( $yes );
|
chomp( $yes );
|
||||||
|
|
||||||
if ( lc( $yes ) eq 'n' ){
|
if ( lc( $yes ) eq 'n' ){
|
||||||
print STDERR "\nAborting!\n\n";
|
print STDERR "\nAborting!\n";
|
||||||
|
|
||||||
exit 1;
|
exit( 1 );
|
||||||
}
|
}
|
||||||
elsif ( lc( $yes ne 'y' ) ){
|
elsif ( lc( $yes ne 'y' ) ){
|
||||||
print "Answer 'y' or 'n': ";
|
print "Answer 'y' or 'n': ";
|
||||||
@@ -182,6 +196,36 @@ sub chkyes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### dirempty() #############################################
|
||||||
|
#
|
||||||
|
# A simple test for an empty directory. The default $empty
|
||||||
|
# is 1 (meaning there are no files in the directory), and
|
||||||
|
# $empty is set to 0 if any files are found.
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
sub dirempty {
|
||||||
|
my $class = shift;
|
||||||
|
my $dir = shift;
|
||||||
|
my $empty = 1;
|
||||||
|
|
||||||
|
if ( ! -d $dir ) {
|
||||||
|
Snap->error( -1, "dirempty(): $dir: Invalid directory" );
|
||||||
|
}
|
||||||
|
|
||||||
|
opendir( my $dh, $dir ) || Snap->error( int( $! ), "dirempty(): $!" );
|
||||||
|
|
||||||
|
while ( readdir( $dh ) ) {
|
||||||
|
if ( $_ ne '.' && $_ ne '..' ) {
|
||||||
|
$empty = 0;
|
||||||
|
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( $empty );
|
||||||
|
}
|
||||||
|
|
||||||
### error() ################################################
|
### error() ################################################
|
||||||
#
|
#
|
||||||
# All errors should be sent here. This sub takes a status
|
# All errors should be sent here. This sub takes a status
|
||||||
@@ -234,7 +278,7 @@ sub error {
|
|||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
sub genpkg{
|
sub genpkg{
|
||||||
my $pkgname = shift;
|
my $pkgname = shift || Snap->error( -1, "genpkg(): pkgname missing" );
|
||||||
my $skelfile = '/usr/share/snap/Makefile.skel';
|
my $skelfile = '/usr/share/snap/Makefile.skel';
|
||||||
my $snapreadme = "This is the directory where the manifest, snapinfo,\n"
|
my $snapreadme = "This is the directory where the manifest, snapinfo,\n"
|
||||||
. "and files.tar.gz files will be created. It is also\n"
|
. "and files.tar.gz files will be created. It is also\n"
|
||||||
@@ -293,7 +337,9 @@ sub httpget {
|
|||||||
PeerPort => 'http(80)',
|
PeerPort => 'http(80)',
|
||||||
Proto => 'tcp'
|
Proto => 'tcp'
|
||||||
) || Snap->error( int( $! ), "IO::Socket::Inet->new(): $!" );
|
) || Snap->error( int( $! ), "IO::Socket::Inet->new(): $!" );
|
||||||
my $bytes;
|
my $bytes = 0;
|
||||||
|
my @wheel = qw( - \ | / );
|
||||||
|
my $p = 0;
|
||||||
|
|
||||||
local $| = 1;
|
local $| = 1;
|
||||||
|
|
||||||
@@ -314,7 +360,7 @@ sub httpget {
|
|||||||
|
|
||||||
while ( <$sock> ) {
|
while ( <$sock> ) {
|
||||||
if ( $dest ) {
|
if ( $dest ) {
|
||||||
$bytes = ( stat( $dest ) )[7] || 0;
|
$bytes += length( $_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $httpget{'dflag'} ) {
|
if ( ! $httpget{'dflag'} ) {
|
||||||
@@ -365,24 +411,25 @@ sub httpget {
|
|||||||
$httpget{'length'} * 100 );
|
$httpget{'length'} * 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Retrieving $filename [";
|
printf( "%-50.50s [%-20s] %s\r",
|
||||||
|
" $wheel[$p] Downloading $filename",
|
||||||
|
'*' x int( $httpget{'pct'} / 5 ),
|
||||||
|
"$httpget{'pct'}%" );
|
||||||
|
|
||||||
for ( my $i = 0; $i < 20; $i++ ){
|
if ( $p >= $#wheel ) {
|
||||||
if ( $i < $httpget{'pct'} / 5 ) {
|
$p = 0;
|
||||||
print '*';
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print ' ';
|
$p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "] $httpget{'pct'}%\r";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $dest ) {
|
if ( $dest ) {
|
||||||
print "Retrieving $filename [********************] 100%"
|
printf( "%-50.50s [%-20s] %s\e[?25h\n",
|
||||||
. "\e[?25h\n";
|
" * Downloaded $filename",
|
||||||
|
'*' x 20,
|
||||||
|
'100%' );
|
||||||
|
|
||||||
close( DEST );
|
close( DEST );
|
||||||
}
|
}
|
||||||
@@ -433,7 +480,50 @@ sub ismountpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub issnap {
|
||||||
|
my $class = shift;
|
||||||
|
my $file = shift;
|
||||||
|
my $lines = 0;
|
||||||
|
my $snapinfo = 0;
|
||||||
|
my $name = 0;
|
||||||
|
my $version = 0;
|
||||||
|
my $issnap = 0;
|
||||||
|
|
||||||
|
open( FILE, "<$file" ) || Snap->error( -1, "open(): $file: $!" );
|
||||||
|
|
||||||
|
while ( <FILE> ) {
|
||||||
|
if ( substr( $_, 0, 9 ) eq 'snapinfo/' ) {
|
||||||
|
$snapinfo++;
|
||||||
|
}
|
||||||
|
elsif ( substr( $_, 0, 5 ) eq 'name:' ) {
|
||||||
|
$name++;
|
||||||
|
}
|
||||||
|
elsif ( substr( $_, 0, 8 ) eq 'version:' ) {
|
||||||
|
$version++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines++;
|
||||||
|
|
||||||
|
if ( $lines >= 12 ) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close( FILE ) || Snap->error( -1, "close(): $file: $!" );
|
||||||
|
|
||||||
|
if ( $snapinfo && $name && $version ) {
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub kernver {
|
||||||
|
return( ( uname() )[2] );
|
||||||
|
}
|
||||||
|
|
||||||
sub list {
|
sub list {
|
||||||
|
my $listpackages = shift;
|
||||||
my $packages = {};
|
my $packages = {};
|
||||||
my $package = {};
|
my $package = {};
|
||||||
|
|
||||||
@@ -441,7 +531,8 @@ sub list {
|
|||||||
. INSTDIR . ": $!" );
|
. INSTDIR . ": $!" );
|
||||||
|
|
||||||
foreach my $dir ( sort { $a cmp $b } readdir( DIR ) ) {
|
foreach my $dir ( sort { $a cmp $b } readdir( DIR ) ) {
|
||||||
if ( $dir =~ /^\.{1,2}$/ || ! -f INSTDIR . "/$dir/snapinfo" ) {
|
if ( $dir =~ /^\.{1,2}$/ || ! -f INSTDIR . "/$dir/snapinfo" ||
|
||||||
|
$listpackages->[0] && ! grep( $dir =~ /$_/, @$listpackages ) ) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,6 +590,13 @@ sub listfiles {
|
|||||||
return( $listfiles );
|
return( $listfiles );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub 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" );
|
||||||
|
}
|
||||||
|
|
||||||
sub mkdirp{
|
sub mkdirp{
|
||||||
( my $dir = shift ) =~ s/\/^//;
|
( my $dir = shift ) =~ s/\/^//;
|
||||||
my $mode = shift;
|
my $mode = shift;
|
||||||
@@ -515,37 +613,60 @@ sub mkdirp{
|
|||||||
|
|
||||||
### readconf() #############################################
|
### readconf() #############################################
|
||||||
#
|
#
|
||||||
# reads CONFFILE and builds a data structure with the
|
# reads INI style files and builds a data structure with the
|
||||||
# parsed values. Only the 'sources' section is treated
|
# parsed values.
|
||||||
# in a special way - it is pushed into an array to maintain
|
#
|
||||||
# the order. This allows us to give priority to the topmost
|
# The config file can 'include' additional directories.
|
||||||
# repositories
|
# Files in these directories will be parsed and added to
|
||||||
|
# the the data structure.
|
||||||
|
#
|
||||||
|
# Files ending in .conf will be parsed into the root of the
|
||||||
|
# data structure while .spt (snap package template) files
|
||||||
|
# will be stored in 'templates'
|
||||||
#
|
#
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
sub readconf {
|
sub readconf {
|
||||||
|
my $conffile = shift || CONFFILE;
|
||||||
|
my $data = shift || {};
|
||||||
my $section = '';
|
my $section = '';
|
||||||
my $data = {};
|
|
||||||
my $line = 0;
|
my $line = 0;
|
||||||
|
my $type;
|
||||||
|
|
||||||
open( FILE, "<", CONFFILE ) || Snap->error( int( $! ),
|
open( my $fh, "<", $conffile ) || Snap->error( int( $! ),
|
||||||
"open: " . CONFFILE . ": $!\n" );
|
"open(): $conffile: $!\n" );
|
||||||
|
|
||||||
while ( <FILE> ) {
|
while ( <$fh> ) {
|
||||||
chomp( $_ );
|
chomp( $_ );
|
||||||
|
|
||||||
if ( $_ =~ /^\s*#/ ) {
|
if ( $_ =~ /^\s*#/ || $_ =~ /^$/ ) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
elsif ( $_ =~ /\s*include\s+(.*)$/ ) {
|
||||||
|
foreach my $dir ( split( ' ', $1 ) ) {
|
||||||
|
opendir( my $dh, $dir ) ||
|
||||||
|
Snap->error( int( $! ),
|
||||||
|
"opendir(): $dir: $!" );
|
||||||
|
|
||||||
|
while ( my $file = readdir( $dh ) ) {
|
||||||
|
if ( -f "$dir/$file" ) {
|
||||||
|
|
||||||
|
readconf( "$dir/$file", $data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir( $dh ) || Snap->error( int( $! ),
|
||||||
|
"closedir(): $dir: $!" );
|
||||||
|
}
|
||||||
|
}
|
||||||
elsif ( $_ =~ /\s*\[(\S+)\]\s*/ ) {
|
elsif ( $_ =~ /\s*\[(\S+)\]\s*/ ) {
|
||||||
$section = $1;
|
$section = $1;
|
||||||
|
|
||||||
if ( $section eq 'sources' ) {
|
if ( $section eq 'sources' && ! $data->{$section} ) {
|
||||||
$data->{$section} = [];
|
$data->{$section} = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $section eq 'sources' &&
|
elsif ( $section eq 'sources' ) {
|
||||||
$_ =~ /(\S+)\s*=\s*(.*)$/ ) {
|
|
||||||
push( @{$data->{$section}}, $_ );
|
push( @{$data->{$section}}, $_ );
|
||||||
}
|
}
|
||||||
elsif ( $_ =~ /(\S+)\s*=\s*(.*)$/ ) {
|
elsif ( $_ =~ /(\S+)\s*=\s*(.*)$/ ) {
|
||||||
@@ -553,7 +674,7 @@ sub readconf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close( FILE );
|
close( $fh );
|
||||||
|
|
||||||
return( $data );
|
return( $data );
|
||||||
}
|
}
|
||||||
@@ -596,35 +717,6 @@ sub setup {
|
|||||||
$chkfails++;
|
$chkfails++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $chkfails ) {
|
|
||||||
print "The following files/directories are missing: \n\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $target ) {
|
|
||||||
print " " . TARGET . "\n";
|
|
||||||
}
|
|
||||||
if ( $snapdir ) {
|
|
||||||
print " " . SNAPDIR . "\n";
|
|
||||||
}
|
|
||||||
if ( $pkgdir ) {
|
|
||||||
print " " . PKGDIR . "\n";
|
|
||||||
}
|
|
||||||
if ( $instdir ) {
|
|
||||||
print " " . INSTDIR . "\n";
|
|
||||||
}
|
|
||||||
if ( $srcdir ) {
|
|
||||||
print " " . SRCDIR . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
print "Create files/directories? (y/n): ";
|
|
||||||
|
|
||||||
chkyes();
|
|
||||||
|
|
||||||
if ( $target ) {
|
if ( $target ) {
|
||||||
mkdir( TARGET, 0755 ) || Snap->error( int( $! ), "mkdir: $!" );
|
mkdir( TARGET, 0755 ) || Snap->error( int( $! ), "mkdir: $!" );
|
||||||
}
|
}
|
||||||
@@ -650,7 +742,14 @@ sub setup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### sha() ###############################################
|
||||||
|
#
|
||||||
|
# This sub returns a hex sha hash of a supplied file
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
sub sha {
|
sub sha {
|
||||||
|
my $class = shift;
|
||||||
my $file = shift;
|
my $file = shift;
|
||||||
my $digest = eval {
|
my $digest = eval {
|
||||||
Digest::SHA->new( 1 )->addfile( $file );
|
Digest::SHA->new( 1 )->addfile( $file );
|
||||||
@@ -675,6 +774,53 @@ sub sha256 {
|
|||||||
return( $digest->hexdigest );
|
return( $digest->hexdigest );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub templates {
|
||||||
|
my $conf = shift;
|
||||||
|
my $templatedir = $conf->{'snapinstall'}{'templatedir'};
|
||||||
|
my $unsorted = [];
|
||||||
|
my $templates = {};
|
||||||
|
|
||||||
|
opendir( my $dh, $templatedir ) ||
|
||||||
|
Snap->error( int( $! ), "templates(): $!" );
|
||||||
|
|
||||||
|
while ( my $template = readdir( $dh ) ) {
|
||||||
|
if ( $template eq '.' || $template eq '..' ) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
elsif ( ! -f "$templatedir/$template/packages" ) {
|
||||||
|
Snap->error( 0, "Template '$template' has"
|
||||||
|
. " no packages" );
|
||||||
|
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$templates->{$template}{'packages'} = [];
|
||||||
|
|
||||||
|
open( my $fh, "$templatedir/$template/packages" ) ||
|
||||||
|
Snap->error( int( $! ), "templates(): $!" );
|
||||||
|
|
||||||
|
while ( readline( $fh ) ) {
|
||||||
|
chomp();
|
||||||
|
|
||||||
|
if ( $_ =~ /^\s*#/ || $_ =~ /^$/ ) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
push( @{$templates->{$template}{'packages'}}, $_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
close( $fh );
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir( $dh );
|
||||||
|
|
||||||
|
foreach ( sort { $a cmp $b }( @$unsorted ) ) {
|
||||||
|
push( @$templates, $_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( $templates );
|
||||||
|
}
|
||||||
|
|
||||||
sub termsize {
|
sub termsize {
|
||||||
my $row = 24;
|
my $row = 24;
|
||||||
my $col = 80;
|
my $col = 80;
|
||||||
@@ -716,7 +862,7 @@ sub termsize {
|
|||||||
waitpid( $pid, 0 );
|
waitpid( $pid, 0 );
|
||||||
$stat = $? >> 8;
|
$stat = $? >> 8;
|
||||||
|
|
||||||
if ( $stdout =~ /(\d+)\s+(\d+)/ ) {
|
if ( $stdout && $stdout =~ /(\d+)\s+(\d+)/ ) {
|
||||||
$row = $1;
|
$row = $1;
|
||||||
$col = $2;
|
$col = $2;
|
||||||
}
|
}
|
||||||
@@ -724,6 +870,13 @@ sub termsize {
|
|||||||
return( { row => $row, col => $col } );
|
return( { row => $row, col => $col } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub unlock {
|
||||||
|
if ( -f LOCKFILE ) {
|
||||||
|
unlink( LOCKFILE ) || Snap->error( int( $! ), "unlink(): "
|
||||||
|
. LOCKFILE . ": Unable to remove lock file" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
### vercmp() ###############################################
|
### vercmp() ###############################################
|
||||||
#
|
#
|
||||||
# This subroutine was basically copied verbatim from the
|
# This subroutine was basically copied verbatim from the
|
||||||
@@ -800,6 +953,18 @@ sub vercmp {
|
|||||||
@A <=> @B;
|
@A <=> @B;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### virtfs() ###############################################
|
||||||
|
#
|
||||||
|
# Need to try and figure out a solution for user installs
|
||||||
|
#
|
||||||
|
# The user may not be able to mount the virt filesystems,
|
||||||
|
# so perhaps it could do some kind of linking instead?
|
||||||
|
#
|
||||||
|
# Also remember you might want to move chroot out of usher
|
||||||
|
# and into here! We could also try to do fakechroot as well
|
||||||
|
#
|
||||||
|
############################################################
|
||||||
|
|
||||||
sub virtfs {
|
sub virtfs {
|
||||||
my $command = shift;
|
my $command = shift;
|
||||||
my $virtfs = {
|
my $virtfs = {
|
||||||
@@ -820,7 +985,7 @@ sub virtfs {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( ! TARGET ) {
|
if ( $> || ! TARGET ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,7 +997,8 @@ sub virtfs {
|
|||||||
my $stat = 0;
|
my $stat = 0;
|
||||||
my $pid;
|
my $pid;
|
||||||
|
|
||||||
if ( ! -f $virtfs->{$fs}{'dir'} ) {
|
|
||||||
|
if ( ! -d $virtfs->{$fs}{'dir'} ) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Compress::Zlib;
|
use Compress::Zlib;
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
use parent 'Snap';
|
use parent 'Snap';
|
||||||
|
|
||||||
|
|||||||
286
SRC/snap/snap
286
SRC/snap/snap
@@ -4,18 +4,8 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Snap;
|
use Snap;
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
############################################################
|
my $command = shift( @ARGV ) || '';
|
||||||
#
|
|
||||||
# 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 $conf = readconf();
|
||||||
my $commands = Snap::Commands->new();
|
my $commands = Snap::Commands->new();
|
||||||
my $sources = Snap::Sources->new( $conf->{'sources'} );
|
my $sources = Snap::Sources->new( $conf->{'sources'} );
|
||||||
@@ -23,9 +13,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' ) {
|
||||||
@@ -51,29 +47,45 @@ elsif ( $command eq 'files' ) {
|
|||||||
};
|
};
|
||||||
my $string = "@ARGV";
|
my $string = "@ARGV";
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
foreach my $arg ( @ARGV ) {
|
foreach my $arg ( @ARGV ) {
|
||||||
my $package = Snap::Package->new( $arg );
|
my $package = Snap::Package->new( $arg );
|
||||||
|
|
||||||
$package->files( $opts );
|
$package->files( $opts );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'genpkg' ) {
|
||||||
|
if ( ! @ARGV ) {
|
||||||
|
Snap->error( -1, "Failed to provide package name" );
|
||||||
|
}
|
||||||
|
|
||||||
print "\n";
|
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' ) {
|
||||||
|
my $cnt = 0;
|
||||||
|
|
||||||
print "\n";
|
if ( ! @ARGV ) {
|
||||||
|
Snap->error( 0, "'$command': You must supply an argument" );
|
||||||
|
|
||||||
|
$commands->commandhelp( 'info' );
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $arg ( @ARGV ) {
|
foreach my $arg ( @ARGV ) {
|
||||||
my $package = Snap::Package->new( $arg );
|
my $package = Snap::Package->new( $arg );
|
||||||
|
|
||||||
|
if ( $cnt ) {
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
$package->printself();
|
$package->printself();
|
||||||
|
|
||||||
print "\n";
|
$cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'install' ) {
|
elsif ( $command eq 'install' ) {
|
||||||
@@ -104,6 +116,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;
|
||||||
@@ -112,8 +126,6 @@ elsif ( $command eq 'install' ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
$sources->readpkgs();
|
$sources->readpkgs();
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
@@ -139,8 +151,8 @@ elsif ( $command eq 'install' ) {
|
|||||||
my $package;
|
my $package;
|
||||||
|
|
||||||
if ( ! -f $arg ) {
|
if ( ! -f $arg ) {
|
||||||
my ( $name, $version ) = split( /(((<|>)=?|=)(.*))/,
|
my ( $name, $version ) =
|
||||||
$arg );
|
split( /(((<|>)=?|=)(.*))/, $arg );
|
||||||
$opts->{'name'} = $name;
|
$opts->{'name'} = $name;
|
||||||
$opts->{'version'} = $version;
|
$opts->{'version'} = $version;
|
||||||
|
|
||||||
@@ -151,7 +163,7 @@ elsif ( $command eq 'install' ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $package ) {
|
if ( ! $package ) {
|
||||||
Snap->error( -1, "$arg: No such package found" );
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $opts->{'nodeps'} ) {
|
if ( ! $opts->{'nodeps'} ) {
|
||||||
@@ -164,21 +176,10 @@ elsif ( $command eq 'install' ) {
|
|||||||
print "Ignoring dependencies for $package->{'name'}\n";
|
print "Ignoring dependencies for $package->{'name'}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! grep( $_->{'name'} eq $package->{'name'},
|
||||||
|
@$packages ) ) {
|
||||||
push( @$packages, $package );
|
push( @$packages, $package );
|
||||||
}
|
}
|
||||||
|
|
||||||
####################################################
|
|
||||||
#
|
|
||||||
# Here we iterate through all installed packages
|
|
||||||
# and add their file lists. This will later be
|
|
||||||
# checked against for conflicts.
|
|
||||||
#
|
|
||||||
####################################################
|
|
||||||
|
|
||||||
foreach my $pkgname ( sort { $sources->{'installed'}{$a}{'name'} cmp
|
|
||||||
$sources->{'installed'}{$b}{'name'} }
|
|
||||||
keys( %{$sources->{'installed'}} ) ) {
|
|
||||||
$sources->{'installed'}{$pkgname}->files( { quiet => 1 } );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( my $i = 0; $i <= $#$packages; $i++ ) {
|
for ( my $i = 0; $i <= $#$packages; $i++ ) {
|
||||||
@@ -301,7 +302,9 @@ elsif ( $command eq 'install' ) {
|
|||||||
. ". Continue? (y/n): ";
|
. ". Continue? (y/n): ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! $opts->{'yes'} ) {
|
||||||
chkyes();
|
chkyes();
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $package ( @$packages ) {
|
foreach my $package ( @$packages ) {
|
||||||
if ( ! $virtfs ) {
|
if ( ! $virtfs ) {
|
||||||
@@ -316,26 +319,71 @@ elsif ( $command eq 'install' ) {
|
|||||||
if ( $virtfs ) {
|
if ( $virtfs ) {
|
||||||
virtfs( 'umount' );
|
virtfs( 'umount' );
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'list' ) {
|
elsif ( $command eq 'list' ) {
|
||||||
my $packages = list();
|
my $opts = {
|
||||||
|
verbose => eval {
|
||||||
|
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
||||||
|
if ( $ARGV[$i] eq '-v' ) {
|
||||||
|
splice( @ARGV, $i, 1 );
|
||||||
|
|
||||||
print "\n";
|
return( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
my $packages = list( \@ARGV );
|
||||||
|
|
||||||
foreach my $package ( sort( keys( %$packages ) ) ) {
|
foreach my $package ( sort( keys( %$packages ) ) ) {
|
||||||
|
if ( $opts->{'verbose'} ) {
|
||||||
|
print "\n";
|
||||||
|
|
||||||
|
$packages->{$package}->printself();
|
||||||
|
}
|
||||||
|
else {
|
||||||
$packages->{$package}->printbrief();
|
$packages->{$package}->printbrief();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print "\n";
|
if ( ! keys( %$packages ) ) {
|
||||||
|
print "No installed packages found matching '@ARGV'\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'provides' ) {
|
||||||
|
( my $string = $ARGV[0] ) =~ s/^\/*/\//;
|
||||||
|
my $len = length( $string );
|
||||||
|
|
||||||
|
$sources->readpkgs();
|
||||||
|
|
||||||
|
foreach my $pkgname ( sort( keys( %{$sources->{'installed'}} ) ) ) {
|
||||||
|
my $package = $sources->{'installed'}{$pkgname};
|
||||||
|
|
||||||
|
$package->files( { quiet => 1 } );
|
||||||
|
|
||||||
|
foreach my $file ( @{$package->{'files'}} ) {
|
||||||
|
if ( substr( "/$file", -$len, $len ) eq "$string" ) {
|
||||||
|
print "$pkgname\n";
|
||||||
|
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'purge' ) {
|
||||||
|
print "Not yet implemented\n";
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'rebuild' ) {
|
||||||
|
print "Not yet implemented\n";
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'refresh' ) {
|
elsif ( $command eq 'refresh' ) {
|
||||||
print "\n";
|
setup();
|
||||||
|
|
||||||
$sources->refresh();
|
$sources->refresh();
|
||||||
|
|
||||||
print "\n";
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
foreach my $source ( @{$conf->{'sources'}} ) {
|
foreach my $source ( @{$conf->{'sources'}} ) {
|
||||||
@@ -348,6 +396,7 @@ elsif ( $command eq 'refresh' ) {
|
|||||||
}
|
}
|
||||||
elsif ( $command eq 'reinstall' ) {
|
elsif ( $command eq 'reinstall' ) {
|
||||||
my $opts = {
|
my $opts = {
|
||||||
|
quiet => 1,
|
||||||
yes => eval {
|
yes => eval {
|
||||||
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
||||||
if ( $ARGV[$i] eq '-y' ) {
|
if ( $ARGV[$i] eq '-y' ) {
|
||||||
@@ -358,13 +407,15 @@ elsif ( $command eq 'reinstall' ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
my $termsize = Snap->termsize();
|
||||||
my $packages = [];
|
my $packages = [];
|
||||||
my $virtfs = 0;
|
my $virtfs = 0;
|
||||||
|
my $cnt = 0;
|
||||||
|
|
||||||
|
setup();
|
||||||
|
|
||||||
$sources->readpkgs();
|
$sources->readpkgs();
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
foreach my $pkgname ( @ARGV ) {
|
foreach my $pkgname ( @ARGV ) {
|
||||||
my $package;
|
my $package;
|
||||||
|
|
||||||
@@ -372,6 +423,10 @@ elsif ( $command eq 'reinstall' ) {
|
|||||||
$package = Snap::Package->new( $pkgname );
|
$package = Snap::Package->new( $pkgname );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if ( ! $sources->{'installed'}{$pkgname} ) {
|
||||||
|
Snap->error( -1, "$pkgname not installed" );
|
||||||
|
}
|
||||||
|
|
||||||
$package = $sources->{'installed'}{$pkgname};
|
$package = $sources->{'installed'}{$pkgname};
|
||||||
$package = $sources->search( {
|
$package = $sources->search( {
|
||||||
name => $package->{'name'},
|
name => $package->{'name'},
|
||||||
@@ -380,12 +435,6 @@ elsif ( $command eq 'reinstall' ) {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $package ) {
|
|
||||||
print STDERR "Package '$pkgname' not installed\n";
|
|
||||||
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $package->{'path'} =~ /https*:\/\// ) {
|
if ( $package->{'path'} =~ /https*:\/\// ) {
|
||||||
( my $filename = $package->{'path'} ) =~ s/.*\///;
|
( my $filename = $package->{'path'} ) =~ s/.*\///;
|
||||||
|
|
||||||
@@ -397,18 +446,21 @@ elsif ( $command eq 'reinstall' ) {
|
|||||||
$package->{'path'} = Snap->PKGDIR . "/$filename";
|
$package->{'path'} = Snap->PKGDIR . "/$filename";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$package->files( $opts );
|
||||||
|
|
||||||
|
if ( ! grep( $_->{'name'} eq $package->{'name'},
|
||||||
|
@$packages ) ) {
|
||||||
push( @$packages, $package );
|
push( @$packages, $package );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
foreach my $package ( @$packages ) {
|
|
||||||
my $termsize = Snap->termsize();
|
|
||||||
my $cnt = 0;
|
|
||||||
|
|
||||||
foreach my $package ( sort { $a->{'name'} cmp $b->{'name'} }
|
foreach my $package ( sort { $a->{'name'} cmp $b->{'name'} }
|
||||||
( @$packages ) ) {
|
( @$packages ) ) {
|
||||||
if ( ! $cnt ) {
|
if ( ! $cnt ) {
|
||||||
print "The following packages will be"
|
print "The following packages will be"
|
||||||
. " reinstalled:\n ";
|
. " reinstalled:\n ";
|
||||||
|
|
||||||
|
$cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $termsize->{'col'} - ( length(
|
if ( $termsize->{'col'} - ( length(
|
||||||
@@ -421,13 +473,13 @@ elsif ( $command eq 'reinstall' ) {
|
|||||||
print "$package->{'name'} ";
|
print "$package->{'name'} ";
|
||||||
|
|
||||||
$termsize->{'col'} -= length( $package->{'name'} ) + 1;
|
$termsize->{'col'} -= length( $package->{'name'} ) + 1;
|
||||||
$cnt++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n\nContinue? (y/n): ";
|
print "\n\nContinue? (y/n): ";
|
||||||
|
|
||||||
|
if ( ! $opts->{'yes'} ) {
|
||||||
chkyes();
|
chkyes();
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $package ( @$packages ) {
|
foreach my $package ( @$packages ) {
|
||||||
if ( ! $virtfs ) {
|
if ( ! $virtfs ) {
|
||||||
@@ -436,12 +488,10 @@ elsif ( $command eq 'reinstall' ) {
|
|||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
$package->install();
|
$package->install( $sources );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtfs( 'umount' );
|
virtfs( 'umount' );
|
||||||
|
|
||||||
print "\n";
|
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'remove' ) {
|
elsif ( $command eq 'remove' ) {
|
||||||
my $opts = {
|
my $opts = {
|
||||||
@@ -470,8 +520,7 @@ elsif ( $command eq 'remove' ) {
|
|||||||
my $bytes = 0;
|
my $bytes = 0;
|
||||||
my $cnt = 0;
|
my $cnt = 0;
|
||||||
my $termsize = Snap->termsize();
|
my $termsize = Snap->termsize();
|
||||||
|
my $virtfs = 0;
|
||||||
print "\n";
|
|
||||||
|
|
||||||
$sources->readpkgs();
|
$sources->readpkgs();
|
||||||
|
|
||||||
@@ -503,7 +552,13 @@ elsif ( $command eq 'remove' ) {
|
|||||||
foreach my $package ( sort { $a->{'name'} cmp $b->{'name'} }
|
foreach my $package ( sort { $a->{'name'} cmp $b->{'name'} }
|
||||||
( @$packages ) ) {
|
( @$packages ) ) {
|
||||||
if ( ! $cnt ) {
|
if ( ! $cnt ) {
|
||||||
print "\nThe following packages will be removed:\n ";
|
print "\nThe following packages will be removed";
|
||||||
|
|
||||||
|
if ( Snap->TARGET ) {
|
||||||
|
print " from " . Snap->TARGET;
|
||||||
|
}
|
||||||
|
|
||||||
|
print ":\n ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $termsize->{'col'} - ( length(
|
if ( $termsize->{'col'} - ( length(
|
||||||
@@ -524,21 +579,35 @@ elsif ( $command eq 'remove' ) {
|
|||||||
print "\n\n" . human( $bytes ) . " will be recovered."
|
print "\n\n" . human( $bytes ) . " will be recovered."
|
||||||
. " Continue? (y/n): ";
|
. " Continue? (y/n): ";
|
||||||
|
|
||||||
|
if ( ! $opts->{'yes'} ) {
|
||||||
chkyes();
|
chkyes();
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
foreach my $package ( @$packages ) {
|
|
||||||
$package->remove( $sources );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
|
$cnt = 0;
|
||||||
|
|
||||||
|
foreach my $package ( @$packages ) {
|
||||||
|
if ( ! $virtfs ) {
|
||||||
|
$virtfs = virtfs( 'mount' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $cnt ) {
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$package->remove( $sources );
|
||||||
|
|
||||||
|
$cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $virtfs ) {
|
||||||
|
virtfs( 'umount' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'revdep' ) {
|
elsif ( $command eq 'revdep' ) {
|
||||||
my $revdeps = [];
|
my $revdeps = [];
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
$sources->readpkgs();
|
$sources->readpkgs();
|
||||||
|
|
||||||
foreach my $arg ( @ARGV ) {
|
foreach my $arg ( @ARGV ) {
|
||||||
@@ -554,8 +623,6 @@ elsif ( $command eq 'revdep' ) {
|
|||||||
if ( ! @$revdeps ) {
|
if ( ! @$revdeps ) {
|
||||||
print "No reverse dependencies found\n";
|
print "No reverse dependencies found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'search' ) {
|
elsif ( $command eq 'search' ) {
|
||||||
my @attribs = qw( name version depends source repo description );
|
my @attribs = qw( name version depends source repo description );
|
||||||
@@ -600,36 +667,93 @@ elsif ( $command eq 'search' ) {
|
|||||||
( $opts->{'string'} = $string ) =~ s/^ *| *$//g;
|
( $opts->{'string'} = $string ) =~ s/^ *| *$//g;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
|
||||||
|
|
||||||
if ( ! $sources->readpkgs() ) {
|
if ( ! $sources->readpkgs() ) {
|
||||||
exit -1;
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $sources->search( $opts ) ) {
|
if ( ! $sources->search( $opts ) ) {
|
||||||
exit -1;
|
exit( -1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'source' ) {
|
||||||
|
my $opts = {
|
||||||
|
latest => eval {
|
||||||
|
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
||||||
|
if ( $ARGV[$i] eq '-l' ) {
|
||||||
|
splice( @ARGV, $i, 1 );
|
||||||
|
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
quiet => 1
|
||||||
|
};
|
||||||
|
$sources->readpkgs();
|
||||||
|
|
||||||
|
if ( ! @ARGV ) {
|
||||||
|
Snap->error( 0, "'$command': You must supply an argument" );
|
||||||
|
|
||||||
|
$commands->commandhelp( 'source' );
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n";
|
foreach my $arg ( @ARGV ) {
|
||||||
|
my $package;# = Snap::Package->new( $arg );
|
||||||
|
|
||||||
|
if ( $sources->{'installed'}{$arg} && ! $opts->{'latest'} ) {
|
||||||
|
$package = $sources->{'installed'}{$arg};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my ( $name, $version ) =
|
||||||
|
split( /(((<|>)=?|=)(.*))/, $arg );
|
||||||
|
$opts->{'name'} = $name;
|
||||||
|
$opts->{'version'} = $version;
|
||||||
|
$package = $sources->search( $opts );
|
||||||
|
}
|
||||||
|
|
||||||
|
$package->source();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif ( $command eq 'upgrade' ) {
|
||||||
|
print "Not yet implemented\n";
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'verify' ) {
|
elsif ( $command eq 'verify' ) {
|
||||||
|
my $opts = {
|
||||||
|
verbose => eval {
|
||||||
|
for ( my $i = 0; $i <= $#ARGV; $i++ ) {
|
||||||
|
if ( $ARGV[$i] eq '-v' ) {
|
||||||
|
splice( @ARGV, $i, 1 );
|
||||||
|
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
foreach my $arg ( @ARGV ) {
|
foreach my $arg ( @ARGV ) {
|
||||||
my $package = Snap::Package->new( $arg );
|
my $package = Snap::Package->new( $arg );
|
||||||
|
|
||||||
print Dumper( $package );
|
$package->verify( $opts );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $command eq 'version' ) {
|
elsif ( $command eq 'version' ) {
|
||||||
print "\n" . Snap->VERSION . "\n\n";
|
print Snap->VERSION . "\n";
|
||||||
}
|
}
|
||||||
elsif ( $command ) {
|
elsif ( $command ) {
|
||||||
print "\n";
|
Snap->error( 0, "'$command': Invalid command" );
|
||||||
|
|
||||||
Snap->error( -1, "'$command': Invalid command" );
|
$commands->help();
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Snap->error( 0, "You must supply a command" );
|
Snap->error( 0, "You must supply a command" );
|
||||||
|
|
||||||
$commands->help();
|
$commands->help();
|
||||||
|
|
||||||
|
exit( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,86 +4,141 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Snap;
|
use Snap;
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
my $conf = readconf();
|
my $conf = readconf();
|
||||||
|
my $templates = templates( $conf );
|
||||||
my $sources = Snap::Sources->new( $conf->{'sources'} );
|
my $sources = Snap::Sources->new( $conf->{'sources'} );
|
||||||
|
my @packages = ();
|
||||||
my $opts = {
|
my $template;
|
||||||
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 ) {
|
if ( ! Snap->TARGET ) {
|
||||||
Snap->error( -1, 'A target must be specified with -t' );
|
Snap->error( -1, 'A target must be specified with -t' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$template = $ARGV[0];
|
||||||
$sources->readpkgs();
|
$sources->readpkgs();
|
||||||
$corepkgs = $sources->search( $opts );
|
|
||||||
|
|
||||||
for ( my $i = 0; $i <= $#$corepkgs; $i++ ) {
|
foreach my $pkgname ( @{$templates->{$template}{'packages'}} ) {
|
||||||
if ( ! $opts->{'nodeps'} ) {
|
my $package = $sources->search( { name => $pkgname, quiet => 1 } );
|
||||||
print "Resolving dependencies for"
|
|
||||||
. " $corepkgs->[$i]{'name'}\n";
|
|
||||||
|
|
||||||
$corepkgs->[$i]->depends( $sources, $packages );
|
if ( $package->{'status'} && $package->{'status'} eq 'installed' ) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $package->{'path'} =~ /https*:\/\// ) {
|
||||||
|
( my $filename = $package->{'path'} ) =~ s/.*\///;
|
||||||
|
|
||||||
|
if ( -f "/var/lib/snap/packages/$filename" ) {
|
||||||
|
$package->{'path'} = "/var/lib/snap/packages/$filename";
|
||||||
|
}
|
||||||
|
elsif ( -f Snap->PKGDIR . "/$filename" ) {
|
||||||
|
$package->{'path'} = Snap->PKGDIR . "/$filename";
|
||||||
|
}
|
||||||
|
elsif ( ! -f Snap->PKGDIR . "/$filename" ) {
|
||||||
|
Snap->httpget( $package->{'path'},
|
||||||
|
Snap->PKGDIR . "/$filename", 0644 );
|
||||||
|
|
||||||
|
$package->{'path'} = Snap->PKGDIR . "/$filename";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print "Ignoring dependencies for"
|
Snap->error( -1, "$package->{'name'}:"
|
||||||
. " $corepkgs->[$i]{'name'}\n";
|
. " Unable to determine package path" );
|
||||||
}
|
|
||||||
|
|
||||||
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 ) {
|
push( @packages, $package );
|
||||||
print "\n";
|
|
||||||
|
|
||||||
$prepkgs->{$package}->install();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $package ( @$packages ) {
|
foreach my $package ( @packages ) {
|
||||||
if ( ! $virtfs ) {
|
$package->files( { quiet => 1 } );
|
||||||
$virtfs = virtfs( 'mount' );
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
$package->install();
|
$package->install();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! @packages ) {
|
||||||
|
print "Nothing to do\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $rootfs = "$conf->{'snapinstall'}{'templatedir'}/$template/rootfs";
|
||||||
|
my $postinst = "$conf->{'snapinstall'}{'templatedir'}"
|
||||||
|
. "/$template/postinst";
|
||||||
|
my $pid;
|
||||||
|
my $stat;
|
||||||
|
|
||||||
|
if ( ! Snap->dirempty( $rootfs ) ) {
|
||||||
|
if ( $pid = fork() ) {
|
||||||
|
waitpid( $pid, 0 );
|
||||||
|
$stat = $? >> 8;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
exec( "cp -a '$rootfs'/* " . Snap->TARGET );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $stat ) {
|
||||||
|
Snap->error( $stat, "Failed to copy rootfs" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Setting root password\n";
|
||||||
|
|
||||||
|
virtfs( 'mount' );
|
||||||
|
|
||||||
|
if ( $pid = fork() ) {
|
||||||
|
waitpid( $pid, 0 );
|
||||||
|
$stat = $? >> 8;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ( $> ) {
|
||||||
|
exec( "fakeroot fakechroot /usr/sbin/chroot "
|
||||||
|
. Snap->TARGET . " passwd root" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
exec ( "chroot " . Snap->TARGET . " passwd root" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtfs( 'umount' );
|
virtfs( 'umount' );
|
||||||
|
|
||||||
print "\n";
|
if ( $stat ) {
|
||||||
|
Snap->error( $stat, "Failed to set password" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( -f $postinst ) {
|
||||||
|
my $tmpscript = "/var/lib/snap/postinst";
|
||||||
|
|
||||||
|
open( my $fh, '<', $postinst ) || Snap->error( int( $! ),
|
||||||
|
"Failed to open $postinst" );
|
||||||
|
open( my $wh, '>', Snap->TARGET . "/$tmpscript" ) ||
|
||||||
|
Snap->error( int( $! ), "Failed to open $tmpscript" );
|
||||||
|
|
||||||
|
while ( <$fh> ) {
|
||||||
|
print $wh $_;
|
||||||
|
}
|
||||||
|
|
||||||
|
close( $wh );
|
||||||
|
close( $fh );
|
||||||
|
|
||||||
|
if ( $pid = fork() ) {
|
||||||
|
waitpid( $pid, 0 );
|
||||||
|
$stat = $? >> 8;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ( $> ) {
|
||||||
|
exec( "fakeroot fakechroot /usr/sbin/chroot "
|
||||||
|
. Snap->TARGET . " $tmpscript" );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
exec ( "chroot " . Snap->TARGET
|
||||||
|
. " $tmpscript" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $stat ) {
|
||||||
|
Snap->error( $stat, "Failed to execute $tmpscript" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
57
SRC/snap/templates/container/packages
Normal file
57
SRC/snap/templates/container/packages
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#
|
||||||
|
# These packages are the bare minimum necessary for a functional system.
|
||||||
|
# This file is required for snapinstall to function, so don't delete it!
|
||||||
|
#
|
||||||
|
|
||||||
|
snap-base
|
||||||
|
dash
|
||||||
|
texinfo
|
||||||
|
glibc
|
||||||
|
coreutils
|
||||||
|
libacl
|
||||||
|
libattr
|
||||||
|
libcap
|
||||||
|
ncurses
|
||||||
|
readline
|
||||||
|
tzdata
|
||||||
|
perl
|
||||||
|
binutils
|
||||||
|
bzip2
|
||||||
|
cpio
|
||||||
|
dhclient
|
||||||
|
e2fsprogs
|
||||||
|
ex
|
||||||
|
findutils
|
||||||
|
gawk
|
||||||
|
gdbm
|
||||||
|
gmp
|
||||||
|
grep
|
||||||
|
groff
|
||||||
|
gzip
|
||||||
|
iana-etc
|
||||||
|
iftools
|
||||||
|
inetutils
|
||||||
|
iproute2
|
||||||
|
kmod
|
||||||
|
less
|
||||||
|
libgcc
|
||||||
|
libpipeline
|
||||||
|
libstdc++
|
||||||
|
libzfs
|
||||||
|
linux-firmware
|
||||||
|
man-db
|
||||||
|
mpfr
|
||||||
|
net-tools
|
||||||
|
procps-ng
|
||||||
|
psmisc
|
||||||
|
sed
|
||||||
|
shadow
|
||||||
|
tar
|
||||||
|
snap
|
||||||
|
initscripts
|
||||||
|
sysklogd
|
||||||
|
sysvinit
|
||||||
|
tar
|
||||||
|
util-linux
|
||||||
|
xz
|
||||||
|
zlib
|
||||||
37
SRC/snap/templates/container/rootfs/etc/inittab
Normal file
37
SRC/snap/templates/container/rootfs/etc/inittab
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Default runlevel
|
||||||
|
id:3:initdefault:
|
||||||
|
|
||||||
|
# This is the set of scripts that prepare the system prior to entering runlevels
|
||||||
|
si::sysinit:/etc/init.d/rc S
|
||||||
|
|
||||||
|
# /etc/init.d/rc executes the S and K scripts when runlevel is changed
|
||||||
|
#
|
||||||
|
# Runlevel 0 is halt.
|
||||||
|
# Runlevel 1 is single-user.
|
||||||
|
# Runlevel 2 is multi-user without networking.
|
||||||
|
# Runlevel 3 is multi-user with networking.
|
||||||
|
# Runlevel 4 is not used by default.
|
||||||
|
# Runlevel 5 is multi-user with GUI.
|
||||||
|
# Runlevel 6 is reboot.
|
||||||
|
|
||||||
|
l0:0:wait:/etc/init.d/rc 0
|
||||||
|
l1:1:wait:/etc/init.d/rc 1
|
||||||
|
l2:2:wait:/etc/init.d/rc 2
|
||||||
|
l3:3:wait:/etc/init.d/rc 3
|
||||||
|
l4:4:wait:/etc/init.d/rc 4
|
||||||
|
l5:5:wait:/etc/init.d/rc 5
|
||||||
|
l6:6:wait:/etc/init.d/rc 6
|
||||||
|
|
||||||
|
# This allows ctrl-alt-del to reboot the system
|
||||||
|
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
|
||||||
|
|
||||||
|
# Single user mode
|
||||||
|
su:S1:respawn:/sbin/sulogin
|
||||||
|
|
||||||
|
# The following spawns agetty on tty1-6
|
||||||
|
#
|
||||||
|
# Format:
|
||||||
|
# id:runlevels:action:process
|
||||||
|
#
|
||||||
|
# More information is available with 'man inittab'
|
||||||
|
1:2345:respawn:/sbin/agetty --noclear --nohints tty1 38400
|
||||||
7
SRC/snap/templates/container/rootfs/etc/network.conf
Executable file
7
SRC/snap/templates/container/rootfs/etc/network.conf
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
|
auto eth0
|
||||||
|
iface eth0 inet dhcp
|
||||||
|
|
||||||
|
source-directory network.d
|
||||||
61
SRC/snap/templates/server/packages
Normal file
61
SRC/snap/templates/server/packages
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#
|
||||||
|
# These packages are the bare minimum necessary for a functional system.
|
||||||
|
# This file is required for snapinstall to function, so don't delete it!
|
||||||
|
#
|
||||||
|
|
||||||
|
snap-base
|
||||||
|
dash
|
||||||
|
texinfo
|
||||||
|
glibc
|
||||||
|
coreutils
|
||||||
|
libacl
|
||||||
|
libattr
|
||||||
|
libcap
|
||||||
|
ncurses
|
||||||
|
readline
|
||||||
|
tzdata
|
||||||
|
perl
|
||||||
|
binutils
|
||||||
|
bzip2
|
||||||
|
cpio
|
||||||
|
dhclient
|
||||||
|
e2fsprogs
|
||||||
|
ex
|
||||||
|
findutils
|
||||||
|
gawk
|
||||||
|
gdbm
|
||||||
|
gmp
|
||||||
|
grep
|
||||||
|
groff
|
||||||
|
grub
|
||||||
|
gzip
|
||||||
|
iana-etc
|
||||||
|
iftools
|
||||||
|
inetutils
|
||||||
|
iproute2
|
||||||
|
kmod
|
||||||
|
less
|
||||||
|
libgcc
|
||||||
|
libpipeline
|
||||||
|
libstdc++
|
||||||
|
libzfs
|
||||||
|
linux-firmware
|
||||||
|
man-db
|
||||||
|
mkinitramfs
|
||||||
|
mpfr
|
||||||
|
net-tools
|
||||||
|
openssh-client
|
||||||
|
openssh-server
|
||||||
|
procps-ng
|
||||||
|
psmisc
|
||||||
|
sed
|
||||||
|
shadow
|
||||||
|
tar
|
||||||
|
snap
|
||||||
|
initscripts
|
||||||
|
sysklogd
|
||||||
|
sysvinit
|
||||||
|
tar
|
||||||
|
util-linux
|
||||||
|
xz
|
||||||
|
zlib
|
||||||
29
SRC/snap/templates/server/postinst
Normal file
29
SRC/snap/templates/server/postinst
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
### PLACEHOLDER ###
|
||||||
|
# This script needs to provide things like network setup perhaps
|
||||||
|
|
||||||
|
# This code should help with setting up the network interfaces
|
||||||
|
#
|
||||||
|
#my $dir = '/sys/class/net';
|
||||||
|
#my $devs = {};
|
||||||
|
#
|
||||||
|
#opendir( my $dh, $dir ) || die( $! );
|
||||||
|
#
|
||||||
|
#while ( readdir( $dh ) ) {
|
||||||
|
# my $link = readlink( "$dir/$_" ) || next;
|
||||||
|
#
|
||||||
|
# if ( $link =~ /virtual/ ) {
|
||||||
|
# next;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# open( my $fh, "$dir/$_/address" ) || die( $! );
|
||||||
|
# $devs->{$_}{'mac'} = <$fh>;
|
||||||
|
# close( $fh );
|
||||||
|
#
|
||||||
|
# chomp( $devs->{$_}{'mac'} );
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
#foreach my $dev ( sort( keys( %$devs ) ) ) {
|
||||||
|
# print "$dev - $devs->{$dev}{'mac'}\n";
|
||||||
|
# }
|
||||||
8
SRC/snap/templates/server/rootfs/etc/snap.conf
Normal file
8
SRC/snap/templates/server/rootfs/etc/snap.conf
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[sources]
|
||||||
|
default = http://packages.snaplinux.org/ core dev main server
|
||||||
|
|
||||||
|
[snapinstall]
|
||||||
|
templatedir = /etc/snap.d/templates
|
||||||
|
|
||||||
|
include /etc/snap.d
|
||||||
|
|
||||||
Reference in New Issue
Block a user