From 997a8d69b51e83a7a6f912ee8087537f603eb209 Mon Sep 17 00:00:00 2001 From: Jay Larson Date: Fri, 4 Nov 2016 08:32:24 -0500 Subject: [PATCH] - Moved away from versioned directory for better tracking - Modified usher to set root password if not already set - Modified snap to deal with circular dependencies properly - Now snap properly checks exit value for usher postinst --- Makefile | 5 ++- SNAP/usher | 30 ++++++++++++++--- SRC/{snap-0.1 => snap}/Makefile | 0 SRC/{snap-0.1 => snap}/Makefile.snaplinux | 39 ++++++++++------------- SRC/{snap-0.1 => snap}/group | 0 SRC/{snap-0.1 => snap}/passwd | 0 SRC/{snap-0.1 => snap}/snap | 8 ++--- SRC/{snap-0.1 => snap}/snap.conf | 0 SRC/{snap-0.1 => snap}/snap.inprogress | 0 SRC/{snap-0.1 => snap}/snap_version | 0 10 files changed, 48 insertions(+), 34 deletions(-) rename SRC/{snap-0.1 => snap}/Makefile (100%) rename SRC/{snap-0.1 => snap}/Makefile.snaplinux (79%) rename SRC/{snap-0.1 => snap}/group (100%) rename SRC/{snap-0.1 => snap}/passwd (100%) rename SRC/{snap-0.1 => snap}/snap (99%) rename SRC/{snap-0.1 => snap}/snap.conf (100%) rename SRC/{snap-0.1 => snap}/snap.inprogress (100%) rename SRC/{snap-0.1 => snap}/snap_version (100%) diff --git a/Makefile b/Makefile index f0f73b5..0ca67f5 100644 --- a/Makefile +++ b/Makefile @@ -12,12 +12,11 @@ DEPENDS = bash,binutils,coreutils,gzip,iana-etc,iproute2,inetutils,initscripts,p ARCH = x86_64 URL = DESC = This is the base of the snaplinux system -SNAPVER = sr0 ARCHIVE := '' -SRCDIR := $(PWD)/SRC/snap-* +SRCDIR := $(PWD)/SRC/snap PATCHDIR := $(PWD)/SRC/patches -VERSION := $(shell echo $(SRCDIR)|egrep -o '\-[0-9].*'|sed 's/^-//')$(SNAPVER) +VERSION := 0.2sr1 MAKEINST = make install diff --git a/SNAP/usher b/SNAP/usher index d466f86..0472cf3 100755 --- a/SNAP/usher +++ b/SNAP/usher @@ -2,7 +2,7 @@ set -e -PASSWD="root:x:0:0:root:/root:/bin/bash +PASSWD="root:SETPASS:0:0:root:/root:/bin/bash bin:x:1:1:bin:/dev/null:/bin/false daemon:x:6:6:Daemon User:/dev/null:/bin/false messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false @@ -84,18 +84,38 @@ case $1 in if [ ! -f ${TARGET}/etc/passwd ]; then echo "Creating /etc/passwd" - echo ${PASSWD} > ${TARGET}/etc/passwd + echo "${PASSWD}" > ${TARGET}/etc/passwd fi - if [ ! -f ${TARGET}/etc/group ]; then echo "Creating /etc/group" - echo ${GROUP} > ${TARGET}/etc/group + echo "${GROUP}" > ${TARGET}/etc/group fi ;; postinst) + setpass=`cat ${TARGET}/etc/shadow|grep ^root|awk -F':' '{print $2}'` + + if [ "$setpass" == 'SETPASS' ]; then + echo "Setting root password" + + if [[ ${TARGET} ]]; then + if ! mountpoint ${TARGET}/dev; then + mount -o ro -t devtmpfs devtmpfs ${TARGET}/dev + chroot ${TARGET} passwd root + umount ${TARGET}/dev + else + chroot ${TARGET} passwd root + fi + else + passwd root + fi + fi + + echo "Refreshing snap" + if [[ ${TARGET} ]]; then - echo "Refreshing snap" chroot ${TARGET} snap refresh + else + snap refresh fi exit 0 ;; diff --git a/SRC/snap-0.1/Makefile b/SRC/snap/Makefile similarity index 100% rename from SRC/snap-0.1/Makefile rename to SRC/snap/Makefile diff --git a/SRC/snap-0.1/Makefile.snaplinux b/SRC/snap/Makefile.snaplinux similarity index 79% rename from SRC/snap-0.1/Makefile.snaplinux rename to SRC/snap/Makefile.snaplinux index b44d104..74e06fa 100644 --- a/SRC/snap-0.1/Makefile.snaplinux +++ b/SRC/snap/Makefile.snaplinux @@ -13,7 +13,6 @@ PACKAGE := $(shell echo $(PWD)|sed 's/.*\///') SNAPDIR = $(PWD)/SNAP ROOT = $(PWD)/ROOT -BYTES = 0 SNAP = $(PACKAGE)-$(VERSION).snap SNAPINFO = $(SNAPDIR)/snapinfo MANIFEST = $(SNAPDIR)/manifest @@ -22,14 +21,6 @@ FILES = $(SNAPDIR)/files.tar.gz # The following values must be set in the Makefile for the package -ifndef ARCHIVE -$(error ARCHIVE is not set) -endif - -ifndef SRCDIR -$(error SRCDIR is not set) -endif - ifndef VERSION $(error VERSION is not set) endif @@ -50,17 +41,16 @@ $(SNAP): $(SNAPINFO) $(FILES) $(SNAPINFO): $(MANIFEST) @>$(SNAPINFO) - $(eval BYTES := $(shell du -sB1 $(ROOT)|awk '{print $$1}')) + $(eval BYTES := $(shell gzip -l $(FILES)|tail -1|awk '{print $$2}')) - @printf "package: $(PACKAGE)\nversion: $(VERSION)\n" > $(SNAPINFO); \ + @printf "package: $(PACKAGE)\nversion: $(VERSION)\n" > $(SNAPINFO) && \ printf "depends: $(DEPENDS)\narch: $(ARCH)\nbytes: $(BYTES)\n" \ - >> $(SNAPINFO); \ + >> $(SNAPINFO) && \ printf "url: $(URL)\ndescription: $(DESC)\n" >> $(SNAPINFO) $(MANIFEST): $(FILES) @>$(MANIFEST) - @bytes=0; \ rootfiles=`cd $(ROOT) && find ! -path .|sed 's/^\.\///'|sort -r`; \ while read -r file; do \ info=`ls -ld "$(ROOT)/$$file"`; \ @@ -82,14 +72,19 @@ $(FILES): $(ROOT) @find $(ROOT) -name perllocal.pod -exec rm {} \; - @files=`find $(ROOT) -type f -exec file -i '{}' \;| grep \ - 'application/x-\(executable\|object\|sharedlib\);' | \ - grep ' charset=binary'`; \ - while read -r line; do \ - file=`echo $$line|sed 's/: application\/x-.*//'`; \ - if [ "$$file" != '' ]; then \ - strip --strip-unneeded $$file; \ - fi; \ - done <<< "$$files" + @find $(ROOT) -type f | while read -r file; do \ + type=`file -i $$file|sed 's/.*: //'`; \ + case $$type in \ + *'/x-executable; charset=binary') \ + strip --strip-unneeded $$file \ + ;; \ + *'/x-object; charset=binary') \ + strip --strip-debug $$file \ + ;; \ + *'/x-sharedlib; charset=binary') \ + strip --strip-debug $$file \ + ;; \ + esac; \ + done @cd $(ROOT) && tar cvzf $(FILES) * diff --git a/SRC/snap-0.1/group b/SRC/snap/group similarity index 100% rename from SRC/snap-0.1/group rename to SRC/snap/group diff --git a/SRC/snap-0.1/passwd b/SRC/snap/passwd similarity index 100% rename from SRC/snap-0.1/passwd rename to SRC/snap/passwd diff --git a/SRC/snap-0.1/snap b/SRC/snap/snap similarity index 99% rename from SRC/snap-0.1/snap rename to SRC/snap/snap index 47ded93..d38aced 100755 --- a/SRC/snap-0.1/snap +++ b/SRC/snap/snap @@ -158,10 +158,9 @@ sub depends { if ( $packages->{$package} && $packages->{$package}{'depends'} ) { foreach my $depend ( split( ',', $packages->{$package}{'depends'} ) ) { - depends( $packages, $depend, $depends ); - if ( ! grep( /^$depend$/, @$depends ) ) { push( @$depends, $depend ); + depends( $packages, $depend, $depends ); } } } @@ -640,7 +639,7 @@ sub install { print STDOUT "\e[K$filenum files extracted\e[?25h\n\n"; - usher( $pkgfile, $target, 'postinst' ); + %result = usher( $pkgfile, $target, 'postinst' ); return( \%result ); } @@ -1807,7 +1806,8 @@ elsif ( $ARGV[0] eq 'install' || $ARGV[0] eq 'reinstall' ){ } } - foreach my $depend ( @depends ) { + for ( my $i = $#depends; $i >= 0; $i-- ) { + my $depend = $depends[$i]; my $depdir = "$target/$conf->{'general'}{'snapdir'}/$depend"; my $dlpath = $packages->{$depend}{'path'}; ( my $file = $dlpath ) =~ s/.*\///; diff --git a/SRC/snap-0.1/snap.conf b/SRC/snap/snap.conf similarity index 100% rename from SRC/snap-0.1/snap.conf rename to SRC/snap/snap.conf diff --git a/SRC/snap-0.1/snap.inprogress b/SRC/snap/snap.inprogress similarity index 100% rename from SRC/snap-0.1/snap.inprogress rename to SRC/snap/snap.inprogress diff --git a/SRC/snap-0.1/snap_version b/SRC/snap/snap_version similarity index 100% rename from SRC/snap-0.1/snap_version rename to SRC/snap/snap_version