Add 'lcthw-remnants/' from commit 'e172f73c8297b22a579c94558f0c171ca74a0e5c'
git-subtree-dir: lcthw-remnants git-subtree-mainline:4107485591
git-subtree-split:e172f73c82
This commit is contained in:
1
lcthw-remnants/devpkg/.gitignore
vendored
Normal file
1
lcthw-remnants/devpkg/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
devpkg
|
16
lcthw-remnants/devpkg/Makefile
Normal file
16
lcthw-remnants/devpkg/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
PREFIX?=/usr/local
|
||||
CFLAGS=-g -Wall -I${PREFIX}/apr/include/apr-1 -D_LARGEFILE64_SOURCE
|
||||
LDFLAGS=-L${PREFIX}/apr/lib -lapr-1 -pthread -laprutil-1
|
||||
|
||||
all: devpkg
|
||||
|
||||
devpkg: bstrlib.o db.o shell.o commands.o
|
||||
|
||||
install: all
|
||||
install -d $(DESTDIR)/$(PREFIX)/bin/
|
||||
install devpkg $(DESTDIR)/$(PREFIX)/bin/
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f devpkg
|
||||
rm -rf *.dSYM
|
0
lcthw-remnants/devpkg/README
Normal file
0
lcthw-remnants/devpkg/README
Normal file
7
lcthw-remnants/devpkg/apr_errno_test.c
Normal file
7
lcthw-remnants/devpkg/apr_errno_test.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <apr_errno.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
2979
lcthw-remnants/devpkg/bstrlib.c
Normal file
2979
lcthw-remnants/devpkg/bstrlib.c
Normal file
File diff suppressed because it is too large
Load Diff
304
lcthw-remnants/devpkg/bstrlib.h
Normal file
304
lcthw-remnants/devpkg/bstrlib.h
Normal file
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
* This source file is part of the bstring string library. This code was
|
||||
* written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause
|
||||
* BSD open source license or GPL v2.0. Refer to the accompanying documentation
|
||||
* for details on usage and license.
|
||||
*/
|
||||
|
||||
/*
|
||||
* bstrlib.h
|
||||
*
|
||||
* This file is the header file for the core module for implementing the
|
||||
* bstring functions.
|
||||
*/
|
||||
|
||||
#ifndef BSTRLIB_INCLUDE
|
||||
#define BSTRLIB_INCLUDE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
|
||||
# if defined (__TURBOC__) && !defined (__BORLANDC__)
|
||||
# define BSTRLIB_NOVSNP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BSTR_ERR (-1)
|
||||
#define BSTR_OK (0)
|
||||
#define BSTR_BS_BUFF_LENGTH_GET (0)
|
||||
|
||||
typedef struct tagbstring * bstring;
|
||||
typedef const struct tagbstring * const_bstring;
|
||||
|
||||
/* Copy functions */
|
||||
#define cstr2bstr bfromcstr
|
||||
extern bstring bfromcstr (const char * str);
|
||||
extern bstring bfromcstralloc (int mlen, const char * str);
|
||||
extern bstring blk2bstr (const void * blk, int len);
|
||||
extern char * bstr2cstr (const_bstring s, char z);
|
||||
extern int bcstrfree (char * s);
|
||||
extern bstring bstrcpy (const_bstring b1);
|
||||
extern int bassign (bstring a, const_bstring b);
|
||||
extern int bassignmidstr (bstring a, const_bstring b, int left, int len);
|
||||
extern int bassigncstr (bstring a, const char * str);
|
||||
extern int bassignblk (bstring a, const void * s, int len);
|
||||
|
||||
/* Destroy function */
|
||||
extern int bdestroy (bstring b);
|
||||
|
||||
/* Space allocation hinting functions */
|
||||
extern int balloc (bstring s, int len);
|
||||
extern int ballocmin (bstring b, int len);
|
||||
|
||||
/* Substring extraction */
|
||||
extern bstring bmidstr (const_bstring b, int left, int len);
|
||||
|
||||
/* Various standard manipulations */
|
||||
extern int bconcat (bstring b0, const_bstring b1);
|
||||
extern int bconchar (bstring b0, char c);
|
||||
extern int bcatcstr (bstring b, const char * s);
|
||||
extern int bcatblk (bstring b, const void * s, int len);
|
||||
extern int binsert (bstring s1, int pos, const_bstring s2, unsigned char fill);
|
||||
extern int binsertch (bstring s1, int pos, int len, unsigned char fill);
|
||||
extern int breplace (bstring b1, int pos, int len, const_bstring b2, unsigned char fill);
|
||||
extern int bdelete (bstring s1, int pos, int len);
|
||||
extern int bsetstr (bstring b0, int pos, const_bstring b1, unsigned char fill);
|
||||
extern int btrunc (bstring b, int n);
|
||||
|
||||
/* Scan/search functions */
|
||||
extern int bstricmp (const_bstring b0, const_bstring b1);
|
||||
extern int bstrnicmp (const_bstring b0, const_bstring b1, int n);
|
||||
extern int biseqcaseless (const_bstring b0, const_bstring b1);
|
||||
extern int bisstemeqcaselessblk (const_bstring b0, const void * blk, int len);
|
||||
extern int biseq (const_bstring b0, const_bstring b1);
|
||||
extern int bisstemeqblk (const_bstring b0, const void * blk, int len);
|
||||
extern int biseqcstr (const_bstring b, const char * s);
|
||||
extern int biseqcstrcaseless (const_bstring b, const char * s);
|
||||
extern int bstrcmp (const_bstring b0, const_bstring b1);
|
||||
extern int bstrncmp (const_bstring b0, const_bstring b1, int n);
|
||||
extern int binstr (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int binstrr (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int binstrcaseless (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int binstrrcaseless (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int bstrchrp (const_bstring b, int c, int pos);
|
||||
extern int bstrrchrp (const_bstring b, int c, int pos);
|
||||
#define bstrchr(b,c) bstrchrp ((b), (c), 0)
|
||||
#define bstrrchr(b,c) bstrrchrp ((b), (c), blength(b)-1)
|
||||
extern int binchr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int binchrr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int bninchr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int bninchrr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int bfindreplace (bstring b, const_bstring find, const_bstring repl, int pos);
|
||||
extern int bfindreplacecaseless (bstring b, const_bstring find, const_bstring repl, int pos);
|
||||
|
||||
/* List of string container functions */
|
||||
struct bstrList {
|
||||
int qty, mlen;
|
||||
bstring * entry;
|
||||
};
|
||||
extern struct bstrList * bstrListCreate (void);
|
||||
extern int bstrListDestroy (struct bstrList * sl);
|
||||
extern int bstrListAlloc (struct bstrList * sl, int msz);
|
||||
extern int bstrListAllocMin (struct bstrList * sl, int msz);
|
||||
|
||||
/* String split and join functions */
|
||||
extern struct bstrList * bsplit (const_bstring str, unsigned char splitChar);
|
||||
extern struct bstrList * bsplits (const_bstring str, const_bstring splitStr);
|
||||
extern struct bstrList * bsplitstr (const_bstring str, const_bstring splitStr);
|
||||
extern bstring bjoin (const struct bstrList * bl, const_bstring sep);
|
||||
extern int bsplitcb (const_bstring str, unsigned char splitChar, int pos,
|
||||
int (* cb) (void * parm, int ofs, int len), void * parm);
|
||||
extern int bsplitscb (const_bstring str, const_bstring splitStr, int pos,
|
||||
int (* cb) (void * parm, int ofs, int len), void * parm);
|
||||
extern int bsplitstrcb (const_bstring str, const_bstring splitStr, int pos,
|
||||
int (* cb) (void * parm, int ofs, int len), void * parm);
|
||||
|
||||
/* Miscellaneous functions */
|
||||
extern int bpattern (bstring b, int len);
|
||||
extern int btoupper (bstring b);
|
||||
extern int btolower (bstring b);
|
||||
extern int bltrimws (bstring b);
|
||||
extern int brtrimws (bstring b);
|
||||
extern int btrimws (bstring b);
|
||||
|
||||
/* <*>printf format functions */
|
||||
#if !defined (BSTRLIB_NOVSNP)
|
||||
extern bstring bformat (const char * fmt, ...);
|
||||
extern int bformata (bstring b, const char * fmt, ...);
|
||||
extern int bassignformat (bstring b, const char * fmt, ...);
|
||||
extern int bvcformata (bstring b, int count, const char * fmt, va_list arglist);
|
||||
|
||||
#define bvformata(ret, b, fmt, lastarg) { \
|
||||
bstring bstrtmp_b = (b); \
|
||||
const char * bstrtmp_fmt = (fmt); \
|
||||
int bstrtmp_r = BSTR_ERR, bstrtmp_sz = 16; \
|
||||
for (;;) { \
|
||||
va_list bstrtmp_arglist; \
|
||||
va_start (bstrtmp_arglist, lastarg); \
|
||||
bstrtmp_r = bvcformata (bstrtmp_b, bstrtmp_sz, bstrtmp_fmt, bstrtmp_arglist); \
|
||||
va_end (bstrtmp_arglist); \
|
||||
if (bstrtmp_r >= 0) { /* Everything went ok */ \
|
||||
bstrtmp_r = BSTR_OK; \
|
||||
break; \
|
||||
} else if (-bstrtmp_r <= bstrtmp_sz) { /* A real error? */ \
|
||||
bstrtmp_r = BSTR_ERR; \
|
||||
break; \
|
||||
} \
|
||||
bstrtmp_sz = -bstrtmp_r; /* Doubled or target size */ \
|
||||
} \
|
||||
ret = bstrtmp_r; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef int (*bNgetc) (void *parm);
|
||||
typedef size_t (* bNread) (void *buff, size_t elsize, size_t nelem, void *parm);
|
||||
|
||||
/* Input functions */
|
||||
extern bstring bgets (bNgetc getcPtr, void * parm, char terminator);
|
||||
extern bstring bread (bNread readPtr, void * parm);
|
||||
extern int bgetsa (bstring b, bNgetc getcPtr, void * parm, char terminator);
|
||||
extern int bassigngets (bstring b, bNgetc getcPtr, void * parm, char terminator);
|
||||
extern int breada (bstring b, bNread readPtr, void * parm);
|
||||
|
||||
/* Stream functions */
|
||||
extern struct bStream * bsopen (bNread readPtr, void * parm);
|
||||
extern void * bsclose (struct bStream * s);
|
||||
extern int bsbufflength (struct bStream * s, int sz);
|
||||
extern int bsreadln (bstring b, struct bStream * s, char terminator);
|
||||
extern int bsreadlns (bstring r, struct bStream * s, const_bstring term);
|
||||
extern int bsread (bstring b, struct bStream * s, int n);
|
||||
extern int bsreadlna (bstring b, struct bStream * s, char terminator);
|
||||
extern int bsreadlnsa (bstring r, struct bStream * s, const_bstring term);
|
||||
extern int bsreada (bstring b, struct bStream * s, int n);
|
||||
extern int bsunread (struct bStream * s, const_bstring b);
|
||||
extern int bspeek (bstring r, const struct bStream * s);
|
||||
extern int bssplitscb (struct bStream * s, const_bstring splitStr,
|
||||
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
|
||||
extern int bssplitstrcb (struct bStream * s, const_bstring splitStr,
|
||||
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
|
||||
extern int bseof (const struct bStream * s);
|
||||
|
||||
struct tagbstring {
|
||||
int mlen;
|
||||
int slen;
|
||||
unsigned char * data;
|
||||
};
|
||||
|
||||
/* Accessor macros */
|
||||
#define blengthe(b, e) (((b) == (void *)0 || (b)->slen < 0) ? (int)(e) : ((b)->slen))
|
||||
#define blength(b) (blengthe ((b), 0))
|
||||
#define bdataofse(b, o, e) (((b) == (void *)0 || (b)->data == (void*)0) ? (char *)(e) : ((char *)(b)->data) + (o))
|
||||
#define bdataofs(b, o) (bdataofse ((b), (o), (void *)0))
|
||||
#define bdatae(b, e) (bdataofse (b, 0, e))
|
||||
#define bdata(b) (bdataofs (b, 0))
|
||||
#define bchare(b, p, e) ((((unsigned)(p)) < (unsigned)blength(b)) ? ((b)->data[(p)]) : (e))
|
||||
#define bchar(b, p) bchare ((b), (p), '\0')
|
||||
|
||||
/* Static constant string initialization macro */
|
||||
#define bsStaticMlen(q,m) {(m), (int) sizeof(q)-1, (unsigned char *) ("" q "")}
|
||||
#if defined(_MSC_VER)
|
||||
/* There are many versions of MSVC which emit __LINE__ as a non-constant. */
|
||||
# define bsStatic(q) bsStaticMlen(q,-32)
|
||||
#endif
|
||||
#ifndef bsStatic
|
||||
# define bsStatic(q) bsStaticMlen(q,-__LINE__)
|
||||
#endif
|
||||
|
||||
/* Static constant block parameter pair */
|
||||
#define bsStaticBlkParms(q) ((void *)("" q "")), ((int) sizeof(q)-1)
|
||||
|
||||
/* Reference building macros */
|
||||
#define cstr2tbstr btfromcstr
|
||||
#define btfromcstr(t,s) { \
|
||||
(t).data = (unsigned char *) (s); \
|
||||
(t).slen = ((t).data) ? ((int) (strlen) ((char *)(t).data)) : 0; \
|
||||
(t).mlen = -1; \
|
||||
}
|
||||
#define blk2tbstr(t,s,l) { \
|
||||
(t).data = (unsigned char *) (s); \
|
||||
(t).slen = l; \
|
||||
(t).mlen = -1; \
|
||||
}
|
||||
#define btfromblk(t,s,l) blk2tbstr(t,s,l)
|
||||
#define bmid2tbstr(t,b,p,l) { \
|
||||
const_bstring bstrtmp_s = (b); \
|
||||
if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
|
||||
int bstrtmp_left = (p); \
|
||||
int bstrtmp_len = (l); \
|
||||
if (bstrtmp_left < 0) { \
|
||||
bstrtmp_len += bstrtmp_left; \
|
||||
bstrtmp_left = 0; \
|
||||
} \
|
||||
if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) \
|
||||
bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
|
||||
if (bstrtmp_len <= 0) { \
|
||||
(t).data = (unsigned char *)""; \
|
||||
(t).slen = 0; \
|
||||
} else { \
|
||||
(t).data = bstrtmp_s->data + bstrtmp_left; \
|
||||
(t).slen = bstrtmp_len; \
|
||||
} \
|
||||
} else { \
|
||||
(t).data = (unsigned char *)""; \
|
||||
(t).slen = 0; \
|
||||
} \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
#define btfromblkltrimws(t,s,l) { \
|
||||
int bstrtmp_idx = 0, bstrtmp_len = (l); \
|
||||
unsigned char * bstrtmp_s = (s); \
|
||||
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
||||
for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
|
||||
} \
|
||||
} \
|
||||
(t).data = bstrtmp_s + bstrtmp_idx; \
|
||||
(t).slen = bstrtmp_len - bstrtmp_idx; \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
#define btfromblkrtrimws(t,s,l) { \
|
||||
int bstrtmp_len = (l) - 1; \
|
||||
unsigned char * bstrtmp_s = (s); \
|
||||
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
||||
for (; bstrtmp_len >= 0; bstrtmp_len--) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
|
||||
} \
|
||||
} \
|
||||
(t).data = bstrtmp_s; \
|
||||
(t).slen = bstrtmp_len + 1; \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
#define btfromblktrimws(t,s,l) { \
|
||||
int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
|
||||
unsigned char * bstrtmp_s = (s); \
|
||||
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
||||
for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
|
||||
} \
|
||||
for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
|
||||
} \
|
||||
} \
|
||||
(t).data = bstrtmp_s + bstrtmp_idx; \
|
||||
(t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
|
||||
/* Write protection macros */
|
||||
#define bwriteprotect(t) { if ((t).mlen >= 0) (t).mlen = -1; }
|
||||
#define bwriteallow(t) { if ((t).mlen == -1) (t).mlen = (t).slen + ((t).slen == 0); }
|
||||
#define biswriteprotected(t) ((t).mlen <= 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
175
lcthw-remnants/devpkg/commands.c
Normal file
175
lcthw-remnants/devpkg/commands.c
Normal file
@@ -0,0 +1,175 @@
|
||||
#include <apr_uri.h>
|
||||
#include <apr_fnmatch.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "dbg.h"
|
||||
#include "bstrlib.h"
|
||||
#include "db.h"
|
||||
#include "shell.h"
|
||||
|
||||
|
||||
int Command_depends(apr_pool_t *p, const char *path)
|
||||
{
|
||||
FILE *in = NULL;
|
||||
bstring line = NULL;
|
||||
|
||||
in = fopen(path, "r");
|
||||
check(in != NULL, "Failed to open downloaded depends: %s", path);
|
||||
|
||||
for(line = bgets((bNgetc)fgetc, in, '\n'); line != NULL;
|
||||
line = bgets((bNgetc)fgetc, in, '\n'))
|
||||
{
|
||||
btrimws(line);
|
||||
log_info("Processing depends: %s", bdata(line));
|
||||
int rc = Command_install(p, bdata(line), NULL, NULL, NULL);
|
||||
check(rc == 0, "Failed to install: %s", bdata(line));
|
||||
bdestroy(line);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if(line) bdestroy(line);
|
||||
if(in) fclose(in);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int Command_fetch(apr_pool_t *p, const char *url, int fetch_only)
|
||||
{
|
||||
apr_uri_t info = {.port = 0};
|
||||
int rc = 0;
|
||||
const char *depends_file = NULL;
|
||||
apr_status_t rv = apr_uri_parse(p, url, &info);
|
||||
|
||||
check(rv == APR_SUCCESS, "Failed to parse URL: %s", url);
|
||||
|
||||
if(apr_fnmatch(GIT_PAT, info.path, 0) == APR_SUCCESS) {
|
||||
rc = Shell_exec(GIT_SH, "URL", url, NULL);
|
||||
check(rc == 0, "git failed.");
|
||||
} else if(apr_fnmatch(DEPEND_PAT, info.path, 0) == APR_SUCCESS) {
|
||||
check(!fetch_only, "No point in fetching a DEPENDS file.");
|
||||
|
||||
if(info.scheme) {
|
||||
depends_file = DEPENDS_PATH;
|
||||
rc = Shell_exec(CURL_SH, "URL", url, "TARGET", depends_file, NULL);
|
||||
check(rc == 0, "Curl failed.");
|
||||
} else {
|
||||
depends_file = info.path;
|
||||
}
|
||||
|
||||
// recursively process the devpkg list
|
||||
log_info("Building according to DEPENDS: %s", url);
|
||||
rv = Command_depends(p, depends_file);
|
||||
check(rv == 0, "Failed to process the DEPENDS: %s", url);
|
||||
|
||||
// this indicates that nothing needs to be done
|
||||
return 0;
|
||||
|
||||
} else if(apr_fnmatch(TAR_GZ_PAT, info.path, 0) == APR_SUCCESS) {
|
||||
if(info.scheme) {
|
||||
rc = Shell_exec(CURL_SH,
|
||||
"URL", url,
|
||||
"TARGET", TAR_GZ_SRC, NULL);
|
||||
check(rc == 0, "Failed to curl source: %s", url);
|
||||
}
|
||||
|
||||
rv = apr_dir_make_recursive(BUILD_DIR,
|
||||
APR_UREAD | APR_UWRITE | APR_UEXECUTE, p);
|
||||
check(rv == APR_SUCCESS, "Failed to make directory %s", BUILD_DIR);
|
||||
|
||||
rc = Shell_exec(TAR_SH, "FILE", TAR_GZ_SRC, NULL);
|
||||
check(rc == 0, "Failed to untar %s", TAR_GZ_SRC);
|
||||
} else if(apr_fnmatch(TAR_BZ2_PAT, info.path, 0) == APR_SUCCESS) {
|
||||
if(info.scheme) {
|
||||
rc = Shell_exec(CURL_SH, "URL", url, "TARGET", TAR_BZ2_SRC, NULL);
|
||||
check(rc == 0, "Curl failed.");
|
||||
}
|
||||
|
||||
apr_status_t rc = apr_dir_make_recursive(BUILD_DIR,
|
||||
APR_UREAD | APR_UWRITE | APR_UEXECUTE, p);
|
||||
|
||||
check(rc == 0, "Failed to make directory %s", BUILD_DIR);
|
||||
rc = Shell_exec(TAR_SH, "FILE", TAR_BZ2_SRC, NULL);
|
||||
check(rc == 0, "Failed to untar %s", TAR_BZ2_SRC);
|
||||
} else {
|
||||
sentinel("Don't know how to handle %s", url);
|
||||
}
|
||||
|
||||
// indicates that an install needs to actually run
|
||||
return 1;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Command_build(apr_pool_t *p, const char *url, const char *configure_opts,
|
||||
const char *make_opts, const char *install_opts)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
check(access(BUILD_DIR, X_OK | R_OK | W_OK) == 0,
|
||||
"Build directory doesn't exist: %s", BUILD_DIR);
|
||||
|
||||
// actually do an install
|
||||
if(access(CONFIG_SCRIPT, X_OK) == 0) {
|
||||
log_info("Has a configure script, running it.");
|
||||
rc = Shell_exec(CONFIGURE_SH, "OPTS", configure_opts, NULL);
|
||||
check(rc == 0, "Failed to configure.");
|
||||
}
|
||||
|
||||
rc = Shell_exec(MAKE_SH, "OPTS", make_opts, NULL);
|
||||
check(rc == 0, "Failed to build.");
|
||||
|
||||
rc = Shell_exec(INSTALL_SH,
|
||||
"TARGET", install_opts ? install_opts : "install",
|
||||
NULL);
|
||||
check(rc == 0, "Failed to install.");
|
||||
|
||||
rc = Shell_exec(CLEANUP_SH, NULL);
|
||||
check(rc == 0, "Failed to cleanup after build.");
|
||||
|
||||
rc = DB_update(url);
|
||||
check(rc == 0, "Failed to add this package to the database.");
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Command_install(apr_pool_t *p, const char *url, const char *configure_opts,
|
||||
const char *make_opts, const char *install_opts)
|
||||
{
|
||||
int rc = 0;
|
||||
check(Shell_exec(CLEANUP_SH, NULL) == 0, "Failed to cleanup before building.");
|
||||
|
||||
rc = DB_find(url);
|
||||
check(rc != -1, "Error checking the install database.");
|
||||
|
||||
if(rc == 1) {
|
||||
log_info("Package %s already installed.", url);
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = Command_fetch(p, url, 0);
|
||||
if(rc == 1) {
|
||||
rc = Command_build(p, url, configure_opts, make_opts, install_opts);
|
||||
check(rc == 0, "Failed to build: %s", url);
|
||||
} else if(rc == 0) {
|
||||
// no install needed
|
||||
log_info("Depends successfully installed: %s", url);
|
||||
} else {
|
||||
// had an error
|
||||
sentinel("Install failed: %s", url);
|
||||
}
|
||||
|
||||
Shell_exec(CLEANUP_SH, NULL);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
Shell_exec(CLEANUP_SH, NULL);
|
||||
return -1;
|
||||
}
|
32
lcthw-remnants/devpkg/commands.h
Normal file
32
lcthw-remnants/devpkg/commands.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _commands_h
|
||||
#define _commands_h
|
||||
|
||||
#include <apr_pools.h>
|
||||
|
||||
#define DEPENDS_PATH "/tmp/DEPENDS"
|
||||
#define TAR_GZ_SRC "/tmp/pkg-src.tar.gz"
|
||||
#define TAR_BZ2_SRC "/tmp/pkg-src.tar.bz2"
|
||||
#define BUILD_DIR "/tmp/pkg-build"
|
||||
#define GIT_PAT "*.git"
|
||||
#define DEPEND_PAT "*DEPENDS"
|
||||
#define TAR_GZ_PAT "*.tar.gz"
|
||||
#define TAR_BZ2_PAT "*.tar.bz2"
|
||||
#define CONFIG_SCRIPT "/tmp/pkg-build/configure"
|
||||
|
||||
enum CommandType {
|
||||
COMMAND_NONE, COMMAND_INSTALL, COMMAND_LIST, COMMAND_FETCH,
|
||||
COMMAND_INIT, COMMAND_BUILD
|
||||
};
|
||||
|
||||
|
||||
int Command_fetch(apr_pool_t *p, const char *url, int fetch_only);
|
||||
|
||||
int Command_install(apr_pool_t *p, const char *url, const char *configure_opts,
|
||||
const char *make_opts, const char *install_opts);
|
||||
|
||||
int Command_depends(apr_pool_t *p, const char *path);
|
||||
|
||||
int Command_build(apr_pool_t *p, const char *url, const char *configure_opts,
|
||||
const char *make_opts, const char *install_opts);
|
||||
|
||||
#endif
|
124
lcthw-remnants/devpkg/db.c
Normal file
124
lcthw-remnants/devpkg/db.c
Normal file
@@ -0,0 +1,124 @@
|
||||
#include <unistd.h>
|
||||
#include <apr_errno.h>
|
||||
#include <apr_file_io.h>
|
||||
|
||||
#include "db.h"
|
||||
#include "bstrlib.h"
|
||||
#include "dbg.h"
|
||||
|
||||
static FILE *DB_open(const char *path, const char *mode)
|
||||
{
|
||||
return fopen(path, mode);
|
||||
}
|
||||
|
||||
|
||||
static void DB_close(FILE *db)
|
||||
{
|
||||
fclose(db);
|
||||
}
|
||||
|
||||
|
||||
static bstring DB_load(const char *path)
|
||||
{
|
||||
FILE *db = NULL;
|
||||
bstring data = NULL;
|
||||
|
||||
db = DB_open(DB_FILE, "r");
|
||||
check(db, "Failed to open database: %s", DB_FILE);
|
||||
|
||||
data = bread((bNread)fread, db);
|
||||
check(data, "Failed to read from db file: %s", DB_FILE);
|
||||
|
||||
DB_close(db);
|
||||
return data;
|
||||
|
||||
error:
|
||||
if(db) DB_close(db);
|
||||
if(data) bdestroy(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int DB_update(const char *url)
|
||||
{
|
||||
if(DB_find(url)) {
|
||||
log_info("Already recorded as installed: %s", url);
|
||||
}
|
||||
|
||||
FILE *db = DB_open(DB_FILE, "a+");
|
||||
check(db, "Failed to open DB file: %s", DB_FILE);
|
||||
|
||||
bstring line = bfromcstr(url);
|
||||
bconchar(line, '\n');
|
||||
int rc = fwrite(line->data, blength(line), 1, db);
|
||||
check(rc == 1, "Failed to append to the db.");
|
||||
|
||||
return 0;
|
||||
error:
|
||||
if(db) DB_close(db);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DB_find(const char *url)
|
||||
{
|
||||
bstring data = NULL;
|
||||
bstring line = bfromcstr(url);
|
||||
int res = -1;
|
||||
|
||||
data = DB_load(DB_FILE);
|
||||
check(data, "Failed to load: %s", DB_FILE);
|
||||
|
||||
if(binstr(data, 0, line) == BSTR_ERR) {
|
||||
res = 0;
|
||||
} else {
|
||||
res = 1;
|
||||
}
|
||||
|
||||
error: //fallthrough
|
||||
if(data) bdestroy(data);
|
||||
if(line) bdestroy(line);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int DB_init()
|
||||
{
|
||||
apr_pool_t *p = NULL;
|
||||
apr_pool_initialize();
|
||||
apr_pool_create(&p, NULL);
|
||||
|
||||
if(access(DB_DIR, W_OK | X_OK) == -1) {
|
||||
apr_status_t rc = apr_dir_make_recursive(DB_DIR,
|
||||
APR_UREAD | APR_UWRITE | APR_UEXECUTE |
|
||||
APR_GREAD | APR_GWRITE | APR_GEXECUTE, p);
|
||||
check(rc == APR_SUCCESS, "Failed to make database dir: %s", DB_DIR);
|
||||
}
|
||||
|
||||
if(access(DB_FILE, W_OK) == -1) {
|
||||
FILE *db = DB_open(DB_FILE, "w");
|
||||
check(db, "Cannot open database: %s", DB_FILE);
|
||||
DB_close(db);
|
||||
}
|
||||
|
||||
apr_pool_destroy(p);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
apr_pool_destroy(p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DB_list()
|
||||
{
|
||||
bstring data = DB_load(DB_FILE);
|
||||
check(data, "Failed to read load: %s", DB_FILE);
|
||||
|
||||
printf("%s", bdata(data));
|
||||
bdestroy(data);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
13
lcthw-remnants/devpkg/db.h
Normal file
13
lcthw-remnants/devpkg/db.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _db_h
|
||||
#define _db_h
|
||||
|
||||
#define DB_FILE "/usr/local/.devpkg/db"
|
||||
#define DB_DIR "/usr/local/.devpkg"
|
||||
|
||||
|
||||
int DB_init();
|
||||
int DB_list();
|
||||
int DB_update(const char *url);
|
||||
int DB_find(const char *url);
|
||||
|
||||
#endif
|
1
lcthw-remnants/devpkg/dbg.h
Symbolic link
1
lcthw-remnants/devpkg/dbg.h
Symbolic link
@@ -0,0 +1 @@
|
||||
../dbg.h
|
105
lcthw-remnants/devpkg/devpkg.c
Normal file
105
lcthw-remnants/devpkg/devpkg.c
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <stdio.h>
|
||||
#include <apr_general.h>
|
||||
#include <apr_getopt.h>
|
||||
#include <apr_strings.h>
|
||||
#include <apr_lib.h>
|
||||
#include <apr_strings.h>
|
||||
|
||||
#include "dbg.h"
|
||||
#include "db.h"
|
||||
#include "commands.h"
|
||||
|
||||
|
||||
int main(int argc, const char const *argv[])
|
||||
{
|
||||
apr_pool_t *p = NULL;
|
||||
apr_pool_initialize();
|
||||
apr_pool_create(&p, NULL);
|
||||
|
||||
apr_getopt_t *opt;
|
||||
apr_status_t rv;
|
||||
|
||||
char ch = '\0';
|
||||
const char *optarg = NULL;
|
||||
const char *config_opts = NULL;
|
||||
const char *install_opts = NULL;
|
||||
const char *make_opts = NULL;
|
||||
const char *url = NULL;
|
||||
enum CommandType request = COMMAND_NONE;
|
||||
|
||||
rv = apr_getopt_init(&opt, p, argc, argv);
|
||||
|
||||
while(apr_getopt(opt, "I:Lc:m:i:d:SF:B:", &ch, &optarg) == APR_SUCCESS) {
|
||||
switch (ch) {
|
||||
case 'I':
|
||||
request = COMMAND_INSTALL;
|
||||
url = optarg;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
request = COMMAND_LIST;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
config_opts = optarg;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
make_opts = optarg;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
install_opts = optarg;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
request = COMMAND_INIT;
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
request = COMMAND_FETCH;
|
||||
url = optarg;
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
request = COMMAND_BUILD;
|
||||
url = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(request) {
|
||||
case COMMAND_INSTALL:
|
||||
check(url, "You must at least give a URL.");
|
||||
Command_install(p, url, config_opts, make_opts, install_opts);
|
||||
break;
|
||||
|
||||
case COMMAND_LIST:
|
||||
DB_list();
|
||||
break;
|
||||
|
||||
case COMMAND_FETCH:
|
||||
check(url != NULL, "You must give a URL.");
|
||||
Command_fetch(p, url, 1);
|
||||
log_info("Downloaded to %s and in /tmp/", BUILD_DIR);
|
||||
break;
|
||||
|
||||
case COMMAND_BUILD:
|
||||
check(url, "You must at least give a URL.");
|
||||
Command_build(p, url, config_opts, make_opts, install_opts);
|
||||
break;
|
||||
|
||||
case COMMAND_INIT:
|
||||
rv = DB_init();
|
||||
check(rv == 0, "Failed to make the database.");
|
||||
break;
|
||||
|
||||
default:
|
||||
sentinel("Invalid command given.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return 1;
|
||||
}
|
113
lcthw-remnants/devpkg/shell.c
Normal file
113
lcthw-remnants/devpkg/shell.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "shell.h"
|
||||
#include "dbg.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
int Shell_exec(Shell template, ...)
|
||||
{
|
||||
apr_pool_t *p = NULL;
|
||||
apr_pool_create(&p, NULL);
|
||||
|
||||
va_list argp;
|
||||
const char *key = NULL;
|
||||
const char *arg = NULL;
|
||||
int i = 0;
|
||||
|
||||
va_start(argp, template);
|
||||
|
||||
for(key = va_arg(argp, const char*);
|
||||
key != NULL;
|
||||
key = va_arg(argp, const char *))
|
||||
{
|
||||
arg = va_arg(argp, const char *);
|
||||
|
||||
for(i = 0; template.args[i] != NULL; i++) {
|
||||
if(strcmp(template.args[i], key) == 0) {
|
||||
template.args[i] = arg;
|
||||
break; // found it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int rc = Shell_run(p, &template);
|
||||
apr_pool_create(&p, NULL);
|
||||
va_end(argp);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int Shell_run(apr_pool_t *p, Shell *cmd)
|
||||
{
|
||||
apr_procattr_t *attr;
|
||||
apr_status_t rv;
|
||||
apr_proc_t newproc;
|
||||
|
||||
rv = apr_procattr_create(&attr, p);
|
||||
check(rv == APR_SUCCESS, "Failed to create proc attr.");
|
||||
|
||||
rv = apr_procattr_io_set(attr, APR_NO_PIPE, APR_NO_PIPE,
|
||||
APR_NO_PIPE);
|
||||
check(rv == APR_SUCCESS, "Failed to set IO of command.");
|
||||
|
||||
rv = apr_procattr_dir_set(attr, cmd->dir);
|
||||
check(rv == APR_SUCCESS, "Failed to set root to %s", cmd->dir);
|
||||
|
||||
rv = apr_procattr_cmdtype_set(attr, APR_PROGRAM_PATH);
|
||||
check(rv == APR_SUCCESS, "Failed to set cmd type.");
|
||||
|
||||
rv = apr_proc_create(&newproc, cmd->exe, cmd->args, NULL, attr, p);
|
||||
check(rv == APR_SUCCESS, "Failed to run command.");
|
||||
|
||||
rv = apr_proc_wait(&newproc, &cmd->exit_code, &cmd->exit_why, APR_WAIT);
|
||||
check(rv == APR_CHILD_DONE, "Failed to wait.");
|
||||
|
||||
check(cmd->exit_code == 0, "%s exited badly.", cmd->exe);
|
||||
check(cmd->exit_why == APR_PROC_EXIT, "%s was killed or crashed", cmd->exe);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
Shell CLEANUP_SH = {
|
||||
.exe = "rm",
|
||||
.dir = "/tmp",
|
||||
.args = {"rm", "-rf", "/tmp/pkg-build", "/tmp/pkg-src.tar.gz",
|
||||
"/tmp/pkg-src.tar.bz2", "/tmp/DEPENDS", NULL}
|
||||
};
|
||||
|
||||
Shell GIT_SH = {
|
||||
.dir = "/tmp",
|
||||
.exe = "git",
|
||||
.args = {"git", "clone", "URL", "pkg-build", NULL}
|
||||
};
|
||||
|
||||
Shell TAR_SH = {
|
||||
.dir = "/tmp/pkg-build",
|
||||
.exe = "tar",
|
||||
.args = {"tar", "-xzf", "FILE", "--strip-components", "1", NULL}
|
||||
};
|
||||
|
||||
Shell CURL_SH = {
|
||||
.dir = "/tmp",
|
||||
.exe = "curl",
|
||||
.args = {"curl", "-L", "-o", "TARGET", "URL", NULL}
|
||||
};
|
||||
|
||||
Shell CONFIGURE_SH = {
|
||||
.exe = "./configure",
|
||||
.dir = "/tmp/pkg-build",
|
||||
.args = {"configure", "OPTS", NULL}
|
||||
};
|
||||
|
||||
Shell MAKE_SH = {
|
||||
.exe = "make",
|
||||
.dir = "/tmp/pkg-build",
|
||||
.args = {"make", "OPTS", NULL}
|
||||
};
|
||||
|
||||
Shell INSTALL_SH = {
|
||||
.exe = "sudo",
|
||||
.dir = "/tmp/pkg-build",
|
||||
.args = {"sudo", "make", "TARGET", NULL}
|
||||
};
|
31
lcthw-remnants/devpkg/shell.h
Normal file
31
lcthw-remnants/devpkg/shell.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _shell_h
|
||||
#define _shell_h
|
||||
|
||||
#define MAX_COMMAND_ARGS 100
|
||||
|
||||
#include <apr_thread_proc.h>
|
||||
|
||||
typedef struct Shell {
|
||||
const char *dir;
|
||||
const char *exe;
|
||||
|
||||
apr_procattr_t *attr;
|
||||
apr_proc_t proc;
|
||||
apr_exit_why_e exit_why;
|
||||
int exit_code;
|
||||
|
||||
const char *args[MAX_COMMAND_ARGS];
|
||||
} Shell;
|
||||
|
||||
int Shell_run(apr_pool_t *p, Shell *cmd);
|
||||
int Shell_exec(Shell cmd, ...);
|
||||
|
||||
extern Shell CLEANUP_SH;
|
||||
extern Shell GIT_SH;
|
||||
extern Shell TAR_SH;
|
||||
extern Shell CURL_SH;
|
||||
extern Shell CONFIGURE_SH;
|
||||
extern Shell MAKE_SH;
|
||||
extern Shell INSTALL_SH;
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user