From e942062393d391aa815797b087ad70b04c415315 Mon Sep 17 00:00:00 2001 From: pkd Date: Thu, 25 Jul 2024 15:10:09 +0200 Subject: [PATCH 1/4] moving hashtable to Cutils --- include/hashtable.h | 26 --------- lib/cutils | 2 +- src/hashtable.c | 137 -------------------------------------------- src/update.c | 12 ++-- test/test.c | 2 + 5 files changed, 8 insertions(+), 171 deletions(-) delete mode 100755 include/hashtable.h delete mode 100644 src/hashtable.c diff --git a/include/hashtable.h b/include/hashtable.h deleted file mode 100755 index 2175d0d..0000000 --- a/include/hashtable.h +++ /dev/null @@ -1,26 +0,0 @@ -typedef struct pair { - char* key; - void* value; -} pair; - -typedef struct { - pair* data; - int size; - int capacity; -} item; - -typedef struct { - item *items; - int capacity; -} hashtable; - - -hashtable *hm_create(int capacity); -void hm_destroy(hashtable *hm); -int hm_add(hashtable *hm, char *key, void *value); -void* hm_get(hashtable *hm, char *key); -int hm_rm(hashtable *hm, char *key); -int hm_visualize(hashtable *hm); -hashtable* hm_init(void* kvlist[][2],int size); - -unsigned int hm_hash(hashtable *hm, char *key);; \ No newline at end of file diff --git a/lib/cutils b/lib/cutils index fa38903..09a856d 160000 --- a/lib/cutils +++ b/lib/cutils @@ -1 +1 @@ -Subproject commit fa389032d3b0de4dad3403bfa12d153c767de10d +Subproject commit 09a856de04a9f5ffe870d76025cf76613e6c5380 diff --git a/src/hashtable.c b/src/hashtable.c deleted file mode 100644 index 001f0df..0000000 --- a/src/hashtable.c +++ /dev/null @@ -1,137 +0,0 @@ -#include "stdio.h" -#include -#include - -#include "hashtable.h" -#include "cutils.h" - -hashtable* hm_create(int capacity) -{ - if (capacity == 0) capacity = 1024; - - hashtable *hm = calloc(1,sizeof(hashtable)); - hm->items = calloc(capacity, sizeof(item)); - if (hm->items == NULL) { - fprintf(stderr, "Out of memory"); - exit(1); - } - hm->capacity = capacity; - return hm; -} - -void hm_destroy(hashtable *hm) -{ - for (int i = 0; i < hm->capacity; i++) { - if (hm->items[i].data != NULL) { - free(hm->items[i].data); - } - } - free(hm->items); - free(hm); -} - -int hm_add(hashtable *hm, char *key, void *value) -{ - - int index = hm_hash(hm,key); - item x = hm->items[index]; - if (x.data == NULL) { - x.data = calloc(8, sizeof(pair)); - x.size = 0; - x.capacity = 8; - } - else if (x.size == x.capacity) { - x.capacity += 8; - //printf("reallocating %d\n", x.capacity); - x.data = realloc(x.data, sizeof(pair)*(x.capacity)); - } - - pair apair = {key, value}; - x.data[x.size++] = apair; - hm->items[index] = x; - - return 0; -} - -void* hm_get(hashtable *hm, char *key) -{ - int index = hm_hash(hm,key); - item x = hm->items[index]; - if (x.data == NULL) return NULL; - for (int i = 0; i < x.size; i++) { - if (strcmp(x.data[i].key,key) == 0) { - return x.data[i].value; - } - } - return NULL; -} - -// here we are converting a pair list into a hash table -hashtable* hm_init(void* kvlist[][2],int size) { - hashtable* hm = hm_create(size*2); - for (int i = 0; i < size; i++) { - hm_add(hm, kvlist[i][0], kvlist[i][1]); - } - return hm; -} - -int hm_rm(hashtable *hm, char *key) -{ - int index = hm_hash(hm,key); - item *x = &hm->items[index]; - if (x->data == NULL) return 1; - for (int i = 0; i < x->size; i++) { - if (strcmp(x->data[i].key,key) == 0) { - x->data[i] = x->data[x->size-1]; - //printf("replacing %s with %s\n", x->data[i].key, x->data[x->size-1].key); - x->size--; - if (x->size == 0) { - //printf("freeing %s\n", x->data[i].key); - free(x->data); - x->data = NULL; - } - return 0; - } - } - return 1; -} - -int hm_visualize(hashtable *hm) -{ - for (int i = 0; i < hm->capacity; i++) { - item x = hm->items[i]; - if (x.data == NULL) continue; - printf("===========================\n"); - printf("%d: ", i); - for (int j = 0; j < x.size; j++) { - printf("%s ", x.data[j].key); - } - printf("\n"); - printf("===========================\n"); - } - return 0; -} - -unsigned int hm_hash(hashtable *hm, char *key) -{ - if (key == NULL) return 0; - - unsigned int len = strlen(key); - - unsigned char *p = (unsigned char*) key; - unsigned int h = 0; - - while(len--) { - h += *p++; - h += (h << 9); - h ^= (h >> 19); - } - - h += (h << 3); - h ^= (h >> 17); - h += (h << 11); - - //printf("hash: %d\n", h % hm->capacity); - - return h % hm->capacity; -} \ No newline at end of file diff --git a/src/update.c b/src/update.c index 02bca13..db79ceb 100644 --- a/src/update.c +++ b/src/update.c @@ -105,14 +105,12 @@ int update() free(files_array); - if(new_version_found != 0) - { - msg(WARNING, "new version found for one or more packages, use --upgrade to upgrade"); + if(new_version_found != 0) { + msg(WARNING, "New version found for one or more packages, use --upgrade to upgrade"); + } + else { + msg(WARNING, "all packages are up to date"); } - else - { - msg(WARNING, "all packages are up to date"); - } return 0; } diff --git a/test/test.c b/test/test.c index c6dd66b..5886055 100644 --- a/test/test.c +++ b/test/test.c @@ -23,7 +23,9 @@ void test_pm(char* spm_path) { init() ; assert(install_package_source(spm_path,0) == 0); + assert(check("vim") == 0); assert(uninstall("vim") == 0); + assert(check("vim") == 1); unsetenv("SOVIET_ROOT"); unsetenv("SOVIET_ROOT"); From d48f16a763564dd79223311d4e2e5287762be97d Mon Sep 17 00:00:00 2001 From: pkd Date: Thu, 25 Jul 2024 15:26:49 +0200 Subject: [PATCH 2/4] finxing compile and linking errors --- formats/ecmp/ecmp.c | 5 +-- include/cutils.h | 82 ++++++++++++++++++++++++++++++++++++++++--- include/libspm.h | 1 + makefile | 3 +- src/move.c | 2 +- test/assets/split.txt | 2 +- test/spm.c | 3 +- 7 files changed, 86 insertions(+), 12 deletions(-) diff --git a/formats/ecmp/ecmp.c b/formats/ecmp/ecmp.c index 49ecc5b..7f42e7b 100644 --- a/formats/ecmp/ecmp.c +++ b/formats/ecmp/ecmp.c @@ -2,14 +2,11 @@ #include "stdlib.h" #include "string.h" #include "unistd.h" -#include "malloc.h" + #include "../../include/libspm.h" #include "../../include/cutils.h" -#include "../../include/hashtable.h" -#include - #define uint unsigned int diff --git a/include/cutils.h b/include/cutils.h index 5e34475..fad47aa 100644 --- a/include/cutils.h +++ b/include/cutils.h @@ -3,7 +3,7 @@ The CUtils Library is a collection of C functions. It can be used for any C project, but it was originally made for the Libspm/CCCP project. It is licensed under the GNU General Public License v3.0. - * Copyright (C) 2019-2020 PKD + * Copyright (C) 2019-2024 PKD */ #include "string.h" @@ -41,7 +41,6 @@ long rdfile(const char* filePath,char** buffer); // write entire file safely int wrnfile(const char* filePath,char* buffer,long size); #define wrfile(filePath,buffer) wrnfile(filePath,buffer,strlen(buffer)) - /* Check if a dir exists : * 0 - doesn't exist @@ -49,10 +48,15 @@ int wrnfile(const char* filePath,char* buffer,long size); * 2 - Not a directory */ int isdir (const char *d); + // create dir recursivelty (similar to mkdir -p) int pmkdir (const char *dir); // move a file and create the dir if it doesn't exist -int mvsp(char* old_path,char* new_path,char* root); +int mvsp(char* old_path,char* new_path); +// move a symlink +int mvlink(char* old_path,char* new_path); +// get the relative path between two paths +char* relpath(char* start,char* end); // LIST file in a dir char** ls(char* path); // exec a shell command and return the output @@ -63,9 +67,9 @@ String utils Functions : * popchar - Remove a character from a string * popcharn - Remove a character from a string (with a size limit) - * s_size should be a size_t (=long unsigned int) * splita - Split a string into an array of strings * countc - Count the number of occurences of a char in a string + * strinarr - Check if a string is in an array of strings */ #define popcharn(str,pos,s_size) if (pos < s_size) { memmove(&str[pos], &str[pos + 1], s_size - pos - 1); str[s_size-1] = '\0'; } @@ -77,6 +81,9 @@ unsigned int splita (char* string,char delim,char*** dest); // to count the number of occurences of a char in a string unsigned int countc(const char* string,char c); +// check if a string is in an array of strings +int strinarr( char* val, char** arr,long arrsize); + /* Logging and debug utils Functions : @@ -102,6 +109,73 @@ int f_dbg__(int level,int line,const char* function,const char* file,char* messa #define dbg(level,message,...) f_dbg__(level,__LINE__,__func__,__FILE__,message,##__VA_ARGS__) +/* Hashtable (Dict) implementation */ + +// A pair of values : +// * key : the key of the pair (in bytes) +// * value : the value of the pair (pointer to anything) +typedef struct pair { + char* key; + void* value; +} pair; + +// An item in the hashtable : +// * data : the pairs of the item +// * size : the number of pairs in the item +// * capacity : the capacity of the item +typedef struct { + pair* data; + int size; + int capacity; +} item; + +// The hashtable : +// * items : the items in the hashtable +// * capacity : the capacity of the hashtable +typedef struct { + item *items; + int capacity; +} hashtable; + +// create a new hashtable +// * capacity : the capacity of the hashtable you want +hashtable *hm_create(int capacity); +// destroy a hashtable (free the memory) +// * hm : the hashtable you want to destroy +void hm_destroy(hashtable *hm); +// add a pair to the hashtable +// * hm : the hashtable you want to add the pair to +// * key : the key of the pair +// * value : the value of the pair +// Equivalent to hm[key] = value +int hm_add(hashtable *hm, char *key, void *value); +// get a value from the hashtable +// * hm : the hashtable you want to get the value from +// * key : the key of the pair +// Equivalent to hm[key] +void* hm_get(hashtable *hm, char *key); +// remove a pair from the hashtable +// * hm : the hashtable you want to remove the pair from +// * key : the key of the pair +// Equivalent to del hm[key] +int hm_rm(hashtable *hm, char *key); +// visualize the hashtable +// basic pretty print of the hashtable +// * hm : the hashtable you want to visualize +int hm_visualize(hashtable *hm); +// initialize a hashtable with a list of key-value pairs +// * kvlist : the list of key-value pairs +// * size : the size of the list +hashtable* hm_init(void* kvlist[][2],int size); +// get the hash of a key +// * hm : the hashtable you want to get the hash from +// * key : the key you want to get the hash of +// WARNING : Used only internally +unsigned int hm_hash(hashtable *hm, char *key);; + + + + // memory safety and debugging void* dbg_malloc(size_t size,char* file,int line); void* dbg_calloc(size_t nmemb,size_t size,char* file,int line); diff --git a/include/libspm.h b/include/libspm.h index 76a79dc..ef90739 100755 --- a/include/libspm.h +++ b/include/libspm.h @@ -2,6 +2,7 @@ #include "cutils.h" #include "globals.h" +#include diff --git a/makefile b/makefile index 7926c37..7e403ba 100755 --- a/makefile +++ b/makefile @@ -85,6 +85,7 @@ check: test check-all libs: for i in $(LOCAL_LIBS); do make -C $$(dirname $$i) all; done + for i in $(LOCAL_LIBS); do cp $$(dirname $$i)/*.h include ; done direct: $(CC) $(CFLAGS) $(SRCS) $(LIBS) -g -shared -fPIC -o $(LIBOUT) @@ -96,7 +97,7 @@ formats: for i in $(FMT_DIR)/*; do \ echo "Building $$i"; \ if [ -d $$i ]; then \ - $(CC) $(CFLAGS) -shared -fPIC $$i/*.c -o $(BINDIR)/plugins/$$(basename $$i).so; \ + $(CC) $(CFLAGS) -shared -fPIC $$i/*.c $(LOCAL_LIBS) -o $(BINDIR)/plugins/$$(basename $$i).so; \ fi; \ done diff --git a/src/move.c b/src/move.c index e4eb176..199c56f 100755 --- a/src/move.c +++ b/src/move.c @@ -55,7 +55,7 @@ void move_binaries(char** locations, long loc_size) { } // Move the files from the build directory to the destination location - switch (mvsp(build_loc, dest_loc, getenv("SOVIET_BUILD_DIR"))) + switch (mvsp(build_loc, dest_loc)) { case -1: msg(FATAL, "Moving %s to %s failed, could not create dir", build_loc, dest_loc); diff --git a/test/assets/split.txt b/test/assets/split.txt index 6a73ebd..be3430b 100644 --- a/test/assets/split.txt +++ b/test/assets/split.txt @@ -1 +1 @@ -Ldg5En7J5,wK4haKNq21CLxQAKJpe9lgbe2tjHBg7DmL9CAt7j8LqXJ8zykW8gMdCU0TpFryahJksx9oZUheaaTByxEOznQPwnb23uNecK8rakjLtRhxjgcl4pTgda5s4DPqNvITQJfcIB1sja9GsCfYUf7K9CmT,m,l1nXLYkTv2pMEwPOlHY6QmhFUrfsivAU11GnQiEL73X9IibIpY7MMC8djqqZ2NzSufmaSWP7gU1LUjv1,bgmbpXnM8FSdCG61ioC7zvbOzd5DPRKCryKMlxezsvMCTnzYhXkSlKzy5y77RLr6mrA4haWUyr8ZbrayoRjCjEZCvyMgzOcD6ETRthgkqmGGUy6oqYyNgJBMLpEZsAmhIcKa45KWMRGShvGNKuK4upc43BEW,sjwCUo4ykb2h6v,NETEaX9V2g0JgXI45qwiruNAGeTsPf5fSXGskdLFof1OkBnabL53HLL5CWteosxyVTQFmoBeFqpbOzC69kSslJO45eKpBse6 \ No newline at end of file +oVil0JdC1BlYeL07Fv8VIwy2LBSxQxAHuXRBYfsNx2UbiBbBrli4ydwhwvd08CTnHxsdmmqG2WSqSnE33d3IsalyOrljQWXh8zUP8TgNP,EzszJSkt1CVWJ899MCNkQCCePjIfrLQNVaUuZEkWAi0X2UrzV3Pvz4fPVebdgENIF6ld,8Fccg9PT,h2MCth6JvahLEKwtLnsg98zz1DJhjmQb29EbAotjUNgHjLIORR6BuHCwbmWoj3whfVuqTPP,1MDxpKQ,6Z5GfHX3GQBhLBna,a24DvMFd4mwlD7LEEQvzhRBjD4AQFsQvvgl735AAe,W4IxFjfNmHPjFIx1iO5M0D0vLCQgZBnJTGuiWbZUa5UFLDrT,RSuvj20HLTqXXrBQow4WlqU,JyWgjBArm,Y0w7o6lUdBCHzIWR4BfgA3KH1DBTqXwnpBqEMZPDHqcmU9bIP8PEtt7xbkQDVS4HbUd6aQegldT0a2YL0xQPiX7sJylECkcLFk0GGkKvNv \ No newline at end of file diff --git a/test/spm.c b/test/spm.c index 359e087..dbf7508 100644 --- a/test/spm.c +++ b/test/spm.c @@ -1,5 +1,6 @@ #include "test.h" -#include +#include "../include/libspm.h" +#include "../include/cutils.h" char WORKING_DIR[2048]; From 433f688f513a7bbc21568f63c56d0f3733ef81ef Mon Sep 17 00:00:00 2001 From: pkd Date: Thu, 25 Jul 2024 15:27:01 +0200 Subject: [PATCH 3/4] new fixed cutils --- lib/cutils | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cutils b/lib/cutils index 09a856d..2fac5f8 160000 --- a/lib/cutils +++ b/lib/cutils @@ -1 +1 @@ -Subproject commit 09a856de04a9f5ffe870d76025cf76613e6c5380 +Subproject commit 2fac5f87d0447f3ac31a72f729f657f638f2747d From 317e11d4e2daa2c30d715d637ae9aa579c2790fc Mon Sep 17 00:00:00 2001 From: pkd Date: Fri, 4 Apr 2025 18:21:58 +0200 Subject: [PATCH 4/4] some basic work to prepare for new packages formats --- scripts/arch-parser | 234 --------- scripts/cccp-makepkg | 1080 ------------------------------------------ src/config.c | 2 +- src/pkg.c | 6 +- 4 files changed, 6 insertions(+), 1316 deletions(-) delete mode 100644 scripts/arch-parser delete mode 100755 scripts/cccp-makepkg diff --git a/scripts/arch-parser b/scripts/arch-parser deleted file mode 100644 index e90655d..0000000 --- a/scripts/arch-parser +++ /dev/null @@ -1,234 +0,0 @@ -#!/usr/bin/env python3 - -# This is a parser for bash-style variable assignments. -# It fully (?) supports the syntax w/o braces, the ${}-syntax -# is implemented very hackish. - -# As aur/opera uses an 'if'-clause outside build(), I am going to -# implement basic 'if'-support, too. But, thinking further -# about this, that 'if' used $CARCH, so parsing that 'if' makes no -# sense anyway, because its hard to find a good default for $CARCH: -# it would be likely to differ from $CARCH on the users machine, so -# this would probably confuse people more than it would help. - -# This is meant for Archlinux' AUR to be used to parse -# PKGBUILD's properly. - -# CREDIT to: github.com/pyropeter/ - -import sys -import re -import json - -args = sys.argv[1:] - -reName = re.compile(r"([\w_][\w\d_]*)") -reAssignment = re.compile(r"([\w_][\w\d_]*)=") - -lines = [""] -symbols = {} - - -file = open(args[0], "r") - - -for line in file: - line = line[:-1] - if not line: continue - lines[-1] += line - if line[-1] != "\\": - lines.append("") - -def bashGlobToRegex(glob): - # Reference: bash(1) "Pathname Expansion" - # TODO: - # * characater classes, equivalence classes, that other foo - # ( [:upper:], [=c=], [.symbol.] - # First should be easy to implement, python's regexes even have - # similar classes (\w, \W, \d, \D, \s, \S) - # Afaik, the first syntax is used rarely, the following two are - # used _never_. No urge to implement them. - # * extended globs: - # ( ?(pattern), *(pattern), +(pattern), etc...) - # Never seen someone use thiese, no urge to implement them. - # * bash may have different handling of \: - # This code just ignores the following characters' special meaning - # and lets it match itself. Bash may evaluate e.g. "\a" as "\a" - # and not as "a". (But both should eval "\*" as "*".) - # UPDATE: This should now be solved. But it was done with magic. - - res = "" - ptr = 0 - while ptr < len(glob): - if glob[ptr] == "\\": - ptr += 1 - res += re.escape(glob[ptr]) - elif glob[ptr] == "*": - res += ".*?" - elif glob[ptr] == "?": - res += "." - elif glob[ptr] == "[": - ptr += 1 - res += "[" - if glob[ptr] == "^" or glob[ptr] == "!": - res += "^" - ptr += 1 - if glob[ptr] == "]": - res += "]" - ptr += 1 - if glob[ptr-1] in "[^!" and glob[ptr] == "\\": - ptr += 1 - while glob[ptr] != "]": - if glob[ptr] == "\\" and glob[ptr+1] in "wsdbaWSDBAZ": - res += "\\" - res += glob[ptr] - ptr += 1 - res += "]" - else: - res += re.escape(glob[ptr]) - ptr += 1 - return res - -def expandParams(text): - # Reference: bash(1) "Parameter Expansion" - # Done: - # * ${foo} - # * ${foo/glob/substitute} - # - # Not done: - # * all other syntaxes - # * support for arrays will not be needed - # * support for 2nd-level indirection will not be needed - # ( foo="bar"; bar="baz"; ${!foo} -> "baz" ) - - res = "" - ptr = 0 - while ptr < len(text): - if text[ptr] == "\\": - ptr += 1 - elif text[ptr] == "$": - ptr += 1 - - # are there braces? - if text[ptr] == "{": - ptr += 1 - name = reName.match(text, ptr) - ptr = name.end() - - if text[ptr] == "/": - # Pattern substitution - # ${parameter/pattern/string} - - ptr += 1 - - # check if all occurences should be substituted - suball = False - if text[ptr] == "/": - suball = True - ptr += 1 - - # fetch the pattern - pattern = "" - while text[ptr] != "/" and text[ptr] != "}": - if text[ptr] == "\\" and text[ptr+1] in "\\}/": - ptr += 1 - pattern += text[ptr] - ptr += 1 - - # fetch the substitute - substitute = "" - if text[ptr] != "}": # there might be no substitute - ptr += 1 - while text[ptr] != "}": - if text[ptr] == "\\": - ptr += 1 - substitute += text[ptr] - ptr += 1 - - if pattern.startswith("#"): - align = 1 - pattern = pattern[1:] - elif pattern.startswith("\\#"): - pattern = pattern[1:] - elif pattern.endswith("%%"): - align = 2 - pattern = pattern[:-1] - elif pattern.endswith("\\%%"): - pattern = pattern[:-1] - else: - align = 0 - regex = ((align == 1 and "^" or "") + - bashGlobToRegex(pattern) + - (align == 2 and "$" or "")) - - res += re.sub(regex, substitute, - symbols.get(name.group(1), ""), - 0 if suball else 1) - else: - # 'normal' expansion - res += symbols.get(name.group(1), "") - else: - name = reName.match(text, ptr) - res += symbols.get(name.group(1), "") - ptr = name.end() - else: - res += text[ptr] - ptr += 1 - return res - -def parseStr(line, ptr): - res = "" - if line[ptr] == "'": - ptr += 1 - while line[ptr] != "'": - res += line[ptr] - ptr += 1 - ptr += 1 - elif line[ptr] == '"': - ptr += 1 - while line[ptr] != '"': - res += line[ptr] - ptr += 1 - res = expandParams(res) - ptr += 1 - else: - while (len(line) > ptr) and (not line[ptr] in " \t)"): - res += line[ptr] - ptr += 1 - res = expandParams(res) - return ptr, res - -i = 0 -while i < len(lines): - line = lines[i] - i += 1 - - assignment = reAssignment.match(line) - if not assignment: - continue - ptr = assignment.end() - - # the parser relys on proper syntax. syntax errors are catched here - try: - if line[ptr] == "(": - symbols[assignment.group(1)] = [] - ptr += 1 - while True: - while (ptr < len(line)) and (line[ptr] != ")"): - if not line[ptr] in [" ", "\t"]: - ptr, val = parseStr(line, ptr) - symbols[assignment.group(1)].append(val) - else: - ptr += 1 - if (ptr < len(line)) and (line[ptr] == ")"): break - if len(lines) == i: break - line = lines[i] - i += 1 - ptr = 0 - else: - ptr, symbols[assignment.group(1)] = parseStr(line, ptr) - except IndexError: - print ("Syntax error, continuing") - continue - -print (json.dumps(symbols,indent = 4)) \ No newline at end of file diff --git a/scripts/cccp-makepkg b/scripts/cccp-makepkg deleted file mode 100755 index 29f7a75..0000000 --- a/scripts/cccp-makepkg +++ /dev/null @@ -1,1080 +0,0 @@ -#!/usr/bin/bash -# -# This is a modified version of the makepkg tool by the SOVIETLINUX dev team -# We modified this tool for use with the libspm and the cccp package manager. -# It permit us to have full archlinux compatibility -# -# Copyright (c) 2006 by PKD -# -# makepkg - make packages compatible for use with pacman -# -# Copyright (c) 2006-2021 Pacman Development Team -# Copyright (c) 2002-2006 by Judd Vinet -# Copyright (c) 2005 by Aurelien Foret -# Copyright (c) 2006 by Miklos Vajna -# Copyright (c) 2005 by Christian Hamar -# Copyright (c) 2006 by Alex Smith -# Copyright (c) 2006 by Andras Voroskoi -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -# makepkg uses quite a few external programs during its execution. You -# need to have at least the following installed for makepkg to function: -# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils), -# gettext, gpg, grep, gzip, sed, tput (ncurses), xz - - - - -# gettext initialization -export TEXTDOMAIN='pacman-scripts' -export TEXTDOMAINDIR='/usr/share/locale' - -# file -i does not work on Mac OSX unless legacy mode is set -export COMMAND_MODE='legacy' -# Ensure CDPATH doesn't screw with our cd calls -unset CDPATH -# Ensure GREP_OPTIONS doesn't screw with our grep calls -unset GREP_OPTIONS - -declare -r makepkg_version='6.0.1' -declare -r confdir='/etc' -declare -r BUILDSCRIPT='PKGBUILD' -declare -r startdir="$(pwd -P)" - -LIBRARY=${LIBRARY:-'/usr/share/makepkg'} - -# Options -ASDEPS=0 -BUILDFUNC=0 -BUILDPKG=1 -CHECKFUNC=0 -CLEANBUILD=0 -CLEANUP=0 -DEP_BIN=0 -FORCE=0 -GENINTEG=0 -HOLDVER=0 -IGNOREARCH=0 -INFAKEROOT=0 -INSTALL=0 -LOGGING=0 -NEEDED=0 -NOARCHIVE=1 -NOBUILD=0 -NODEPS=0 -NOEXTRACT=0 -PKGFUNC=0 -PKGVERFUNC=0 -PREPAREFUNC=0 -REPKG=0 -REPRODUCIBLE=0 -RMDEPS=0 -SKIPCHECKSUMS=0 -SKIPPGPCHECK=1 -SIGNPKG='' -SPLITPKG=0 -SOURCEONLY=0 -VERIFYSOURCE=0 - -if [[ -n $SOURCE_DATE_EPOCH ]]; then - REPRODUCIBLE=1 -else - SOURCE_DATE_EPOCH=$(date +%s) -fi -export SOURCE_DATE_EPOCH - - -shopt -s extglob - -### SUBROUTINES ### - -#Import libmakepkg -for lib in "$LIBRARY"/*.sh; do - source "$lib" -done - -## -# Special exit call for traps, Don't print any error messages when inside, -# the fakeroot call, the error message will be printed by the main call. -## -trap_exit() { - local signal=$1; shift - - if (( ! INFAKEROOT )); then - echo - error "$@" - fi - [[ -n $srclinks ]] && rm -rf "$srclinks" - - # unset the trap for this signal, and then call the default handler - trap -- "$signal" - kill "-$signal" "$$" -} - - -## -# Clean up function. Called automatically when the script exits. -## -clean_up() { - local EXIT_CODE=$? - - if (( INFAKEROOT )); then - # Don't clean up when leaving fakeroot, we're not done yet. - return 0 - fi - - if [[ -p $logpipe ]]; then - rm "$logpipe" - fi - - if (( (EXIT_CODE == E_OK || EXIT_CODE == E_INSTALL_FAILED) && BUILDPKG && CLEANUP )); then - local pkg file - - # If it's a clean exit and -c/--clean has been passed... - msg "$(gettext "Cleaning up...")" - rm -rf "$pkgdirbase" "$srcdir" - if [[ -n $pkgbase ]]; then - local fullver=$(get_full_version) - # Can't do this unless the BUILDSCRIPT has been sourced. - if (( PKGVERFUNC )); then - rm -f "${pkgbase}-${fullver}-${CARCH}-pkgver.log"* - fi - if (( PREPAREFUNC )); then - rm -f "${pkgbase}-${fullver}-${CARCH}-prepare.log"* - fi - if (( BUILDFUNC )); then - rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"* - fi - if (( CHECKFUNC )); then - rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"* - fi - if (( PKGFUNC )); then - rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"* - elif (( SPLITPKG )); then - for pkg in ${pkgname[@]}; do - rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"* - done - fi - - # clean up dangling symlinks to packages - for pkg in ${pkgname[@]}; do - for file in ${pkg}-*-*-*{${PKGEXT},${SRCEXT}}; do - if [[ -h $file && ! -e $file ]]; then - rm -f "$file" - fi - done - done - fi - fi - - - exit $EXIT_CODE - -} - -enter_fakeroot() { - msg "$(gettext "Entering %s environment...")" "fakeroot" - fakeroot -- bash -$- "${BASH_SOURCE[0]}" -F "${ARGLIST[@]}" || exit $? -} - -# Automatically update pkgver variable if a pkgver() function is provided -# Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver -update_pkgver() { - msg "$(gettext "Starting %s()...")" "pkgver" - newpkgver=$(run_function_safe pkgver) - if (( $? != 0 )); then - error_function pkgver - fi - if ! check_pkgver "$newpkgver"; then - error "$(gettext "pkgver() generated an invalid version: %s")" "$newpkgver" - exit $E_PKGBUILD_ERROR - fi - - if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then - if [[ -w $BUILDFILE ]]; then - mapfile -t buildfile < "$BUILDFILE" - buildfile=("${buildfile[@]/#pkgver=*([^ ])/pkgver=$newpkgver}") - buildfile=("${buildfile[@]/#pkgrel=*([^ ])/pkgrel=1}") - if ! printf '%s\n' "${buildfile[@]}" > "$BUILDFILE"; then - error "$(gettext "Failed to update %s from %s to %s")" \ - "pkgver" "$pkgver" "$newpkgver" - exit $E_PKGBUILD_ERROR - fi - source_safe "$BUILDFILE" - local fullver=$(get_full_version) - msg "$(gettext "Updated version: %s")" "$pkgbase $fullver" - else - warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \ - "$BUILDFILE" - fi - fi -} - -# Print 'source not found' error message and exit makepkg -missing_source_file() { - error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")" - plainerr "$(gettext "Aborting...")" - exit $E_MISSING_FILE -} - -error_function() { - # first exit all subshells, then print the error - if (( ! BASH_SUBSHELL )); then - error "$(gettext "A failure occurred in %s().")" "$1" - plainerr "$(gettext "Aborting...")" - fi - exit $E_USER_FUNCTION_FAILED -} - -merge_arch_attrs() { - local attr supported_attrs=( - provides conflicts depends replaces optdepends - makedepends checkdepends) - - for attr in "${supported_attrs[@]}"; do - eval "$attr+=(\"\${${attr}_$CARCH[@]}\")" - done - - # ensure that calling this function is idempotent. - unset -v "${supported_attrs[@]/%/_$CARCH}" -} - -source_buildfile() { - source_safe "$@" -} - -run_function_safe() { - local restoretrap restoreshopt - - # we don't set any special shopts of our own, but we don't want the user to - # muck with our environment. - restoreshopt=$(shopt -p) - - # localize 'set' shell options to this function - this does not work for shopt - local - - shopt -o -s errexit errtrace - - restoretrap=$(trap -p ERR) - trap "error_function '$1'" ERR - - run_function "$1" - - trap - ERR - eval "$restoretrap" - eval "$restoreshopt" -} - -run_function() { - if [[ -z $1 ]]; then - return 1 - fi - local pkgfunc="$1" - - if (( ! BASH_SUBSHELL )); then - msg "$(gettext "Starting %s()...")" "$pkgfunc" - fi - cd_safe "$srcdir" - - local ret=0 - if (( LOGGING )); then - local fullver=$(get_full_version) - local BUILDLOG="$LOGDEST/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log" - if [[ -f $BUILDLOG ]]; then - local i=1 - while true; do - if [[ -f $BUILDLOG.$i ]]; then - i=$(($i +1)) - else - break - fi - done - mv "$BUILDLOG" "$BUILDLOG.$i" - fi - - # ensure overridden package variables survive tee with split packages - logpipe=$(mktemp -u "$LOGDEST/logpipe.XXXXXXXX") - mkfifo "$logpipe" - tee "$BUILDLOG" < "$logpipe" & - local teepid=$! - - $pkgfunc &>"$logpipe" - - wait -f $teepid - rm "$logpipe" - else - "$pkgfunc" - fi -} - -run_prepare() { - run_function_safe "prepare" -} - -run_build() { - run_function_safe "build" -} - -run_check() { - run_function_safe "check" -} - -run_package() { - run_function_safe "package${1:+_$1}" -} - - - - - - -write_kv_pair() { - local key="$1" - shift - - for val in "$@"; do - if [[ $val = *$'\n'* ]]; then - error "$(gettext "Invalid value for %s: %s")" "$key" "$val" - exit $E_PKGBUILD_ERROR - fi - printf "%s = %s\n" "$key" "$val" - done -} - - - - - -# build a sorted NUL-separated list of the full contents of the current -# directory suitable for passing to `bsdtar --files-from` -# database files are placed at the beginning of the package regardless of -# sorting -list_package_files() { - ( - export LC_COLLATE=C - shopt -s dotglob globstar - # bash 5.0 only works with combo directory + file globs - printf '%s\0' **/* - ) -} - -create_package() { - (( NOARCHIVE )) && return 0 - - if [[ ! -d $pkgdir ]]; then - error "$(gettext "Missing %s directory.")" "\$pkgdir/" - plainerr "$(gettext "Aborting...")" - exit $E_MISSING_PKGDIR - fi - - cd_safe "$pkgdir" - msg "$(gettext "Creating package \"%s\"...")" "$pkgname" - - pkgarch=$(get_pkg_arch) - - - # check for changelog/install files - for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do - IFS='/' read -r orig dest < <(printf '%s\n' "$i") - - if [[ -n ${!orig} ]]; then - msg2 "$(gettext "Adding %s file...")" "$orig" - if ! cp "$startdir/${!orig}" "$dest"; then - error "$(gettext "Failed to add %s file to package.")" "$orig" - exit $E_MISSING_FILE - fi - chmod 644 "$dest" - fi - done - - # tar it up - local fullver=$(get_full_version) - local pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}" - local ret=0 - - [[ -f $pkg_file ]] && rm -f "$pkg_file" - [[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig" - - # ensure all elements of the package have the same mtime - find . -exec touch -h -d @$SOURCE_DATE_EPOCH {} + - - - msg2 "$(gettext "Compressing package...")" - # TODO: Maybe this can be set globally for robustness - shopt -s -o pipefail - list_package_files | LANG=C bsdtar --no-fflags -cnf - --null --files-from - | - compress_as "$PKGEXT" > "${pkg_file}" || ret=$? - - shopt -u -o pipefail - - if (( ret )); then - error "$(gettext "Failed to create package file.")" - exit $E_PACKAGE_FAILED - fi -} - -create_debug_package() { - # check if a debug package was requested - if ! check_option "debug" "y" || ! check_option "strip" "y"; then - return 0 - fi - - local pkgdir="$pkgdirbase/$pkgbase-debug" - - # check if we have any debug symbols to package - if dir_is_empty "$pkgdir/usr/lib/debug"; then - return 0 - fi - - unset groups depends optdepends provides conflicts replaces backup install changelog - - local pkg - for pkg in ${pkgname[@]}; do - if [[ $pkg != $pkgbase ]]; then - provides+=("$pkg-debug") - fi - done - - pkgdesc="Detached debugging symbols for $pkgname" - pkgname=$pkgbase-debug - - create_package -} - -create_srcpackage() { - local ret=0 - msg "$(gettext "Creating source package...")" - local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)" - mkdir "${srclinks}"/${pkgbase} - - msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" - ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}" - - msg2 "$(gettext "Generating %s file...")" .SRCINFO - write_srcinfo > "$srclinks/$pkgbase"/.SRCINFO - - local file all_sources - - get_all_sources 'all_sources' - for file in "${all_sources[@]}"; do - if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY == 2 )); then - local absfile - absfile=$(get_filepath "$file") || missing_source_file "$file" - msg2 "$(gettext "Adding %s...")" "${absfile##*/}" - ln -s "$absfile" "$srclinks/$pkgbase" - fi - done - - # set pkgname the same way we do for running package(), this way we get - # the right value in extract_function_variable - local pkgname_backup=(${pkgname[@]}) - local i pkgname - for i in 'changelog' 'install'; do - local file files - - [[ ${!i} ]] && files+=("${!i}") - for pkgname in "${pkgname_backup[@]}"; do - if extract_function_variable "package_$pkgname" "$i" 0 file; then - files+=("$file") - fi - done - - for file in "${files[@]}"; do - if [[ $file && ! -f "${srclinks}/${pkgbase}/$file" ]]; then - msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}" - ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/" - fi - done - done - pkgname=(${pkgname_backup[@]}) - - local fullver=$(get_full_version) - local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}" - - # tar it up - msg2 "$(gettext "Compressing source package...")" - cd_safe "${srclinks}" - - # TODO: Maybe this can be set globally for robustness - shopt -s -o pipefail - LANG=C bsdtar --no-fflags -cLf - ${pkgbase} | compress_as "$SRCEXT" > "${pkg_file}" || ret=$? - - shopt -u -o pipefail - - if (( ret )); then - error "$(gettext "Failed to create source package file.")" - exit $E_PACKAGE_FAILED - fi - - cd_safe "${startdir}" - rm -rf "${srclinks}" -} - - - -check_build_status() { - local fullver pkgarch allpkgbuilt somepkgbuilt - if (( ! SPLITPKG )); then - fullver=$(get_full_version) - pkgarch=$(get_pkg_arch) - if [[ -f $PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT} ]] \ - && ! (( FORCE || SOURCEONLY || NOBUILD || NOARCHIVE)); then - - error "$(gettext "A package has already been built. (use %s to overwrite)")" "-f" - exit $E_ALREADY_BUILT - fi - else - allpkgbuilt=1 - somepkgbuilt=0 - for pkg in ${pkgname[@]}; do - fullver=$(get_full_version) - pkgarch=$(get_pkg_arch $pkg) - if [[ -f $PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT} ]]; then - somepkgbuilt=1 - else - allpkgbuilt=0 - fi - done - if ! (( FORCE || SOURCEONLY || NOBUILD || NOARCHIVE)); then - if (( allpkgbuilt )); then - error "$(gettext "The package group has already been built. (use %s to overwrite)")" "-f" - exit $E_ALREADY_BUILT - fi - if (( somepkgbuilt && ! PKGVERFUNC )); then - error "$(gettext "Part of the package group has already been built. (use %s to overwrite)")" "-f" - exit $E_ALREADY_BUILT - fi - fi - fi -} - -backup_package_variables() { - local var - for var in ${pkgbuild_schema_package_overrides[@]}; do - local indirect="${var}_backup" - eval "${indirect}=(\"\${$var[@]}\")" - done -} - -restore_package_variables() { - local var - for var in ${pkgbuild_schema_package_overrides[@]}; do - local indirect="${var}_backup" - if [[ -n ${!indirect} ]]; then - eval "${var}=(\"\${$indirect[@]}\")" - else - unset ${var} - fi - done -} - -run_single_packaging() { - local pkgdir="$pkgdirbase/$pkgname" - mkdir "$pkgdir" - if [[ -n $1 ]] || (( PKGFUNC )); then - run_package $1 - fi - tidy_install - lint_package || exit $E_PACKAGE_FAILED - create_package -} - -run_split_packaging() { - local pkgname_backup=("${pkgname[@]}") - backup_package_variables - for pkgname in ${pkgname_backup[@]}; do - run_single_packaging $pkgname - restore_package_variables - done - pkgname=("${pkgname_backup[@]}") -} - -usage() { - printf "makepkg (pacman) %s\n" "$makepkg_version" - echo - printf -- "$(gettext "Make packages compatible for use with pacman")\n" - echo - printf -- "$(gettext "Usage: %s [options]")\n" "$0" - echo - printf -- "$(gettext "Options:")\n" - printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT" - printf -- "$(gettext " -c, --clean Clean up work files after build")\n" - printf -- "$(gettext " -C, --cleanbuild Remove %s dir before building the package")\n" "\$srcdir/" - printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n" - printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "\$srcdir/" - printf -- "$(gettext " -f, --force Overwrite existing package")\n" - printf -- "$(gettext " -g, --geninteg Generate integrity checks for source files")\n" - printf -- "$(gettext " -h, --help Show this help message and exit")\n" - printf -- "$(gettext " -i, --install Install package after successful build")\n" - printf -- "$(gettext " -L, --log Log package build process")\n" - printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" - printf -- "$(gettext " -o, --nobuild Download and extract files only")\n" - printf -- "$(gettext " -p Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" - printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n" - printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n" - printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" - printf -- "$(gettext " -S, --source Generate a source-only tarball without downloaded sources")\n" - printf -- "$(gettext " -V, --version Show version information and exit")\n" - printf -- "$(gettext " --allsource Generate a source-only tarball including downloaded sources")\n" - printf -- "$(gettext " --check Run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" - printf -- "$(gettext " --config Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf" - printf -- "$(gettext " --holdver Do not update VCS sources")\n" - printf -- "$(gettext " --key Specify a key to use for %s signing instead of the default")\n" "gpg" - printf -- "$(gettext " --noarchive Do not create package archive")\n" - printf -- "$(gettext " --nocheck Do not run the %s function in the %s")\n" "check()" "$BUILDSCRIPT" - printf -- "$(gettext " --noprepare Do not run the %s function in the %s")\n" "prepare()" "$BUILDSCRIPT" - printf -- "$(gettext " --nosign Do not create a signature for the package")\n" - printf -- "$(gettext " --packagelist Only list package filepaths that would be produced")\n" - printf -- "$(gettext " --printsrcinfo Print the generated SRCINFO and exit")\n" - printf -- "$(gettext " --sign Sign the resulting package with %s")\n" "gpg" - printf -- "$(gettext " --skipchecksums Do not verify checksums of the source files")\n" - printf -- "$(gettext " --skipinteg Do not perform any verification checks on source files")\n" - printf -- "$(gettext " --skippgpcheck Do not verify source files with PGP signatures")\n" - printf -- "$(gettext " --verifysource Download source files (if needed) and perform integrity checks")\n" - echo - printf -- "$(gettext "These options can be passed to %s:")\n" "pacman" - echo - printf -- "$(gettext " --asdeps Install packages as non-explicitly installed")\n" - printf -- "$(gettext " --needed Do not reinstall the targets that are already up to date")\n" - printf -- "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")\n" - printf -- "$(gettext " --noprogressbar Do not show a progress bar when downloading files")\n" - echo - printf -- "$(gettext "If %s is not specified, %s will look for '%s'")\n" "-p" "makepkg" "$BUILDSCRIPT" - echo -} - -version() { - printf "makepkg (pacman) %s\n" "$makepkg_version" - printf -- "Copyright (c) 2006-2021 Pacman Development Team .\n" - printf -- "Copyright (C) 2002-2006 Judd Vinet .\n" - printf '\n' - printf -- "$(gettext "\ -This is free software; see the source for copying conditions.\n\ -There is NO WARRANTY, to the extent permitted by law.\n")" -} - -# PROGRAM START - -# ensure we have a sane umask set -umask 0022 - -# determine whether we have gettext; make it a no-op if we do not -if ! type -p gettext >/dev/null; then - gettext() { - printf "%s\n" "$@" - } -fi - -ARGLIST=("$@") - -# Parse Command Line Options. -OPT_SHORT="AcCdefFghiLmop:rRsSV" -OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 'config:' 'force' 'geninteg' - 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild' - 'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'packagelist' - 'printsrcinfo' 'repackage' 'rmdeps' 'sign' 'skipchecksums' 'skipinteg' - 'skippgpcheck' 'source' 'syncdeps' 'verifysource' 'version') - - -if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then - exit $E_INVALID_OPTION -fi -set -- "${OPTRET[@]}" -unset OPT_SHORT OPT_LONG OPTRET - -while true; do - case "$1" in - - # Makepkg Options - --allsource) BUILDPKG=0 SOURCEONLY=2 ;; - -A|--ignorearch) IGNOREARCH=1 ;; - -c|--clean) CLEANUP=1 ;; - -C|--cleanbuild) CLEANBUILD=1 ;; - --check) RUN_CHECK='y' ;; - --config) shift; MAKEPKG_CONF=$1 ;; - -d|--nodeps) NODEPS=1 ;; - -e|--noextract) NOEXTRACT=1 ;; - -f|--force) FORCE=1 ;; - -F) INFAKEROOT=1 ;; - # generating integrity checks does not depend on architecture - -g|--geninteg) BUILDPKG=0 GENINTEG=1 IGNOREARCH=1;; - --holdver) HOLDVER=1 ;; - -i|--install) INSTALL=1 ;; - --key) shift; GPGKEY=$1 ;; - -L|--log) LOGGING=1 ;; - -m|--nocolor) USE_COLOR='n'; PACMAN_OPTS+=("--color" "never") ;; - --noarchive) NOARCHIVE=1 ;; - --nocheck) RUN_CHECK='n' ;; - --noprepare) RUN_PREPARE='n' ;; - --nosign) SIGNPKG='n' ;; - -o|--nobuild) BUILDPKG=0 NOBUILD=1 ;; - -p) shift; BUILDFILE=$1 ;; - --packagelist) BUILDPKG=0 PACKAGELIST=1 IGNOREARCH=1;; - --printsrcinfo) BUILDPKG=0 PRINTSRCINFO=1 IGNOREARCH=1;; - -r|--rmdeps) RMDEPS=1 ;; - -R|--repackage) REPKG=1 ;; - --sign) SIGNPKG='y' ;; - --skipchecksums) SKIPCHECKSUMS=1 ;; - --skipinteg) SKIPCHECKSUMS=1; SKIPPGPCHECK=1 ;; - --skippgpcheck) SKIPPGPCHECK=1;; - -s|--syncdeps) DEP_BIN=1 ;; - -S|--source) BUILDPKG=0 SOURCEONLY=1 ;; - --verifysource) BUILDPKG=0 VERIFYSOURCE=1 ;; - - -h|--help) usage; exit $E_OK ;; - -V|--version) version; exit $E_OK ;; - - --) shift; break ;; - esac - shift -done - -# attempt to consume any extra argv as environment variables. this supports -# overriding (e.g. CC=clang) as well as overriding (e.g. CFLAGS+=' -g'). -extra_environment=() -while [[ $1 ]]; do - if [[ $1 = [_[:alpha:]]*([[:alnum:]_])?(+)=* ]]; then - extra_environment+=("$1") - fi - shift -done - -# setup signal traps -trap 'clean_up' 0 -for signal in TERM HUP QUIT; do - trap "trap_exit $signal \"$(gettext "%s signal caught. Exiting...")\" \"$signal\"" "$signal" -done -trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT -trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR - -load_makepkg_config - -# override settings from extra variables on commandline, if any -if (( ${#extra_environment[*]} )); then - export "${extra_environment[@]}" -fi - -# canonicalize paths and provide defaults if anything is still undefined -for var in PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR; do - printf -v "$var" '%s' "$(canonicalize_path "${!var:-$startdir}")" -done -unset var -PACKAGER=${PACKAGER:-"Unknown Packager"} - - - -# check if messages are to be printed using color -if [[ -t 2 && $USE_COLOR != "n" ]] && check_buildenv "color" "y"; then - colorize -else - unset ALL_OFF BOLD BLUE GREEN RED YELLOW -fi - - -# check makepkg.conf for some basic requirements -lint_config || exit $E_CONFIG_ERROR - - -# check that all settings directories are user-writable -if ! ensure_writable_dir "BUILDDIR" "$BUILDDIR"; then - plainerr "$(gettext "Aborting...")" - exit $E_FS_PERMISSIONS -fi - -if (( ! (NOBUILD || GENINTEG) )) && ! ensure_writable_dir "PKGDEST" "$PKGDEST"; then - plainerr "$(gettext "Aborting...")" - exit $E_FS_PERMISSIONS -fi - -if ! ensure_writable_dir "SRCDEST" "$SRCDEST" ; then - plainerr "$(gettext "Aborting...")" - exit $E_FS_PERMISSIONS -fi - -if (( SOURCEONLY )); then - if ! ensure_writable_dir "SRCPKGDEST" "$SRCPKGDEST"; then - plainerr "$(gettext "Aborting...")" - exit $E_FS_PERMISSIONS - fi - - # If we're only making a source tarball, then we need to ignore architecture- - # dependent behavior. - IGNOREARCH=1 -fi - -if (( LOGGING )) && ! ensure_writable_dir "LOGDEST" "$LOGDEST"; then - plainerr "$(gettext "Aborting...")" - exit $E_FS_PERMISSIONS -fi - -if (( ! INFAKEROOT )); then - if (( EUID == 0 )); then - error "$(gettext "Running %s as root is not allowed as it can cause permanent,\n\ -catastrophic damage to your system.")" "makepkg" - - fi -else - if [[ -z $FAKEROOTKEY ]]; then - error "$(gettext "Do not use the %s option. This option is only for internal use by %s.")" "'-F'" "makepkg" - exit $E_INVALID_OPTION - fi -fi - -unset pkgname "${pkgbuild_schema_strings[@]}" "${pkgbuild_schema_arrays[@]}" -unset "${known_hash_algos[@]/%/sums}" -unset -f pkgver prepare build check package "${!package_@}" -unset "${!makedepends_@}" "${!depends_@}" "${!source_@}" "${!checkdepends_@}" -unset "${!optdepends_@}" "${!conflicts_@}" "${!provides_@}" "${!replaces_@}" -unset "${!cksums_@}" "${!md5sums_@}" "${!sha1sums_@}" "${!sha224sums_@}" -unset "${!sha256sums_@}" "${!sha384sums_@}" "${!sha512sums_@}" "${!b2sums_@}" - -BUILDFILE=${BUILDFILE:-$BUILDSCRIPT} -if [[ ! -f $BUILDFILE ]]; then - error "$(gettext "%s does not exist.")" "$BUILDFILE" - exit $E_PKGBUILD_ERROR - -else - if [[ $(<"$BUILDFILE") = *$'\r'* ]]; then - error "$(gettext "%s contains %s characters and cannot be sourced.")" "$BUILDFILE" "CRLF" - exit $E_PKGBUILD_ERROR - fi - - if [[ ! $BUILDFILE -ef $PWD/${BUILDFILE##*/} ]]; then - error "$(gettext "%s must be in the current working directory.")" "$BUILDFILE" - exit $E_PKGBUILD_ERROR - fi - - if [[ ${BUILDFILE:0:1} != "/" ]]; then - BUILDFILE="$startdir/$BUILDFILE" - fi - source_buildfile "$BUILDFILE" -fi - -pkgbase=${pkgbase:-${pkgname[0]}} - -# check the PKGBUILD for some basic requirements -lint_pkgbuild || exit $E_PKGBUILD_ERROR - -if (( !SOURCEONLY && !PRINTSRCINFO )); then - merge_arch_attrs -fi - -basever=$(get_full_version) - -if [[ $BUILDDIR -ef "$startdir" ]]; then - srcdir="$BUILDDIR/src" - pkgdirbase="$BUILDDIR/pkg" -else - srcdir="$BUILDDIR/$pkgbase/src" - pkgdirbase="$BUILDDIR/$pkgbase/pkg" - -fi - -# set pkgdir to something "sensible" for (not recommended) use during build() -pkgdir="$pkgdirbase/$pkgbase" - -if (( GENINTEG )); then - mkdir -p "$srcdir" - chmod a-s "$srcdir" - cd_safe "$srcdir" - download_sources novcs allarch >&2 - generate_checksums - exit $E_OK -fi - -if have_function pkgver; then - PKGVERFUNC=1 -fi - - - -if (( ${#pkgname[@]} > 1 )) || have_function package_${pkgname}; then - SPLITPKG=1 -fi - -# test for available PKGBUILD functions -if have_function prepare; then - # "Hide" prepare() function if not going to be run - if [[ $RUN_PREPARE != "n" ]]; then - PREPAREFUNC=1 - fi -fi -if have_function build; then - BUILDFUNC=1 -fi -if have_function check; then - # "Hide" check() function if not going to be run - if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv "check" "n" && [[ $RUN_CHECK != "n" ]]; }; then - CHECKFUNC=1 - fi -fi -if have_function package; then - PKGFUNC=1 -fi - -# check if gpg signature is to be created and if signing key is valid -if { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; } || [[ $SIGNPKG == 'y' ]]; then - SIGNPKG='y' - if ! gpg --list-secret-key ${GPGKEY:+"$GPGKEY"} &>/dev/null; then - if [[ ! -z $GPGKEY ]]; then - error "$(gettext "The key %s does not exist in your keyring.")" "${GPGKEY}" - else - error "$(gettext "There is no key in your keyring.")" - fi - exit $E_PRETTY_BAD_PRIVACY - fi -fi - -if (( PACKAGELIST )); then - print_all_package_names - exit $E_OK -fi - -if (( PRINTSRCINFO )); then - write_srcinfo_content - exit $E_OK -fi - -if (( ! PKGVERFUNC )); then - check_build_status -fi - -# Run the bare minimum in fakeroot -if (( INFAKEROOT )); then - if (( SOURCEONLY )); then - create_srcpackage - msg "$(gettext "Leaving %s environment.")" "fakeroot" - exit $E_OK - fi - - prepare_buildenv - - chmod 755 "$pkgdirbase" - if (( ! SPLITPKG )); then - run_single_packaging - else - run_split_packaging - fi - - create_debug_package - - msg "$(gettext "Leaving %s environment.")" "fakeroot" - exit $E_OK -fi - -msg "$(gettext "Making package: %s")" "$pkgbase $basever ($(date +%c))" - -# if we are creating a source-only package, go no further -if (( SOURCEONLY )); then - if [[ -f $SRCPKGDEST/${pkgbase}-${basever}${SRCEXT} ]] \ - && (( ! FORCE )); then - error "$(gettext "A source package has already been built. (use %s to overwrite)")" "-f" - exit $E_ALREADY_BUILT - fi - - # Get back to our src directory so we can begin with sources. - mkdir -p "$srcdir" - chmod a-s "$srcdir" - cd_safe "$srcdir" - if (( SOURCEONLY == 2 )); then - download_sources allarch - elif ( (( ! SKIPCHECKSUMS )) || \ - ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ); then - download_sources allarch novcs - fi - check_source_integrity all - cd_safe "$startdir" - - enter_fakeroot - - if [[ $SIGNPKG = 'y' ]]; then - msg "$(gettext "Signing package...")" - create_signature "$SRCPKGDEST/${pkgbase}-$(get_full_version)${SRCEXT}" - fi - - msg "$(gettext "Source package created: %s")" "$pkgbase ($(date +%c))" - exit $E_OK -fi - -# get back to our src directory so we can begin with sources -mkdir -p "$srcdir" -chmod a-s "$srcdir" -cd_safe "$srcdir" - -if (( !REPKG )); then - if (( NOEXTRACT && ! VERIFYSOURCE )); then - warning "$(gettext "Using existing %s tree")" "\$srcdir/" - else - download_sources - check_source_integrity - (( VERIFYSOURCE )) && exit $E_OK - - if (( CLEANBUILD )); then - msg "$(gettext "Removing existing %s directory...")" "\$srcdir/" - rm -rf "$srcdir"/* - fi - - extract_sources - if (( PREPAREFUNC )); then - run_prepare - fi - if (( REPRODUCIBLE )); then - # We have activated reproducible builds, so unify source times before - # building - find "$srcdir" -exec touch -h -d @$SOURCE_DATE_EPOCH {} + - fi - fi - - if (( PKGVERFUNC )); then - update_pkgver - basever=$(get_full_version) - check_build_status - fi -fi - -if (( NOBUILD )); then - msg "$(gettext "Sources are ready.")" - exit $E_OK -else - # clean existing pkg directory - if [[ -d $pkgdirbase ]]; then - msg "$(gettext "Removing existing %s directory...")" "\$pkgdir/" - rm -rf "$pkgdirbase" - fi - mkdir -p "$pkgdirbase" - chmod a-srw "$pkgdirbase" - cd_safe "$startdir" - - prepare_buildenv - - if (( ! REPKG )); then - (( BUILDFUNC )) && run_build - (( CHECKFUNC )) && run_check - cd_safe "$startdir" - fi - - enter_fakeroot - - create_package_signatures || exit $E_PRETTY_BAD_PRIVACY -fi - -rm -rf $srcdir - - - - -msg "$(gettext "Finished making: %s")" "$pkgbase $basever ($(date +%c))" - - diff --git a/src/config.c b/src/config.c index 55b0f26..8c659a4 100755 --- a/src/config.c +++ b/src/config.c @@ -31,7 +31,7 @@ ConfigEntry configEntries[] = { { "MAKE_FLAGS", "-j1" }, { "SOVIET_DEFAULT_REPO", "OUR" }, { "SOVIET_DEFAULT_REPO_URL", "https://github.com/Soviet-Linux/OUR.git" }, - { "SOVIET_FORMATS", "ecmp" }, + { "SOVIET_FORMATS", "ecmp" }, // Add any new formats (PKGBUILD eventually) here { "SOVIET_SOURCE_DIR", "/usr/src/cccp" }, { "SOVIET_ENV_DIR", "/etc/cccp" }, { "SOVIET_CLEANUP", "/usr/share/info/dir:/usr/share/doc/" }, diff --git a/src/pkg.c b/src/pkg.c index 137359c..69ef604 100644 --- a/src/pkg.c +++ b/src/pkg.c @@ -42,8 +42,12 @@ int open_pkg(const char* path, struct package* pkg, const char* format) { if (format == NULL) { dbg(2, "Getting format from file extension"); format = strrchr(path, '.') + 1; - dbg(1, "Format: %s\n", format); + // if no '.' keep the entire file name + if (format == NULL) { + format = strrchr(path, '/') + 1; + } } + printf("format: %s\n", format); char** FORMATS; int FORMAT_COUNT = splita(getenv("SOVIET_FORMATS"), ' ', &FORMATS);