init
This commit is contained in:
commit
b7b31abc0e
19
Makefile
Normal file
19
Makefile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
include config.mk
|
||||||
|
|
||||||
|
all:
|
||||||
|
@echo "Run 'make test' for the test binary, or 'make lib' to generate a static library."
|
||||||
|
@echo "Run 'make help' for a full list of options."
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "Make options for libglacier:"
|
||||||
|
@echo ""
|
||||||
|
@echo "lib - generate the static library"
|
||||||
|
@echo "test - generate a test binary"
|
||||||
|
@echo "clean - remove all generated files"
|
||||||
|
|
||||||
|
test:
|
||||||
|
$(CC) libglacier.c $(LIBFLAGS) -o libglacier.test
|
||||||
|
cp etc/example.cfg ./glacier.cfg
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm libglacier.test libglacier.a glacier.cfg
|
15
README
Normal file
15
README
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
+ libglacier
|
||||||
|
|
||||||
|
The underlying C libraries for the Glacier package manager
|
||||||
|
|
||||||
|
+ Rationale
|
||||||
|
|
||||||
|
Glacier has been written in Bash since its conception. For obvious reasons, this is terrible for portability.
|
||||||
|
While writing an entire library for a project that's been in the works for a year at this point will take
|
||||||
|
much more time, it should futureproof Glacier and make it easier to deploy and test.
|
||||||
|
|
||||||
|
+ Usage
|
||||||
|
|
||||||
|
#include <glacier_log.h>
|
||||||
|
#include <glacier_config.h>
|
||||||
|
|
8
config.mk
Normal file
8
config.mk
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#
|
||||||
|
# config.mk
|
||||||
|
#
|
||||||
|
|
||||||
|
CC = /bin/gcc
|
||||||
|
AR = /bin/ar
|
||||||
|
|
||||||
|
LIBFLAGS = -lconfig
|
34
etc/example.cfg
Normal file
34
etc/example.cfg
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# glacier.cfg
|
||||||
|
# The settings defined in this file will be loaded when Glacier is called.
|
||||||
|
# For more information on this file, see https://www.everestlinux.org/docs/intro-to-glacier
|
||||||
|
#
|
||||||
|
|
||||||
|
# Services
|
||||||
|
# Whether Glacier will allow external service files to be called
|
||||||
|
# WARNING: Services may pose a security risk to your system. Only use services you trust.
|
||||||
|
GLACIER_ALLOW_SERVICES = false;
|
||||||
|
|
||||||
|
# Permitted software licenses
|
||||||
|
# When installing a package, Glacier will check its license. If said license is listed here,
|
||||||
|
# it will proceed with the installation. Otherwise, it'll return an error.
|
||||||
|
# For more information on licenses listed below, see https://www.everestlinux.org/docs/intro-to-glacier
|
||||||
|
# Some common license names with their designation codes are:
|
||||||
|
# - GNU General Public License (GPL)
|
||||||
|
# - MIT License (MIT)
|
||||||
|
# - BSD License (BSD)
|
||||||
|
# - Apache license (APACHE)
|
||||||
|
# - Binary-redistributable software (BIN-REDIST)
|
||||||
|
# - End-user-license-agreement (EULA)
|
||||||
|
# If, for any reason, a package uses a custom license, you can simply add it to this list.
|
||||||
|
GLACIER_ALLOWED_LICENSES = [ "GPL", "MIT", "BSD", "APACHE" ]
|
||||||
|
|
||||||
|
# Profile-specific settings
|
||||||
|
# WARNING: The settings below are tied into the system's profile. Changing any of these manually
|
||||||
|
# will certainly cause breakage.
|
||||||
|
# If, for any reason, you must change any of these settings, use `glacier-mkprofile`.
|
||||||
|
# Profile migration may cause breakage. Doing a clean install is the preferred method for changing profiles.
|
||||||
|
|
||||||
|
### DO NOT EDIT ANY SETTINGS BELOW THIS LINE ###
|
||||||
|
### DO NOT EDIT ANY SETTINGS BELOW THIS LINE ###
|
||||||
|
### DO NOT EDIT ANY SETTINGS BELOW THIS LINE ###
|
68
include/glacier_config.h
Normal file
68
include/glacier_config.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* glacier.h - Function declarations for libglacier
|
||||||
|
*
|
||||||
|
* This file is part of Glacier.
|
||||||
|
*
|
||||||
|
* Glacier 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 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Glacier 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 Glacier. If
|
||||||
|
* not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLACIERCONFIG_H_
|
||||||
|
#define GLACIERCONFIG_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* init_config
|
||||||
|
* DESCRIPTION: Init_config initializes the libconfig library, so it can read the required runtime files
|
||||||
|
* PARAMETERS:
|
||||||
|
* None.
|
||||||
|
* RETURN VAUES:
|
||||||
|
* 0 on success, 1 on failure
|
||||||
|
* CAVEATS:
|
||||||
|
* None.
|
||||||
|
* EXAMPLE:
|
||||||
|
* init_config();
|
||||||
|
*/
|
||||||
|
|
||||||
|
int init_config();
|
||||||
|
|
||||||
|
/**************************************************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* die_config
|
||||||
|
* DESCRPTION: Die_config destroys the loaded libconfig library.
|
||||||
|
* PARAMETERS:
|
||||||
|
* None.
|
||||||
|
* RETURN VALUES:
|
||||||
|
* 0 on success, 1 on failure
|
||||||
|
* CAVEATS:
|
||||||
|
* None.
|
||||||
|
* EXAMPLE:
|
||||||
|
* die_config();
|
||||||
|
*/
|
||||||
|
|
||||||
|
int die_config();
|
||||||
|
|
||||||
|
/**************************************************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* load_setting_from_config
|
||||||
|
* DESCRIPTION: Initialize all settings from glacier.cfg.
|
||||||
|
* PARAMETERS:
|
||||||
|
* None.
|
||||||
|
* RETURN VALUES:
|
||||||
|
* None.
|
||||||
|
* EXAMPLE:
|
||||||
|
* load_setting_from_config();
|
||||||
|
*/
|
||||||
|
|
||||||
|
void load_setting_from_config();
|
||||||
|
|
||||||
|
#endif
|
78
include/glacier_log.h
Normal file
78
include/glacier_log.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* glacier_log.h - Logging function declarations for libglacier
|
||||||
|
*
|
||||||
|
* This file is part of Glacier.
|
||||||
|
*
|
||||||
|
* Glacier 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 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Glacier 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 Glacier. If
|
||||||
|
* not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLACIERLOG_H_
|
||||||
|
#define GLACIERLOG_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* infolog
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Infolog outputs a stylized info message. It follows Glacier's uniform CLI style.
|
||||||
|
* PARAMETERS:
|
||||||
|
* char MSG[] -> The message to output
|
||||||
|
* RETURN VALUES:
|
||||||
|
* None.
|
||||||
|
* CAVEATS:
|
||||||
|
* * Cannot output variables. If you must output variables, use printf instead.
|
||||||
|
* * A NEWLINE ('\n') character is implied, therefore putting one at the end of
|
||||||
|
* a string is not needed.
|
||||||
|
* EXAMPLE:
|
||||||
|
* infolog("This is an info message.");
|
||||||
|
*/
|
||||||
|
|
||||||
|
void infolog(char MSG[]);
|
||||||
|
|
||||||
|
/**************************************************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* warnlog
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Warnlog outputs a stylized warning message. It follows Glacier's uniform CLI style.
|
||||||
|
* PARAMETERS:
|
||||||
|
* char MSG[] -> The message to output
|
||||||
|
* RETURN VALUES:
|
||||||
|
* None.
|
||||||
|
* CAVEATS:
|
||||||
|
* * Cannot output variables. If you must output variables, use printf instead.
|
||||||
|
* * A NEWLINE ('\n') character is implied, therefore putting one at the end of
|
||||||
|
* a string is not needed.
|
||||||
|
* EXAMPLE:
|
||||||
|
* warnlog("This is a warning message.");
|
||||||
|
*/
|
||||||
|
|
||||||
|
void warnlog(char MSG[]);
|
||||||
|
|
||||||
|
/**************************************************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* errlog
|
||||||
|
* DESCRIPTION: Errlog outputs a stylized error message. It follows Glacier's uniform CLI style.
|
||||||
|
* PARAMETERS:
|
||||||
|
* char MSG[] -> The message to output
|
||||||
|
* RETURN VALUES:
|
||||||
|
* None.
|
||||||
|
* CAVEATS:
|
||||||
|
* * Cannot output variables. If you must output variables, use printf instead.
|
||||||
|
* * A NEWLINE ('\n') character is implied, therefore putting one at the end of
|
||||||
|
* a string is not needed.
|
||||||
|
* EXAMPLE:
|
||||||
|
* errlog("This is an error message.");
|
||||||
|
*/
|
||||||
|
|
||||||
|
void errlog(char MSG[]);
|
||||||
|
|
||||||
|
#endif
|
24
include/glacier_runtime.h
Normal file
24
include/glacier_runtime.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* glacier_runtime.h - Runtime function declarations for libglacier
|
||||||
|
*
|
||||||
|
* This file is part of Glacier.
|
||||||
|
*
|
||||||
|
* Glacier 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 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Glacier 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 Glacier. If
|
||||||
|
* not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GLACIERRUNTIME_H_
|
||||||
|
#define GLACIERRUNTIME_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* runtime_exists
|
||||||
|
*
|
||||||
|
* DESCRIPTION: runtime_exists checks if all necessary runtime files exist.
|
165
libglacier.c
Normal file
165
libglacier.c
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* libglacier.c - Backend C library for Glacier
|
||||||
|
*
|
||||||
|
* This file is part of Glacier.
|
||||||
|
*
|
||||||
|
* Glacier 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 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Glacier 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 Glacier. If
|
||||||
|
* not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <color.h>
|
||||||
|
#include <libconfig.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* Global variables */
|
||||||
|
|
||||||
|
config_t cfg;
|
||||||
|
config_setting_t *setting;
|
||||||
|
const char str;
|
||||||
|
int GLACIER_ALLOW_SERVICES;
|
||||||
|
char GLACIER_ALLOWED_LICENSES;
|
||||||
|
|
||||||
|
const char *runtime_files[] = { "/etc/glacier.cfg", "/etc/glacier/call-hooks", "/etc/make.conf" };
|
||||||
|
|
||||||
|
/*
|
||||||
|
* infolog
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Output a stylized info message.
|
||||||
|
* PARAMETERS: char MSG[]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
infolog(char MSG[])
|
||||||
|
{
|
||||||
|
if (MSG == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(COL_BLUE "[i]" COL_RESET " %s\n", MSG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* warnlog
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Output a stylized warning message.
|
||||||
|
* Parameters: char MSG[]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
warnlog(char MSG[])
|
||||||
|
{
|
||||||
|
if (MSG == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(COL_YELLOW "[!]" COL_RESET " %s\n", MSG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* errlog
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Output a stylized error message.
|
||||||
|
* PARAMETERS: char MSG[]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
errlog(char MSG[])
|
||||||
|
{
|
||||||
|
if (MSG == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, COL_RED "[x]" COL_RESET " %s\n", MSG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* runtime_exists
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Check if necesary runtime files exist.
|
||||||
|
* PARAMETERS: None.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
runtime_exists()
|
||||||
|
{
|
||||||
|
int f;
|
||||||
|
|
||||||
|
for (f = 0; f < 3; f++) {
|
||||||
|
if (access(runtime_files[f], F_OK) == 0) {
|
||||||
|
printf("%s exists\n", runtime_files[f]);
|
||||||
|
} else {
|
||||||
|
printf("%s does not exist\n", runtime_files[f]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* init_config
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Initialize libconfig.
|
||||||
|
* PARAMETERS: None.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
init_config()
|
||||||
|
{
|
||||||
|
config_init(&cfg);
|
||||||
|
|
||||||
|
if (! config_read_file(&cfg, "glacier.cfg")) {
|
||||||
|
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
|
||||||
|
config_error_line(&cfg), config_error_text(&cfg));
|
||||||
|
config_destroy(&cfg);
|
||||||
|
return(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
infolog("Initialized libconfig");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
die_config()
|
||||||
|
{
|
||||||
|
config_destroy(&cfg);
|
||||||
|
infolog("Destroyed libconfig");
|
||||||
|
return(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
load_setting_from_config()
|
||||||
|
{
|
||||||
|
if(config_lookup_bool(&cfg, "GLACIER_ALLOW_SERVICES", &GLACIER_ALLOW_SERVICES))
|
||||||
|
printf("Services allowed: %s\n", GLACIER_ALLOW_SERVICES ? "true" : "false");
|
||||||
|
else
|
||||||
|
warnlog("GLACIER_SERVICES_ALLOWED is not defined in glacier.cfg.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
errlog("Unknown option.");
|
||||||
|
printf(COL_RED "[x]" COL_RESET " usage: %s [-h] [-v] [-f] [-u] [-x] [-fl] [-ul] [-d] [-s] PKG\n", argv[0]);
|
||||||
|
runtime_exists();
|
||||||
|
init_config();
|
||||||
|
load_setting_from_config();
|
||||||
|
die_config();
|
||||||
|
}
|
26
lua.c
Normal file
26
lua.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
#include <lualib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
char buff[256];
|
||||||
|
int error;
|
||||||
|
lua_State *L = lua_open();
|
||||||
|
luaL_openlibs(L);
|
||||||
|
|
||||||
|
while (fgets(buff, sizeof(buff), stdin) != NULL) {
|
||||||
|
error = lua_loadbuffer(L, buff, strlen(buff), "line") ||
|
||||||
|
lua_pcall(L, 0, 0, 0);
|
||||||
|
if (error) {
|
||||||
|
fprintf(stderr, "%s", lua_tostring(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_close(L);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user