From 99d5350b30d881ed8cf97639fde69d79b8efef4d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 20 Oct 2008 16:34:27 +0200 Subject: [PATCH] Major changes to not depend on cksum and db from NetBSD. Two new utilities in C have been created: - xbps-digest: shows the SHA256 hash for a file. - xbps-pkgdb: handles dependency stuff via proplib. Templates should use now $build_depends and change $checksum to be a SHA256 hash. That means that I'm currently using xbps on Linux and I lost interest on NetBSD, perhaps I'll add support for it in the future. Only git and its dependencies have been converted, as well as vim. --HG-- extra : convert_revision : 53a7e030ca6b6d02bb6cd3e51d42b7d5702c1b57 --- .gitignore | 1 + Makefile | 8 + README | 10 + dependencies/build-depends.db | Bin 20992 -> 0 bytes templates/curl.tmpl | 4 +- templates/expat.tmpl | 4 +- templates/git.tmpl | 6 +- templates/libidn.tmpl | 4 +- templates/libtool.tmpl | 2 +- templates/perl-runstuff-after-install.sh | 2 +- templates/perl.tmpl | 2 +- templates/pkg-config.tmpl | 2 +- templates/vim.tmpl | 2 +- templates/xstow.tmpl | 2 +- xbps-digest/Makefile | 10 + xbps-digest/xbps-digest.c | 453 +++++++++++++++++++++++ xbps-pkgdb/Makefile | 13 + xbps-pkgdb/xbps-pkgdb.c | 197 ++++++++++ xbps.sh | 255 +++++++------ 19 files changed, 851 insertions(+), 126 deletions(-) create mode 100644 Makefile delete mode 100644 dependencies/build-depends.db create mode 100644 xbps-digest/Makefile create mode 100644 xbps-digest/xbps-digest.c create mode 100644 xbps-pkgdb/Makefile create mode 100644 xbps-pkgdb/xbps-pkgdb.c diff --git a/.gitignore b/.gitignore index 46916c43903..74e5ce74f79 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ depot/ packages/ srcdistdir/ builddir/ +utils/ diff --git a/Makefile b/Makefile new file mode 100644 index 00000000000..51cab5d0926 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +all: + mkdir -p utils + cd xbps-digest && make + cp -f xbps-digest/xbps-digest utils/ + cd xbps-pkgdb && make + cp -f xbps-pkgdb/xbps-pkgdb utils/ + cd xbps-digest && make clean + cd xbps-pkgdb && make clean diff --git a/README b/README index 6cda700df94..ffedc5585d1 100644 --- a/README +++ b/README @@ -7,10 +7,20 @@ Multiple versions of a package can be installed, because they can be enabled or disabled at the master directory anytime, to e.g allow testing different versions of the same package by "stowning" or "unstowning" them. +xbps uses proplib, a property container object library and it's almost the +same one available for NetBSD. Be sure to have it installed before using +xbps. You can get it at: + +http://code.google.com/p/portableproplib/ + ------------------------------------------------------------------------------ HOW TO USE IT ------------------------------------------------------------------------------ +Before using xbps, some required utilities need to be built and installed into +the utils/ directory. You can do this by issuing a "make" command in the +top level directory. + Once you download it, you should edit the configuration file located at the xbps directory. By default it uses the xbps directory in your $HOME. diff --git a/dependencies/build-depends.db b/dependencies/build-depends.db deleted file mode 100644 index b9e3fc6baf1fcc38d88de3366b4d5931d0648efa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20992 zcmeHPKaeC<8GlbjQBlwTC!W|KB5>E^%Qr()FxSkg1yGu!O+bkp6l zH%Ad@6@ivmWngdt0f7MlWnDl(Kww}%KtMo1Kww!H5D*X$7!dgTeXsw#?wP%D-4l+5 zhPmzOe(!tVd*A=>eQyT68`MV?u8;5^b2;VBhkuX!3TSJFyg#nq&~NKE^y~V(zEgim zzo}kO6ZMLILj6NOum7t5qMuby>Id{(KdfI>XVi{0+F>V!PsRUgOSuk(HsPjhz`a=e@QJyhzG`13X1d$T+q#?z5XQuaO0XY*{tzF+12 zBpht-srVRfzs&CfYY^sHo(5jzZjRj{arqM82`=F@ndNS@*4ZE)U*vPsXUCn)h8O+N z_wtKLa3KxzAayt0UWd4R!EU!{`hC87=K1j;aDizOdhRCWhxn*yC}Q+E)2_q$eU|rm zZ;SYUn)k%XPczQ#Q~aI;laJvK$K>2b?t142+}>Dx-%dOCd;<6U$lOP{;(NlA@4%kp z@R^!yj|i9W)Oa!>9wOVrIAR+IAGYD2Z}J~pY|o2pZ`S*Se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zPBRacX;n*ehYCvi+7 z^ERQr`KP2mE26Aj9b-kTb|2mzofV+mmsd%D`4s|_+$MXLyAntlEU*7{s#-%RC)D7U z@IL%|{jb37K#_hAX>V-YW&H|rf7d_eA508s=f!6k@20_If)hd3afGgNNJo+Bar1PG zoiXCiN8ncjkTmQH?divo4@mzL>S6Vgei)wKpYiQ*7yTFUoyS3*(`=`+X^!&|c3Kiv z%JMBtF5+Jtb{t0LXIvU#ZWRn$)25|^%f_O9{1^igt@xDznoK$G#63y8+357-{2aC$ znfYXK=uS9{Cpa~NKT|i~32<(MmUA(-<*!xPCp*yWG>!)%1Bg2eieHQ{=gp))Y`S&k zq{=cwGp?hLSqIKo?DVGie&3b(+VA#Xp$bN^mK<{vSxNeU;_DJG*}yQ!tu@XurnA9C zEX`JD(@i$ll;oreA|su$Ik{xfQT@aVd}CxG}RnkdfHvV*nYIDEI!+D&O z{0hmcG?E2d_MJf6P3$1iGi;=1tZf4E3#;>i!ZVC582cFd_YwC!1?uQ7QB}oo)#Us#FkQP>@hN~lz0(supMLxx}kx@;(S-S^VKFE zRT_l71)OLQ=1Jb5ALHB=@tbuf%H%&7Ymz4o{ohot>1T2N_f0}PQWw{~!x`1TiLtO& z?ca83R^Axi2n>ug7{&88=`D$DnW*hb=p1vF4< $config_pm.in diff --git a/templates/perl.tmpl b/templates/perl.tmpl index b22cacde4f6..f4d84553cd1 100644 --- a/templates/perl.tmpl +++ b/templates/perl.tmpl @@ -9,7 +9,7 @@ configure_args="-Dusethreads -des -Dprefix=$XBPS_DESTDIR/$pkgname-$version build_style=configure short_desc="Practical Extraction and Report Language" maintainer="Juan RP " -checksum=c6614fc99a162790a703f91085b24a60af903ba2 +checksum=94464a0d374fa63226eee56e0bb3d35564f9d8391a1a8d9f0055805ec25f3b2e long_desc=" Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including diff --git a/templates/pkg-config.tmpl b/templates/pkg-config.tmpl index a3de4e3c9b4..8830797aca1 100644 --- a/templates/pkg-config.tmpl +++ b/templates/pkg-config.tmpl @@ -7,7 +7,7 @@ build_style=gnu_configure configure_args="--disable-threads --with-pc-path=$XBPS_MASTERDIR/lib/pkgconfig" short_desc="System for managing library compile/link flags" maintainer="Juan RP " -checksum=0aa5565430d609319917ac2c8ffeaa5e4a509489 +checksum=08a0e072d6a05419a58124db864f0685e6ac96e71b2875bf15ac12714e983b53 long_desc=" pkg-config is a system for managing library compile/link flags that works with automake and autoconf. It replaces the ubiquitous diff --git a/templates/vim.tmpl b/templates/vim.tmpl index d026899f7c7..d6923f43acc 100644 --- a/templates/vim.tmpl +++ b/templates/vim.tmpl @@ -6,7 +6,7 @@ distfiles="ftp://ftp.vim.org/pub/vim/unix/$pkgname-$version@.tar.bz2" build_style=gnu_configure short_desc="Vim editor (vi clone)" maintainer="Juan RP " -checksum=eaff64d0fec09d725addf8de569f508b80a5766e +checksum=914db0f2205ebd6f02878295ec2506036ea7500399db112c61a01491cd9a1d86 long_desc=" Vim is an almost compatible version of the UNIX editor Vi. Many new features have been added: multi level undo, syntax highlighting, command line history, diff --git a/templates/xstow.tmpl b/templates/xstow.tmpl index f13d2b70ce9..ae4b4c32621 100644 --- a/templates/xstow.tmpl +++ b/templates/xstow.tmpl @@ -6,7 +6,7 @@ http://kent.dl.sourceforge.net/sourceforge/xstow/$pkgname-$version@.tar.bz2" build_style=gnu_configure short_desc="Replacement of GNU Stow written in C++" maintainer="Juan RP " -checksum=9b99bd9affe9a841503970e903555ce340fcf296 +checksum=f1872c10eccca3b3b4202e2e0f4c7f10833bc941e02f3f17776d5ddb192f68f5 long_desc=" XStow as GNU Stow, are programs for managing the installation of software packages, keeping them separate (/usr/local/stow/emacs vs. diff --git a/xbps-digest/Makefile b/xbps-digest/Makefile new file mode 100644 index 00000000000..9010242864b --- /dev/null +++ b/xbps-digest/Makefile @@ -0,0 +1,10 @@ +CFLAGS += -Wall -Werror -O3 -funroll-all-loops -ftree-loop-linear + +all: xbps-digest + +xbps-digest: xbps-digest.o + $(CC) $(CFLAGS) $< -o $@ + +clean: + -rm -rf *.o xbps-digest + diff --git a/xbps-digest/xbps-digest.c b/xbps-digest/xbps-digest.c new file mode 100644 index 00000000000..531f2afeef3 --- /dev/null +++ b/xbps-digest/xbps-digest.c @@ -0,0 +1,453 @@ +/* + * Written by Aaron D. Gifford + * + * Copyright 2000 Aaron D. Gifford. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef uint8_t sha2_byte; /* Exactly 1 byte */ +typedef uint32_t sha2_word32; /* Exactly 4 bytes */ +typedef uint64_t sha2_word64; /* Exactly 8 bytes */ + +/*** SHA-256 Various Length Definitions ***********************/ +#define SHA256_BLOCK_LENGTH 64 +#define SHA256_DIGEST_LENGTH 32 +#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) + +/*** SHA-256 Context Structures *******************************/ +typedef struct _SHA256_CTX { + uint32_t state[8]; + uint64_t bitcount; + uint8_t buffer[SHA256_BLOCK_LENGTH]; +} SHA256_CTX; + +static void SHA256_Init(SHA256_CTX *); +static void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t); +static void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*); +static char *SHA256_End(SHA256_CTX*, uint8_t[SHA256_DIGEST_STRING_LENGTH]); +static void SHA256_Transform(SHA256_CTX*, const sha2_word32*); + +/*** SHA-256 Machine Architecture Definitions *****************/ + +/*** SHA-256 Various Length Definitions ***********************/ +/* NOTE: Most of these are in sha2.h */ +#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) + +/*** ENDIAN REVERSAL MACROS *******************************************/ +#ifndef WORDS_BIGENDIAN +#define REVERSE32(w,x) { \ + sha2_word32 tmp = (w); \ + tmp = (tmp >> 16) | (tmp << 16); \ + (x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \ +} +#define REVERSE64(w,x) { \ + sha2_word64 tmp = (w); \ + tmp = (tmp >> 32) | (tmp << 32); \ + tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \ + ((tmp & 0x00ff00ff00ff00ffULL) << 8); \ + (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \ + ((tmp & 0x0000ffff0000ffffULL) << 16); \ +} +#endif /* WORDS_BIGENDIAN */ + +/* + * Macro for incrementally adding the unsigned 64-bit integer n to the + * unsigned 128-bit integer (represented using a two-element array of + * 64-bit words): + */ +#define ADDINC128(w,n) { \ + (w)[0] += (sha2_word64)(n); \ + if ((w)[0] < (n)) { \ + (w)[1]++; \ + } \ +} + +/*** THE SIX LOGICAL FUNCTIONS ****************************************/ +/* + * Bit shifting and rotation (used by the six SHA-XYZ logical functions: + * + * NOTE: The naming of R and S appears backwards here (R is a SHIFT and + * S is a ROTATION) because the SHA-256/384/512 description document + * (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this + * same "backwards" definition. + */ +/* Shift-right (used in SHA-256, SHA-384, and SHA-512): */ +#define R(b,x) ((x) >> (b)) +/* 32-bit Rotate-right (used in SHA-256): */ +#define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b)))) + +/* Two of six logical functions used in SHA-256, SHA-384, and SHA-512: */ +#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) +#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) + +/* Four of six logical functions used in SHA-256: */ +#define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x))) +#define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x))) +#define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x))) +#define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x))) + +/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/ +/* Hash constant words K for SHA-256: */ +const static sha2_word32 K256[64] = { + 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, + 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, + 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, + 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, + 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, + 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, + 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, + 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, + 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, + 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, + 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, + 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, + 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, + 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, + 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, + 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL +}; + +/* Initial hash value H for SHA-256: */ +const static sha2_word32 sha256_initial_hash_value[8] = { + 0x6a09e667UL, + 0xbb67ae85UL, + 0x3c6ef372UL, + 0xa54ff53aUL, + 0x510e527fUL, + 0x9b05688cUL, + 0x1f83d9abUL, + 0x5be0cd19UL +}; + +/*** SHA-256: *********************************************************/ +static void SHA256_Init(SHA256_CTX* context) +{ + if (context == (SHA256_CTX*)0) { + return; + } + memcpy(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH); + memset(context->buffer, 0, SHA256_BLOCK_LENGTH); + context->bitcount = 0; +} + +/* Unrolled SHA-256 round macros: */ + +#ifndef WORDS_BIGENDIAN + +#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \ + REVERSE32(*data++, W256[j]); \ + T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \ + K256[j] + W256[j]; \ + (d) += T1; \ + (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \ + j++ + + +#else /* WORDS__BIGENDIAN */ + +#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \ + T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \ + K256[j] + (W256[j] = *data++); \ + (d) += T1; \ + (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \ + j++ + +#endif /* WORDS_BIGENDIAN */ + +#define ROUND256(a,b,c,d,e,f,g,h) \ + s0 = W256[(j+1)&0x0f]; \ + s0 = sigma0_256(s0); \ + s1 = W256[(j+14)&0x0f]; \ + s1 = sigma1_256(s1); \ + T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + K256[j] + \ + (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \ + (d) += T1; \ + (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \ + j++ + +static void +SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) +{ + sha2_word32 a, b, c, d, e, f, g, h, s0, s1; + sha2_word32 T1, *W256; + int j; + + W256 = (sha2_word32*)context->buffer; + + /* Initialize registers with the prev. intermediate value */ + a = context->state[0]; + b = context->state[1]; + c = context->state[2]; + d = context->state[3]; + e = context->state[4]; + f = context->state[5]; + g = context->state[6]; + h = context->state[7]; + + j = 0; + do { + /* Rounds 0 to 15 (unrolled): */ + ROUND256_0_TO_15(a,b,c,d,e,f,g,h); + ROUND256_0_TO_15(h,a,b,c,d,e,f,g); + ROUND256_0_TO_15(g,h,a,b,c,d,e,f); + ROUND256_0_TO_15(f,g,h,a,b,c,d,e); + ROUND256_0_TO_15(e,f,g,h,a,b,c,d); + ROUND256_0_TO_15(d,e,f,g,h,a,b,c); + ROUND256_0_TO_15(c,d,e,f,g,h,a,b); + ROUND256_0_TO_15(b,c,d,e,f,g,h,a); + } while (j < 16); + + /* Now for the remaining rounds to 64: */ + do { + ROUND256(a,b,c,d,e,f,g,h); + ROUND256(h,a,b,c,d,e,f,g); + ROUND256(g,h,a,b,c,d,e,f); + ROUND256(f,g,h,a,b,c,d,e); + ROUND256(e,f,g,h,a,b,c,d); + ROUND256(d,e,f,g,h,a,b,c); + ROUND256(c,d,e,f,g,h,a,b); + ROUND256(b,c,d,e,f,g,h,a); + } while (j < 64); + + /* Compute the current intermediate hash value */ + context->state[0] += a; + context->state[1] += b; + context->state[2] += c; + context->state[3] += d; + context->state[4] += e; + context->state[5] += f; + context->state[6] += g; + context->state[7] += h; + + /* Clean up */ + a = b = c = d = e = f = g = h = T1 = 0; +} + +static void +SHA256_Update(SHA256_CTX* context, const uint8_t *data, size_t len) +{ + unsigned int freespace, usedspace; + + if (len == 0) { + /* Calling with no data is valid - we do nothing */ + return; + } + + /* Sanity check: */ + assert(context != NULL && data != NULL); + + usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; + if (usedspace > 0) { + /* Calculate how much free space is available in the buffer */ + freespace = SHA256_BLOCK_LENGTH - usedspace; + + if (len >= freespace) { + /* Fill the buffer completely and process it */ + memcpy(&context->buffer[usedspace], data, freespace); + context->bitcount += freespace << 3; + len -= freespace; + data += freespace; + SHA256_Transform(context, + (sha2_word32*)context->buffer); + } else { + /* The buffer is not yet full */ + memcpy(&context->buffer[usedspace], data, len); + context->bitcount += len << 3; + /* Clean up: */ + usedspace = freespace = 0; + return; + } + } + while (len >= SHA256_BLOCK_LENGTH) { + /* Process as many complete blocks as we can */ + SHA256_Transform(context, (const sha2_word32*)data); + context->bitcount += SHA256_BLOCK_LENGTH << 3; + len -= SHA256_BLOCK_LENGTH; + data += SHA256_BLOCK_LENGTH; + } + if (len > 0) { + /* There's left-overs, so save 'em */ + memcpy(context->buffer, data, len); + context->bitcount += len << 3; + } + /* Clean up: */ + usedspace = freespace = 0; +} + +static void +SHA256_Final(sha2_byte digest[], SHA256_CTX* context) +{ + sha2_word32 *d = (sha2_word32*)digest; + unsigned int usedspace; + + /* Sanity check: */ + assert(context != NULL); + + /* If no digest buffer is passed, we don't bother doing this: */ + if (digest != (sha2_byte*)0) { + usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; +#ifndef WORDS_BIGENDIAN + /* Convert FROM host byte order */ + REVERSE64(context->bitcount,context->bitcount); +#endif + if (usedspace > 0) { + /* Begin padding with a 1 bit: */ + context->buffer[usedspace++] = 0x80; + + if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) { + /* Set-up for the last transform: */ + memset(&context->buffer[usedspace], 0, + SHA256_SHORT_BLOCK_LENGTH - usedspace); + } else { + if (usedspace < SHA256_BLOCK_LENGTH) { + memset(&context->buffer[usedspace], 0, + SHA256_BLOCK_LENGTH - usedspace); + } + /* Do second-to-last transform: */ + SHA256_Transform(context, + (sha2_word32*)context->buffer); + + /* And set-up for the last transform: */ + memset(context->buffer, 0, + SHA256_SHORT_BLOCK_LENGTH); + } + } else { + /* Set-up for the last transform: */ + memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); + + /* Begin padding with a 1 bit: */ + *context->buffer = 0x80; + } + /* Set the bit count: */ + *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = + context->bitcount; + + /* Final transform: */ + SHA256_Transform(context, (sha2_word32*)context->buffer); + +#ifndef WORDS_BIGENDIAN + { + /* Convert TO host byte order */ + int j; + for (j = 0; j < 8; j++) { + REVERSE32(context->state[j],context->state[j]); + *d++ = context->state[j]; + } + } +#else + memcpy(d, context->state, SHA256_DIGEST_LENGTH); +#endif + } + + /* Clean up state data: */ + memset(context, 0, sizeof(SHA256_CTX)); + usedspace = 0; +} + +/* + * Constant used by SHA256/384/512_End() functions for converting the + * digest to a readable hexadecimal character string: + */ +static const char sha2_hex_digits[] = "0123456789abcdef"; + +static char * +SHA256_End(SHA256_CTX *ctx, uint8_t *buffer) +{ + uint8_t digest[SHA256_DIGEST_LENGTH], *d = digest; + uint8_t *ret; + int i; + + /* Sanity check: */ + assert(ctx != NULL); + + if ((ret = buffer) != NULL) { + SHA256_Final(digest, ctx); + + for (i = 0; i < SHA256_DIGEST_LENGTH; i++) { + *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4]; + *buffer++ = sha2_hex_digits[*d & 0x0f]; + d++; + } + *buffer = (char) 0; + } else { + (void)memset(ctx, 0, sizeof(SHA256_CTX)); + } + (void)memset(digest, 0, SHA256_DIGEST_LENGTH); + return (char *)ret; +} + +static void +usage(void) +{ + fprintf(stderr, "usage: xbps-digest \n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + SHA256_CTX ctx; + uint8_t buffer[BUFSIZ * 20], *digest; + ssize_t bytes; + int fd; + + if (argc != 2) + usage(); + + if ((fd = open(argv[1], O_RDONLY)) == -1) { + printf("xbps-digest: cannot open %s (%s)\n", argv[1], + strerror(errno)); + exit(1); + } + + digest = malloc(SHA256_DIGEST_LENGTH * 2 + 1); + if (digest == NULL) { + printf("xbps-digest: malloc failed (%s)\n", strerror(errno)); + exit(1); + } + + SHA256_Init(&ctx); + while ((bytes = read(fd, buffer, sizeof(buffer))) > 0) + SHA256_Update(&ctx, buffer, (size_t)bytes); + + printf("%s\n", SHA256_End(&ctx, digest)); + free(digest); + close(fd); + + exit(0); +} diff --git a/xbps-pkgdb/Makefile b/xbps-pkgdb/Makefile new file mode 100644 index 00000000000..361e1429eb6 --- /dev/null +++ b/xbps-pkgdb/Makefile @@ -0,0 +1,13 @@ +# Override PREFIX to look in correct path. +# +PREFIX ?= /usr/local +CFLAGS += -Wall -Werror -I$(PREFIX)/include +LDFLAGS += -L$(PREFIX)/lib -Wl,-R$(PREFIX)/lib -lprop + +all: xbps-pkgdb + +xbps-pkgdb: xbps-pkgdb.o + $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ + +clean: + -rm -f *.o *.core xbps-pkgdb diff --git a/xbps-pkgdb/xbps-pkgdb.c b/xbps-pkgdb/xbps-pkgdb.c new file mode 100644 index 00000000000..d04379ce913 --- /dev/null +++ b/xbps-pkgdb/xbps-pkgdb.c @@ -0,0 +1,197 @@ +/*- + * Copyright (c) 2008 Juan Romero Pardines. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#define _XBPS_PKGDB_DEFPATH "/usr/local/packages/.xbps-pkgdb.plist" + +static void usage(void); + +static void +usage(void) +{ + printf("usage: xbps-pkgdb [ ]\n"); + printf("\n"); + printf(" Available actions:\n"); + printf(" installed, list, register, unregister, version\n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + prop_dictionary_t dbdict; + prop_object_iterator_t dbditer; + prop_object_t obj, obj2; + prop_string_t pkg; + char dbfile[PATH_MAX], *dbfileenv, *tmppath; + + if (argc < 2) + usage(); + + if ((dbfileenv = getenv("XBPS_PKGDB_FPATH")) != NULL) { + /* Use path as defined by XBPS_PKGDB_FPATH env var */ + tmppath = strncpy(dbfile, dbfileenv, sizeof(dbfile)); + if (sizeof(*tmppath) >= sizeof(dbfile)) + exit(1); + } else { + /* Use default path */ + tmppath = + strncpy(dbfile, _XBPS_PKGDB_DEFPATH, sizeof(dbfile)); + if (sizeof(*tmppath) >= sizeof(dbfile)) + exit(1); + } + /* nul terminate string */ + dbfile[sizeof(dbfile) - 1] = '\0'; + + if (strcmp(argv[1], "installed") == 0) { + /* Returns 0 if pkg is installed, 1 otherwise */ + if (argc != 3) + usage(); + + dbdict = prop_dictionary_internalize_from_file(dbfile); + if (dbdict == NULL) { + perror("ERROR: couldn't read database file"); + exit(1); + } + obj = prop_dictionary_get(dbdict, argv[2]); + if (obj == NULL) + exit(1); + + } else if (strcmp(argv[1], "register") == 0) { + /* Registers a package into the database */ + if (argc != 4) + usage(); + + dbdict = prop_dictionary_internalize_from_file(dbfile); + if (dbdict == NULL) { + /* create db file and register pkg */ + dbdict = prop_dictionary_create(); + if (dbdict == NULL) { + perror("ERROR"); + exit(1); + } + prop_dictionary_set_cstring_nocopy(dbdict, argv[2], argv[3]); + if (!prop_dictionary_externalize_to_file(dbdict, dbfile)) { + perror("ERROR: couldn't write database file"); + exit(1); + } + printf("==> Package database file not found, " + "creating it.\n"); + prop_object_release(dbdict); + } else { + /* register pkg if it's not registered already */ + pkg = prop_dictionary_get(dbdict, argv[2]); + if (pkg && prop_object_type(pkg) == PROP_TYPE_STRING) { + printf("==> Package `%s' already registered.\n", argv[2]); + exit(0); + } + prop_dictionary_set_cstring_nocopy(dbdict, argv[2], argv[3]); + if (!prop_dictionary_externalize_to_file(dbdict, dbfile)) { + perror(" ERROR: couldn't write database file"); + exit(1); + } + } + printf("==> %s-%s registered successfully.\n", argv[2], argv[3]); + + } else if (strcmp(argv[1], "unregister") == 0) { + /* Unregisters a package from the database */ + if (argc != 4) + usage(); + + dbdict = prop_dictionary_internalize_from_file(dbfile); + if (dbdict == NULL) { + perror("ERROR: couldn't read database file"); + exit(1); + } + obj = prop_dictionary_get(dbdict, argv[2]); + if (obj == NULL) { + printf("ERROR: package `%s' not registered in database.\n", + argv[2]); + exit(1); + } + prop_dictionary_remove(dbdict, argv[2]); + if (!prop_dictionary_externalize_to_file(dbdict, dbfile)) { + perror("ERROR: couldn't write database file"); + exit(1); + } + + printf("==> %s-%s unregistered successfully.\n", argv[2], argv[3]); + + } else if (strcmp(argv[1], "list") == 0) { + /* Lists packages currently registered in database */ + if (argc != 2) + usage(); + + dbdict = prop_dictionary_internalize_from_file(dbfile); + if (dbdict == NULL) { + perror("ERROR: couldn't read database file"); + exit(1); + } + dbditer = prop_dictionary_iterator(dbdict); + if (dbditer == NULL) { + perror("ERROR"); + exit(1); + } + while ((obj = prop_object_iterator_next(dbditer)) != NULL) { + obj2 = prop_dictionary_get_keysym(dbdict, obj); + if (obj2 != NULL) { + printf("%s", prop_dictionary_keysym_cstring_nocopy(obj)); + printf("-%s\n", prop_string_cstring_nocopy(obj2)); + } + } + prop_object_iterator_release(dbditer); + + } else if (strcmp(argv[1], "version") == 0) { + /* Prints version of an installed package */ + if (argc != 3) + usage(); + + dbdict = prop_dictionary_internalize_from_file(dbfile); + if (dbdict == NULL) { + perror("ERROR: couldn't read database file"); + exit(1); + } + obj = prop_dictionary_get(dbdict, argv[2]); + if (obj == NULL) { + printf("ERROR: package `%s' not registered in database.\n", + argv[2]); + exit(1); + } + printf("%s\n", prop_string_cstring_nocopy(obj)); + + } else { + usage(); + } + + exit(0); +} diff --git a/xbps.sh b/xbps.sh index bb1c9cf140d..5669fcc85a7 100755 --- a/xbps.sh +++ b/xbps.sh @@ -41,27 +41,26 @@ : ${XBPS_CONFIG_FILE:=/usr/local/etc/xbps.conf} : ${progname:=$(basename $0)} -: ${topdir:=$(/bin/pwd -P 2>/dev/null)} -: ${fetch_cmd:=/usr/bin/ftp -a} -: ${cksum_cmd:=/usr/bin/cksum -a rmd160} +: ${topdir:=$(/bin/pwd 2>/dev/null)} +: ${fetch_cmd:=/usr/bin/wget} : ${awk_cmd:=/usr/bin/awk} -: ${mkdir_cmd:=/bin/mkdir -p} -: ${tar_cmd:=/usr/bin/tar} +: ${mkdir_cmd:=/bin/mkdir} +: ${tar_cmd:=/bin/tar} : ${rm_cmd:=/bin/rm} : ${mv_cmd:=/bin/mv} : ${cp_cmd:=/bin/cp} -: ${sed_cmd=/usr/bin/sed} -: ${grep_cmd=/usr/bin/grep} -: ${gunzip_cmd:=/usr/bin/gunzip} -: ${bunzip2_cmd:=/usr/bin/bunzip2} +: ${sed_cmd=/bin/sed} +: ${grep_cmd=/bin/grep} +: ${gunzip_cmd:=/bin/gunzip} +: ${bunzip2_cmd:=/bin/bunzip2} : ${patch_cmd:=/usr/bin/patch} : ${find_cmd:=/usr/bin/find} : ${file_cmd:=/usr/bin/file} : ${ln_cmd:=/bin/ln} : ${chmod_cmd:=/bin/chmod} -: ${db_cmd:=/usr/bin/db -q} : ${chmod_cmd:=/bin/chmod} : ${touch_cmd:=/usr/bin/touch} +: ${env_cmd:=/usr/bin/env} : ${xstow_args:=-ap} : ${xstow_ignore_files:=perllocal.pod} # XXX For now ignore them. @@ -70,12 +69,13 @@ set_defvars() { # Directories : ${XBPS_TEMPLATESDIR:=$XBPS_DISTRIBUTIONDIR/templates} - : ${XBPS_DEPSDIR:=$XBPS_DISTRIBUTIONDIR/dependencies} - : ${XBPS_BUILD_DEPS_DB:=$XBPS_DEPSDIR/build-depends.db} : ${XBPS_TMPLHELPDIR:=$XBPS_DISTRIBUTIONDIR/helper-templates} - : ${XBPS_REGPKG_DB:=$XBPS_DESTDIR/.xbps-registered-pkgs.db} + : ${XBPS_PKGDB_FPATH:=$XBPS_DESTDIR/.xbps-pkgdb.plist} + : ${XBPS_UTILSDIR:=$XBPS_DISTRIBUTIONDIR/utils} + : ${XBPS_DIGEST_CMD:=$XBPS_UTILSDIR/xbps-digest} + : ${XBPS_PKGDB_CMD:=$XBPS_UTILSDIR/xbps-pkgdb} - local DDIRS="XBPS_DEPSDIR XBPS_TEMPLATESDIR XBPS_TMPLHELPDIR" + local DDIRS="XBPS_TEMPLATESDIR XBPS_TMPLHELPDIR XBPS_UTILSDIR" for i in ${DDIRS}; do eval val="\$$i" if [ ! -d "$val" ]; then @@ -83,6 +83,20 @@ set_defvars() exit 1 fi done + + local CMDS="fetch_cmd awk_cmd mkdir_cmd tar_cmd rm_cmd mv_cmd \ + cp_cmd sed_cmd grep_cmd gunzip_cmd bunzip2_cmd patch_cmd find_cmd \ + file_cmd ln_cmd chmod_cmd chmod_cmd touch_cmd XBPS_DIGEST_CMD \ + XBPS_PKGDB_CMD" + for f in ${CMDS}; do + eval val="\$$f" + if [ ! -x "$val" ]; then + echo "*** ERROR: cannot find $f command, aborting ***" + exit 1 + fi + done + + XBPS_PKGDB_CMD="$env_cmd XBPS_PKGDB_FPATH=$XBPS_PKGDB_FPATH $XBPS_PKGDB_CMD" } usage() @@ -97,8 +111,8 @@ Targets: fetch Download distribution file(s). info Show information about . install-destdir build + configure + install into destdir. - install Same than \`install-destdir´ but also stows package. - list Lists all currently \`stowned´ packages. + install Same than 'install-destdir' but also stows package. + list Lists all currently 'stowned' packages. remove Remove package completely (unstow + remove data) listfiles Lists files installed from . stow Create links in master directory. @@ -171,19 +185,19 @@ info_tmpl() echo "pkgname: $pkgname" echo "version: $version" for i in "${distfiles}"; do - [ -n "$i" ] && i=$(echo $i|$sed_cmd s'|@||g') && echo "distfile: $i" + [ -n "$i" ] && i=$(echo $i|$sed_cmd s'|@||g') && \ + echo "distfile: $i" done - echo "maintainer: $maintainer" [ -n $checksum ] && echo "checksum: $checksum" + echo "maintainer: $maintainer" echo "build_style: $build_style" echo "short_desc: $short_desc" echo "$long_desc" echo check_build_depends_pkg $pkgname-$version if [ $? -eq 0 ]; then - local list="$($db_cmd -V btree $XBPS_BUILD_DEPS_DB $pkgname)" echo "This package requires the following dependencies to be built:" - for i in ${list}; do + for i in ${build_depends}; do echo " $i" done fi @@ -220,7 +234,7 @@ check_config_vars() fi local XBPS_VARS="XBPS_MASTERDIR XBPS_DESTDIR XBPS_BUILDDIR \ - XBPS_SRCDISTDIR XBPS_SYSCONFDIR" + XBPS_SRCDISTDIR XBPS_SYSCONFDIR" for f in ${XBPS_VARS}; do eval val="\$$f" @@ -255,7 +269,7 @@ reset_tmpl_vars() run_stuff_before_install_cmd run_stuff_after_install_cmd \ make_install_target postinstall_helpers version \ ignore_files tar_override_cmd xml_entries sgml_entries \ - make_install_prefix \ + make_install_prefix build_depends \ XBPS_EXTRACT_DONE XBPS_CONFIGURE_DONE \ XBPS_BUILD_DONE XBPS_INSTALL_DONE" @@ -279,7 +293,7 @@ setup_tmpl() fi prepare_tmpl else - echo "*** ERROR: cannot find \`$pkg´ template file ***" + echo "*** ERROR: cannot find $pkg template file ***" exit 1 fi } @@ -300,7 +314,7 @@ prepare_tmpl() for i in ${REQ_VARS}; do eval val="\$$i" if [ -z "$val" -o -z "$i" ]; then - echo -n "*** ERROR: \"$i\" not set on \`$pkgname' " + echo -n "*** ERROR: \"$i\" not set on $pkgname " echo "template ***" exit 1 fi @@ -318,7 +332,7 @@ prepare_tmpl() XBPS_BUILD_DONE="$wrksrc/.xbps_build_done" XBPS_INSTALL_DONE="$wrksrc/.xbps_install_done" - export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$XBPS_MASTERDIR/bin:$XBPS_MASTERDIR/sbin" + export PATH="$XBPS_MASTERDIR/bin:$XBPS_MASTERDIR/sbin:/bin:/sbin:/usr/bin:/usr/sbin" } # @@ -377,18 +391,26 @@ extract_distfiles() fi case ${cursufx} in - .tar.bz2|.tar.gz|.tgz|.tbz) + .tar.bz2|.tbz) + $ltar_cmd xfj $XBPS_SRCDISTDIR/$curfile -C $lwrksrc + if [ $? -ne 0 ]; then + echo -n "*** ERROR extracting $curfile into " + echo "$lwrksrc ***" + exit 1 + fi + ;; + .tar.gz|.tgz) $ltar_cmd xfz $XBPS_SRCDISTDIR/$curfile -C $lwrksrc if [ $? -ne 0 ]; then - echo -n "*** ERROR extracting \`$curfile' into " - echo "$lwrksrc ***" + echo -n "*** ERROR extracting $curfile into " + echo "$lwrksrc ***" exit 1 fi ;; .tar) $ltar_cmd xf $XBPS_SRCDISTDIR/$curfile -C $lwrksrc if [ $? -ne 0 ]; then - echo -n "*** ERROR extracting \`$curfile' into " + echo -n "*** ERROR extracting $curfile into " echo "$lwrksrc ***" exit 1 fi @@ -412,13 +434,13 @@ extract_distfiles() extract_unzip $XBPS_SRCDISTDIR/$curfile $lwrksrc if [ $? -ne 0 ]; then - echo -n "*** ERROR extracting \`$curfile' into " + echo -n "*** ERROR extracting $curfile into " echo "$lwrksrc ***" exit 1 fi ;; *) - echo -n "*** ERROR: cannot guess \`$curfile' extract " + echo -n "*** ERROR: cannot guess $curfile extract " echo "suffix ***" exit 1 ;; @@ -432,20 +454,20 @@ extract_distfiles() # Verifies that file's checksum downloaded matches what it's specified # in template file. # -verify_rmd160_cksum() +verify_sha256_cksum() { local file="$1" local origsum="$2" [ -z "$file" -o -z "$cksum" ] && return 1 - filesum="$($cksum_cmd $XBPS_SRCDISTDIR/$file | $awk_cmd '{print $4}')" + filesum=$($XBPS_DIGEST_CMD $XBPS_SRCDISTDIR/$file) if [ "$origsum" != "$filesum" ]; then - echo "*** ERROR: RMD160 checksum doesn't match for \`$file' ***" + echo "*** ERROR: SHA256 checksum doesn't match for $file ***" exit 1 fi - echo "=> checksum (RMD160) OK for \`$file'." + echo "=> SHA256 checksum OK for $file." } # @@ -487,7 +509,7 @@ fetch_distfiles() exit 1 fi - verify_rmd160_cksum $curfile $cksum + verify_sha256_cksum $curfile $cksum if [ $? -eq 0 ]; then unset cksum found ckcount=0 @@ -537,7 +559,7 @@ fetch_distfiles() exit 1 fi - verify_rmd160_cksum $curfile $cksum + verify_sha256_cksum $curfile $cksum if [ $? -eq 0 ]; then unset cksum found ckcount=0 @@ -565,7 +587,7 @@ fixup_tmpl_libtool() $ln_cmd -s $XBPS_MASTERDIR/bin/libtool $wrksrc/libtool fi - for f in $($find_cmd $wrksrc -type f -name libtool\*); do + for f in $($find_cmd $wrksrc -type f -name libtool); do if [ -f $f ]; then $rm_cmd -f $f $ln_cmd -s $XBPS_MASTERDIR/bin/libtool $f @@ -606,7 +628,7 @@ apply_tmpl_patches() for i in ${patch_files}; do patch="$XBPS_TEMPLATESDIR/$i" if [ ! -f "$patch" ]; then - echo "*** WARNING: unexistent patch '$i' ***" + echo "*** WARNING: unexistent patch: $i ***" continue fi @@ -622,16 +644,15 @@ apply_tmpl_patches() elif $(echo $patch|$grep_cmd -q .diff); then patch=$i else - echo "*** WARNING: unknown patch type '$i' ***" + echo "*** WARNING: unknown patch type: $i ***" continue fi - cd $wrksrc && $patch_cmd < $patch 2>/dev/null + cd $wrksrc && $patch_cmd -p0 < $patch 2>/dev/null if [ "$?" -eq 0 ]; then - echo "=> Patch applied: \`$i'." + echo "=> Patch applied: $i." else - echo -n "*** ERROR: couldn't apply patch '$i'," - echo " aborting ***" + echo "*** ERROR: couldn't apply patch: $i." exit 1 fi done @@ -656,14 +677,14 @@ configure_src_phase() [ "$build_style" = "meta-template" ] && return 0 if [ ! -d $wrksrc ]; then - echo "*** ERROR: unexistent build directory \`$wrksrc' ***" + echo "*** ERROR: unexistent build directory $wrksrc ***" exit 1 fi # Apply patches if requested by template file [ ! -f $XBPS_APPLYPATCHES_DONE ] && apply_tmpl_patches - echo "=> Running \`\`configure´´ phase for \`$pkgname-$version'." + echo "=> Running configure phase for $pkgname-$version." # Run stuff before configure. local rbcf="$XBPS_TEMPLATESDIR/$pkgname-runstuff-before-configure.sh" @@ -723,12 +744,12 @@ configure_src_phase() # Unknown build_style type won't work :-) # else - echo "*** ERROR unknown build_style \`$build_style' ***" + echo "*** ERROR unknown build_style: $build_style ***" exit 1 fi if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then - echo "*** ERROR building (configure state) \`$pkg' ***" + echo "*** ERROR building (configure state) $pkg ***" exit 1 fi @@ -760,13 +781,13 @@ build_src_phase() [ "$build_style" = "meta-template" ] && return 0 if [ ! -d $wrksrc ]; then - echo "*** ERROR: unexistent build directory \`$wrksrc' ***" + echo "*** ERROR: unexistent build directory: $wrksrc ***" exit 1 fi cd $wrksrc || exit 1 - echo "=> Running \`\`build´´ phase for \`$pkg'." + echo "=> Running build phase for $pkg." # # Assume BSD make if make_cmd not set in template. @@ -796,7 +817,7 @@ build_src_phase() # ${make_cmd} ${makejobs} ${make_build_args} ${make_build_target} if [ "$?" -ne 0 ]; then - echo "*** ERROR building (make stage) \`$pkg' ***" + echo "*** ERROR building (make stage) $pkg ***" exit 1 fi @@ -832,16 +853,16 @@ install_src_phase() [ "$build_style" = "meta-template" ] && return 0 if [ ! -d $wrksrc ]; then - echo "*** ERROR: unexistent build directory \`$wrksrc' ***" + echo "*** ERROR: unexistent build directory: $wrksrc ***" exit 1 fi cd $wrksrc || exit 1 - echo "=> Running \`\`install´´ phase for: \`$pkgname-$version´." + echo "=> Running install phase for: $pkgname-$version." [ -z "$make_install_prefix" ] && \ - make_install_prefix="prefix=\"$XBPS_DESTDIR/$pkgname-$version\"" + make_install_prefix="prefix=$XBPS_DESTDIR/$pkgname-$version" # # Install package via make. @@ -849,7 +870,7 @@ install_src_phase() ${make_cmd} ${make_install_args} ${make_install_target} \ ${make_install_prefix} if [ "$?" -ne 0 ]; then - echo "*** ERROR instaling \`$pkgname-$version' ***" + echo "*** ERROR installing $pkgname-$version ***" exit 1 fi @@ -880,7 +901,7 @@ install_src_phase() # Unset build vars. unset_build_vars - echo "==> Installed \`$pkgname-$version' into $XBPS_DESTDIR." + echo "==> Installed $pkgname-$version into $XBPS_DESTDIR." $touch_cmd -f $XBPS_INSTALL_DONE @@ -890,7 +911,7 @@ install_src_phase() if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then $rm_cmd -rf $wrksrc [ "$?" -eq 0 ] && \ - echo "=> Removed \`$pkgname-$version' build directory." + echo "=> Removed $pkgname-$version build directory." fi cd $XBPS_BUILDDIR @@ -908,19 +929,11 @@ register_pkg_handler() [ -z "$action" -o -z "$pkg" -o -z "$version" ] && return 1 if [ "$action" = "register" ]; then - $db_cmd -w btree $XBPS_REGPKG_DB $pkg $version 2>&1 >/dev/null - if [ "$?" -ne 0 ]; then - echo -n "*** ERROR: couldn't register \`$pkg'" - echo " in db file ***" - exit 1 - fi + $XBPS_PKGDB_CMD register $pkg $version + [ $? -ne 0 ] && exit 1 elif [ "$action" = "unregister" ]; then - $db_cmd -d btree $XBPS_REGPKG_DB $pkg 2>&1 >/dev/null - if [ "$?" -ne 0 ]; then - echo -n "*** ERROR: \`$pkg' not registered " - echo "in db file? ***" - exit 1 - fi + $XBPS_PKGDB_CMD unregister $pkg $version + [ $? -ne 0 ] && exit 1 else return 1 fi @@ -937,32 +950,32 @@ add_dependency_tolist() [ -z "$curpkg" ] && return 1 [ -n "$prev_pkg" ] && curpkg=$prev_pkg - for i in $($db_cmd -V btree $XBPS_BUILD_DEPS_DB ${curpkg%-[0-9]*.*}); do + reset_tmpl_vars + run_file $XBPS_TEMPLATESDIR/${curpkg%-[0-9]*.*}.tmpl + for i in ${build_depends}; do # # Check if dep already installed. # - if [ -r "$XBPS_REGPKG_DB" ]; then - check_installed_pkg $i ${i##[aA-zZ]*-} - # - # If dep is already installed, check one more time - # if all its deps are there and continue. - # - if [ $? -eq 0 ]; then - install_builddeps_required_pkg $i - installed_deps_list="$i $installed_deps_list" - continue - fi + check_installed_pkg $i ${i##[aA-zZ]*-} + # + # If dep is already installed, check one more time + # if all its deps are there and continue. + # + if [ $? -eq 0 ]; then + install_builddeps_required_pkg $i + installed_deps_list="$i $installed_deps_list" + continue + fi - deps_list="$i $deps_list" - [ -n "$prev_pkg" ] && unset prev_pkg - # - # Check if dependency needs more deps. - # - check_build_depends_pkg ${i%-[0-9]*.*} - if [ $? -eq 0 ]; then - add_dependency_tolist $i - prev_pkg="$i" - fi + deps_list="$i $deps_list" + [ -n "$prev_pkg" ] && unset prev_pkg + # + # Check if dependency needs more deps. + # + check_build_depends_pkg ${i%-[0-9]*.*} + if [ $? -eq 0 ]; then + add_dependency_tolist $i + prev_pkg="$i" fi done } @@ -1029,7 +1042,7 @@ install_dependencies_pkg() doing_deps=true - echo -n "=> Calculating dependency list for '$pkgname-$version'... " + echo -n "=> Calculating dependency list for $pkgname-$version... " add_dependency_tolist $pkg find_dupdeps_inlist installed find_dupdeps_inlist notinstalled @@ -1039,7 +1052,7 @@ install_dependencies_pkg() echo "==> Required dependencies for $(basename $pkg):" for i in ${installed_deps_list}; do - fpkg="$($db_cmd -O '-' btree $XBPS_REGPKG_DB ${i%-[0-9]*.*})" + fpkg="$($XBPS_PKGDB_CMD list|$grep_cmd ${i%-[0-9]*.*})" echo " $i: found $fpkg." done @@ -1052,7 +1065,7 @@ install_dependencies_pkg() check_installed_pkg $i ${i##[aA-zZ]*-} [ $? -eq 0 ] && continue # continue installing deps - echo "==> Installing \`$pkg´ dependency: \`$i´." + echo "==> Installing $pkg dependency: $i." install_pkg ${i%-[0-9]*.*} done @@ -1066,10 +1079,14 @@ install_builddeps_required_pkg() [ -z "$pkg" ] && return 1 - for dep in $($db_cmd -V btree $XBPS_BUILD_DEPS_DB ${pkg%-[0-9]*.*}); do + if [ "$pkgname" != "${pkg%-[0-9]*.*}" ]; then + run_file $XBPS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl + fi + + for dep in ${build_depends}; do check_installed_pkg $dep ${dep##[aA-zZ]*-} if [ $? -ne 0 ]; then - echo "==> Installing \`$pkg´ dependency: $dep." + echo "==> Installing $pkg dependency: $dep." install_pkg ${dep%-[0-9]*.*} fi done @@ -1085,7 +1102,7 @@ check_installed_pkg() local reqver="$2" local iver= - [ -z "$pkg" -o -z "$reqver" -o ! -r $XBPS_REGPKG_DB ] && return 1 + [ -z "$pkg" -o -z "$reqver" -o ! -r $XBPS_PKGDB_FPATH ] && return 1 if [ "$pkgname" != "${pkg%-[0-9]*.*}" ]; then run_file $XBPS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl @@ -1093,12 +1110,12 @@ check_installed_pkg() reqver="$(echo $reqver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')" - $db_cmd -K btree $XBPS_REGPKG_DB $pkgname 2>&1 >/dev/null + $XBPS_PKGDB_CMD installed $pkgname if [ $? -eq 0 ]; then # # Package is installed, let's check the version. # - iver="$($db_cmd -V btree $XBPS_REGPKG_DB $pkgname)" + iver="$($XBPS_PKGDB_CMD version $pkgname)" if [ -n "$iver" ]; then # # As shell only supports decimal arith expressions, @@ -1125,10 +1142,18 @@ check_build_depends_pkg() { local pkg="$1" - [ -z $pkg -o ! -r $XBPS_BUILD_DEPS_DB ] && return 1 + [ -z $pkg ] && return 1 - $db_cmd -V btree $XBPS_BUILD_DEPS_DB ${pkg%-[0-9]*.*} 2>&1 >/dev/null - return $? + if [ "$pkgname" != "${pkg%-[0-9]*.*}" ]; then + reset_tmpl_vars + run_file $XBPS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl + fi + + if [ -n "$build_depends" ]; then + return 0 + fi + + return 1 } # @@ -1141,7 +1166,7 @@ install_pkg() local cur_tmpl="$XBPS_TEMPLATESDIR/$curpkgn.tmpl" if [ -z $cur_tmpl -o ! -f $cur_tmpl ]; then - echo "*** ERROR: cannot find \`$cur_tmpl´ template file ***" + echo "*** ERROR: cannot find $cur_tmpl template file ***" exit 1 fi @@ -1203,7 +1228,7 @@ install_pkg() # if [ "$build_style" = "meta-template" ]; then register_pkg_handler register $pkgname $version - echo "==> Installed meta-template \`$pkg'." + echo "==> Installed meta-template: $pkg." return 0 fi @@ -1254,15 +1279,15 @@ install_xstow_pkg() # list_pkgs() { - if [ ! -r "$XBPS_REGPKG_DB" ]; then + if [ ! -r "$XBPS_PKGDB_FPATH" ]; then echo "=> No packages registered or missing register db file." exit 0 fi - for i in $($db_cmd -K btree $XBPS_REGPKG_DB); do + for i in $($XBPS_PKGDB_CMD list); do # Run file to get short_desc and print something useful - run_file $XBPS_TEMPLATESDIR/$i.tmpl - echo "$i-$version $short_desc" + run_file $XBPS_TEMPLATESDIR/${i%-[0-9]*.*}.tmpl + echo "$i $short_desc" reset_tmpl_vars done } @@ -1280,7 +1305,7 @@ list_pkg_files() fi if [ ! -d "$XBPS_DESTDIR/$pkg" ]; then - echo "*** ERROR: cannot find \`$pkg' in $XBPS_DESTDIR ***" + echo "*** ERROR: cannot find $pkg in $XBPS_DESTDIR ***" exit 1 fi @@ -1314,7 +1339,7 @@ remove_pkg() if [ "$build_style" = "meta-template" ]; then register_pkg_handler unregister $pkgname $version [ $? -eq 0 ] && \ - echo "=> Removed meta-template \`$pkg'." + echo "=> Removed meta-template: $pkg." return $? fi @@ -1372,10 +1397,10 @@ stow_pkg() -dir $XBPS_DESTDIR -target $XBPS_MASTERDIR \ $XBPS_DESTDIR/$pkg if [ "$?" -ne 0 ]; then - echo "*** ERROR: couldn't create symlinks for \`$pkg' ***" + echo "*** ERROR: couldn't create symlinks for $pkg ***" exit 1 else - echo "==> Created \`$pkg' symlinks into master directory." + echo "==> Created $pkg symlinks into master directory." fi register_pkg_handler register $pkgname $version @@ -1411,7 +1436,7 @@ unstow_pkg() fi if [ "$pkg" = "xstow" ]; then - echo "*** INFO: You aren't allowed to unstow \`$pkg'." + echo "*** INFO: You aren't allowed to unstow $pkg." exit 1 fi @@ -1446,7 +1471,7 @@ unstow_pkg() # # main() # -args=$(getopt Cc $*) +args=$(getopt Cc: $*) [ "$?" -ne 0 ] && usage set -- $args @@ -1543,7 +1568,7 @@ unstow) unstow_pkg $2 ;; *) - echo "*** ERROR: invalid target \`$target' ***" + echo "*** ERROR: invalid target: $target ***" usage esac