diff --git a/etc/glacier.cfg b/etc/glacier.cfg new file mode 100644 index 0000000..02f0481 --- /dev/null +++ b/etc/glacier.cfg @@ -0,0 +1,41 @@ +# +# 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" ]; + +# Package integrity checking +# WARNING: It is strongly recommended to keep this enabled. +# This ensures all incoming packages are not tampered with. +GLACIER_DO_INT_CHECK = true; + +# Verbose logging +# Enable this option to see exta verbosity. +GLACIER_VERBOSE = false; + +# 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. + +@include "/etc/glacier/profile.cfg"; diff --git a/etc/profile.cfg b/etc/profile.cfg new file mode 100644 index 0000000..74e4df2 --- /dev/null +++ b/etc/profile.cfg @@ -0,0 +1,24 @@ +# +# profile.cfg +# The settings defined in this file descirbe the system's profile. +# For more information on this file, see https://www.everestlinux.org/docs/intro-to-glacier +# + +# Package Repository +# This is the URL which glacier-update-pkgdb will clone to the localdb +GLACIER_REPO = ""; + +# System architecture +# The architecture of your system's CPU +GLACIER_ARCH = ""; + +# Target compulation triplet +# The triplet to be used during compilation, if cross compilation must be invoked +GLACIER_TARGET = ""; + +# System profile +# This variable tells Glacier about your system and which packages can be installed. +# This setting depends on the three above and should not be changed manually. +# If you wixh to migrate system profiles, see https://www.everestlinux.org/docs/musl-or-glibc +GLACIER_SYSTEM_PROFILE = ""; + diff --git a/src/glacier-mkprofile b/src/glacier-mkprofile new file mode 100755 index 0000000..9f7b006 Binary files /dev/null and b/src/glacier-mkprofile differ diff --git a/src/glacier-mkprofile.c b/src/glacier-mkprofile.c new file mode 100644 index 0000000..6132e7e --- /dev/null +++ b/src/glacier-mkprofile.c @@ -0,0 +1,185 @@ +/* + * glacier-mkprofile.c - Create and modify the system profile + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "glacier.h" + +const wchar_t w_check = 0x2713; + +int iprofile; + +static void +usage(int argc, char *argv[]) +{ + printf(COL_BLUE "[*] " COL_RESET "%s - create and modify the system profile\n", argv[0]); + printf(COL_BLUE "[?] " COL_RESET "usage: %s [-h] [-v] [-f] [-u] [-x]\n", argv[0]); + printf("\n"); + printf("%s {-h} Show this message\n", argv[0]); + printf("%s {-v} Show the current version\n", argv[0]); + printf("%s {-l} List available system profiles\n", argv[0]); + printf("%s {-p} PROFILE Create or update the system profile PROFILE at /etc/glacier/profile.cfg\n", argv[0]); + printf("\n"); + printf("Glacier is free software.\n"); + printf("See the GNU GPL version 3 for details.\n"); +} + +static void +usage_small(int argc, char *argv[]) +{ + printf(COL_RED "[x] " COL_RESET "usage: %s [-h] [-v] [-l] [-p]\n", argv[0]); +} + +int +main(int argc, char *argv[]) +{ + if (argc < 2) { + printf(COL_RED "[x] " COL_RESET "%s: not enough arguments (expected 1, got %i)\n", argv[0], argc - 1); + usage_small(argc, argv); + exit(1); + } + + setlocale(LC_CTYPE, ""); + + int opt; + + while ((opt = getopt(argc, argv, "hvlp:")) != -1) { + switch (opt) { + case 'h': + usage(argc, argv); + return 0; + break; + case 'v': + printf(GLACIER_VERSION "\n"); + return 0; + break; + case 'l': + infolog("Available profiles:"); + printf("1)\tx86_64-musl\n"); + printf("\t"); + return 0; + break; + case 'p': + if (argc < 3) { errlog("No system profile specified."); + return 1; + } + + is_process_root("Cannot access the system profile: permission denied. Are you root?"); + + if (strcmp(optarg, "x86_64-musl") == 0) { + infolog ("Using system profile \"x86_64-musl\""); + iprofile = 1; + } else { + fprintf(stderr, COL_RED "[x] " COL_RESET "System profile %s is unknown or not supported.\n", optarg); + return 1; + } + + if (access("/etc/glacier/profile.cfg", F_OK != 0)) { + infolog("No profile exists, skipping backup..."); + } else if (access("/etc/glacier/profile.cfg", F_OK == 0) && access("/etc/glacier/profile.old", F_OK != 0)) { + infolog("Creating backup of old system profile at /etc/glacier/profile.old..."); + + if (remove("/etc/glacier/profile.old") == 0) { + infolog("Removed old backup."); + } + + FILE *oldprofile, *oldprofile_back; + char filename[128], contents; + oldprofile = fopen("/etc/glacier/profile.cfg", "r"); + oldprofile_back = fopen("/etc/glacier/profile.old", "a+"); + contents = fgetc(oldprofile); + + while (contents != EOF) { + fputc(contents, oldprofile_back); + contents = fgetc(oldprofile); + } + + fclose(oldprofile); + fclose(oldprofile_back); + + successlog("Successfully created backup."); + } + + infolog("Creating new profile configuration file..."); + static const char *newprofile = "/etc/glacier/profile.cfg"; + config_t pprofile; + config_setting_t *setting, *root; + + config_init(&pprofile); + + root = config_root_setting(&pprofile); + + if (iprofile == 1) { + infolog("Writing configuration to file..."); + + setting = config_setting_add(root, "GLACIER_REPO", CONFIG_TYPE_STRING); + config_setting_set_string(setting, "https://git.everestlinux.org/EverestLinux/epkgs-x86_64-musl"); + printf("\tGLACIER_REPO = \"https://git.everestlinux.org/EverestLinux/epkgs-x86_64-musl\";\n"); + + setting = config_setting_add(root, "GLACIER_ARCH", CONFIG_TYPE_STRING); + config_setting_set_string(setting, "x86_64"); + printf("\tGLACIER_ARCH = \"x86_64\";\n"); + + setting = config_setting_add(root, "GLACIER_TARGET", CONFIG_TYPE_STRING); + config_setting_set_string(setting, "x86_64-linux-musl"); + printf("\tGLACIER_TARGET = \"x86_64-linux-musl\";\n"); + + setting = config_setting_add(root, "GLACIER_LOCALDB", CONFIG_TYPE_STRING); + config_setting_set_string(setting, "/glacier/localdb/epkgs-x86_64-musl"); + printf("\tGLACIER_LOCALDB = \"/glacier/localdb/epkgs-x86_64-musl\";\n"); + + setting = config_setting_add(root, "GLACIER_SYSTEM_PROFILE", CONFIG_TYPE_STRING); + config_setting_set_string(setting, "x86_64-musl"); + printf("\tGLACIER_SYSTEM_PROFILE = \"x86_64-musl\";\n"); + } + + if (! config_write_file(&pprofile, newprofile)) { + errlog("Error while applying new profile to configuration."); + config_destroy(&pprofile); + return(EXIT_FAILURE); + } + + successlog("Successfully updated system profile."); + config_destroy(&pprofile); + return(EXIT_SUCCESS); + break; + case '?': + printf(COL_RED "[x] " COL_RESET "%s: Unknown argument '%s'.\n", argv[0], argv[1]); + usage_small(argc, argv); + return 1; + break; + } + + } + + printf(COL_RED "[x] " COL_RESET "%s: Unknown argument '%s'.\n", argv[0], argv[1]); + usage_small(argc, argv); + return 1; +} diff --git a/src/glacier-update-pkgdb b/src/glacier-update-pkgdb new file mode 100755 index 0000000..699da3a Binary files /dev/null and b/src/glacier-update-pkgdb differ diff --git a/src/glacier-update-pkgdb.c b/src/glacier-update-pkgdb.c new file mode 100644 index 0000000..37c1bb3 --- /dev/null +++ b/src/glacier-update-pkgdb.c @@ -0,0 +1,79 @@ +/* + * glacier-update-pkgdb.c - Update the local package database + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "glacier.h" + +static void +usage(int argc, char *argv[]) +{ + printf(COL_BLUE "[*] " COL_RESET "%s - update the local package database\n", argv[0]); + printf(COL_BLUE "[?] " COL_RESET "usage: %s [-h] [-v] [-u]\n", argv[0]); + printf("\n"); + printf("%s {-h} Show this messsage\n", argv[0]); + printf("%s {-v} Show the current version\n", argv[0]); + printf("%s {-u} Update the local database\n", argv[0]); + printf("\n"); + printf("Glacier is free software.\n"); + printf("See the GNU GPL version 3 for details.\n"); +} + +static void +usage_small(int argc, char *argv[]) +{ + printf(COL_RED "[x] " COL_RESET "usage: %s [-h] [-v] [-u]\n", argv[0]); +} + +int +main(int argc, char *argv[]) +{ + if (argc < 2) { + printf(COL_RED "[x] " COL_RESET "%s: not enough arguments (expected 1, got %i)\n", argv[0], argc - 1); + usage_small(argc, argv); + exit(1); + } + + int opt; + + while ((opt = getopt(argc, argv, "hvu:")) != -1) { + switch (opt) { + case 'h': + usage(argc, argv); + return 0; + break; + case 'v': + printf(GLACIER_VERSION "\n"); + return 0; + break; + case 'u': + return 0; + break; + } + } +} diff --git a/src/glacier.h b/src/glacier.h new file mode 100644 index 0000000..5f5c5c2 --- /dev/null +++ b/src/glacier.h @@ -0,0 +1,25 @@ +/* + * glacier.h - Operate on the user package index + * + * This file is patr 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 . + */ + +#ifndef GLACIER_H_ +#define GLACIER_H_ + +#define GLACIER_VERSION "4.0.0rc" + +#endif + + diff --git a/src/gpkg b/src/gpkg new file mode 100755 index 0000000..5b44d78 Binary files /dev/null and b/src/gpkg differ diff --git a/src/gpkg.c b/src/gpkg.c index cc6363b..9c8d5b2 100644 --- a/src/gpkg.c +++ b/src/gpkg.c @@ -1,7 +1,7 @@ /* * gpkg.c - Operate on the user package index * - * This file is patr of 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 @@ -15,30 +15,31 @@ * not, see . */ +#include +#include #include #include +#include #include -/* -#include -#include -#include -#include +#include +#include +#include +#include -#include "gpkg.h" -*/ +#include "glacier.h" static void usage(int argc, char *argv[]) { - printf("%s - operate on the user package index\n", argv[0]); - printf("usage: %s [-h] [-v] [-f] [-u] [-x]\n", argv[0]); + printf(COL_BLUE "[*] " COL_RESET "%s - operate on the user package index\n", argv[0]); + printf(COL_BLUE "[?] " COL_RESET "usage: %s [-h] [-v] [-f] [-u] [-x]\n", argv[0]); printf("\n"); printf("%s {-h} Show this message\n", argv[0]); - printf("%s {-v} Show the current version\n", argv[0]); - printf("%s {-f} PKG Install package PKG\n", argv[0]); - printf("%s {-u} PKG Update package PKG\n", argv[0]); - printf("%s {-x} PKG Remove package PKG\n", argv[0]); + printf("%s {-v} Show the current version\n", argv[0]); + printf("%s {-f} PKG Install package PKG\n", argv[0]); + printf("%s {-u} PKG Update package PKG\n", argv[0]); + printf("%s {-x} PKG Remove package PKG\n", argv[0]); printf("\n"); printf("Glacier is free software.\n"); printf("See the GNU GPL version 3 for details.\n"); @@ -47,45 +48,65 @@ usage(int argc, char *argv[]) static void usage_small(int argc, char *argv[]) { - printf("usage: %s [-h] [-v] [-f] [-u] [-x]\n", argv[0]); + printf(COL_RED "[x] " COL_RESET "usage: %s [-h] [-v] [-f] [-u] [-x]\n", argv[0]); } int main(int argc, char *argv[]) { if (argc < 2) { + printf(COL_RED "[x] " COL_RESET "%s: not enough arguments (expected 1, got %i)\n", argv[0], argc - 1); usage_small(argc, argv); - return 1; + exit(1); } int opt; - while ((opt = getopt(argc, argv, ":if:hvfux")) != -1) { - switch(opt) { - case 'h': - usage(argc, argv); - return 0; - break; - case 'v': - /* printf(GPKG_VERSION "\n"); */ - printf("v4.0.0\n"); - return 0; - break; - case 'f': - return 0; - break; - case 'u': - return 0; - break; - case 'x': - return 0; - break; - case '?': - usage_small(argc, argv); - return 1; - break; + while ((opt = getopt(argc, argv, "hvfux:")) != -1) { + switch(opt) { + case 'h': + usage(argc, argv); + return 0; + break; + case 'v': + printf(GLACIER_VERSION "\n"); + return 0; + break; + case 'f': + if (argc < 3) { errlog("No package(s) specified."); return 1; } + if (is_process_root() == 0) { + errlog("Failed to open package index: permission denied. Are you root?"); + return(EXIT_FAILURE); } + runtime_exists(); + if (errno != 0) { exit(1); } + init_config(); + load_all_from_config(); + mkworkspace(); + die_config(); + return 0; + break; + case 'u': + if (argc < 3) { errlog("No package(s) specified."); return 1; } + is_process_root("Failed to open package index: permission denied. Are you root?"); + mkworkspace(); + return 0; + break; + case 'x': + if (argc < 3) { errlog("No package(s) specified."); return 1; } + is_process_root("Failed to open package index: permission denied. Are you root?"); + mkworkspace(); + return 0; + break; + case '?': + printf(COL_RED "[x] " COL_RESET "%s: Unknown argument '%s'.\n", argv[0], argv[1]); + usage_small(argc, argv); + return 1; + break; + } } - - return 0; + + printf(COL_RED "[x] " COL_RESET "%s: Unknown argument '%s'.\n", argv[0], argv[1]); + usage_small(argc, argv); + return 1; } diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..0a24a95 --- /dev/null +++ b/src/log.c @@ -0,0 +1,7 @@ +#include + +int +main() +{ + successlog("hi"); +}