#ifndef APT_LAYER_H #define APT_LAYER_H #include #include #include #include #include #include #include #include // Version information #define APT_LAYER_VERSION "1.0.0" #define APT_LAYER_NAME "apt-layer" // Configuration defaults #define DEFAULT_WORKSPACE "/workspace" #define DEFAULT_OSTREE_REPO "/workspace/cache/ostree-repo" #define DEFAULT_BUILD_DIR "/workspace/cache/build" #define DEFAULT_CONTAINER_RUNTIME "podman" // Error codes typedef enum { APT_LAYER_SUCCESS = 0, APT_LAYER_ERROR_INVALID_ARGS = 1, APT_LAYER_ERROR_DEPENDENCIES = 2, APT_LAYER_ERROR_OSTREE = 3, APT_LAYER_ERROR_APT = 4, APT_LAYER_ERROR_CONTAINER = 5, APT_LAYER_ERROR_CONFIG = 6, APT_LAYER_ERROR_PERMISSION = 7, APT_LAYER_ERROR_IO = 8 } apt_layer_error_t; // Log levels typedef enum { LOG_LEVEL_ERROR = 0, LOG_LEVEL_WARNING = 1, LOG_LEVEL_INFO = 2, LOG_LEVEL_DEBUG = 3 } log_level_t; // Command types typedef enum { CMD_CREATE = 0, CMD_LIST = 1, CMD_INFO = 2, CMD_ROLLBACK = 3, CMD_CONTAINER = 4, CMD_OCI_EXPORT = 5, CMD_HELP = 6, CMD_VERSION = 7 } command_type_t; // Configuration structure typedef struct { char workspace[256]; char ostree_repo[256]; char build_dir[256]; char container_runtime[64]; log_level_t log_level; bool debug; bool verbose; } apt_layer_config_t; // Command structure typedef struct { command_type_t type; char base_branch[256]; char new_branch[256]; char **packages; int package_count; char image_name[256]; char recipe_file[256]; } apt_layer_command_t; // Global configuration extern apt_layer_config_t config; // Function declarations // Configuration apt_layer_error_t config_init(apt_layer_config_t *config); apt_layer_error_t config_load_from_file(apt_layer_config_t *config, const char *filename); apt_layer_error_t config_load_from_env(apt_layer_config_t *config); // Logging void log_init(log_level_t level); void log_error(const char *format, ...); void log_warning(const char *format, ...); void log_info(const char *format, ...); void log_debug(const char *format, ...); void log_success(const char *format, ...); void log_layer(const char *format, ...); void log_container(const char *format, ...); // CLI apt_layer_error_t cli_parse_args(int argc, char *argv[], apt_layer_command_t *cmd); void cli_show_usage(void); void cli_show_version(void); // Dependencies apt_layer_error_t check_dependencies(const apt_layer_command_t *cmd); // OSTree operations apt_layer_error_t ostree_init_repo(const char *repo_path); apt_layer_error_t ostree_checkout_branch(const char *repo_path, const char *branch, const char *checkout_path); apt_layer_error_t ostree_create_commit(const char *repo_path, const char *branch, const char *tree_path, const char *subject); apt_layer_error_t ostree_list_branches(const char *repo_path); apt_layer_error_t ostree_show_branch_info(const char *repo_path, const char *branch); apt_layer_error_t ostree_rollback_branch(const char *repo_path, const char *branch); // Layer operations apt_layer_error_t layer_create(const apt_layer_command_t *cmd); apt_layer_error_t layer_create_container(const apt_layer_command_t *cmd); apt_layer_error_t layer_export_oci(const apt_layer_command_t *cmd); // Package management apt_layer_error_t apt_install_packages(const char *chroot_path, char **packages, int package_count); apt_layer_error_t apt_update(const char *chroot_path); apt_layer_error_t apt_cleanup(const char *chroot_path); // Container operations apt_layer_error_t container_build_image(const char *containerfile, const char *context, const char *image_name); apt_layer_error_t container_extract_filesystem(const char *image_name, const char *extract_path); // Utility functions apt_layer_error_t execute_command(const char *command, char **args, int arg_count); apt_layer_error_t execute_command_with_output(const char *command, char **args, int arg_count, char *output, size_t output_size); bool file_exists(const char *path); bool directory_exists(const char *path); apt_layer_error_t create_directory(const char *path); apt_layer_error_t remove_directory(const char *path); char *strdup_safe(const char *str); // Memory management void free_string_array(char **array, int count); #endif // APT_LAYER_H