src/cli/lib/command.c \
src/cli/lib/command.h \
src/cli/lib/dump.c \
- src/cli/lib/dump.h
+ src/cli/lib/dump.h \
+ src/cli/lib/terminal.c \
+ src/cli/lib/terminal.h
libcli_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2023 Pakfire development team #
+# #
+# 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 3 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 <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <pakfire/pakfire.h>
+
+#include "terminal.h"
+
+static int cli_term_is_interactive(void) {
+ return isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) && isatty(STDERR_FILENO);
+}
+
+int cli_term_confirm(struct pakfire* pakfire,
+ void* data, const char* message, const char* question) {
+ char* line = NULL;
+ size_t length = 0;
+ int r = 1;
+
+ // Show the message if any
+ if (message)
+ printf("%s\n", message);
+
+ for (;;) {
+ // Print question
+ printf("%s ", question);
+
+ // Do not wait for any input if the terminal isn't interactive
+ if (!cli_term_is_interactive())
+ break;
+
+ // Wait for the user to enter something
+ ssize_t bytes_read = getline(&line, &length, stdin);
+ if (bytes_read < 0) {
+ r = bytes_read;
+ goto END;
+
+ // If we have read more than one character + newline, we will ask again
+ } else if (bytes_read > 2)
+ continue;
+
+ // Check the response
+ switch (*line) {
+ // Yes!
+ case 'Y':
+ case 'y':
+ r = 0;
+ goto END;
+
+ // No!
+ case 'N':
+ case 'n':
+ r = 1;
+ goto END;
+
+ // Ask again for any other inputs
+ default:
+ continue;
+ }
+ }
+
+END:
+ if (line)
+ free(line);
+
+ return r;
+}
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2023 Pakfire development team #
+# #
+# 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 3 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 <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef PAKFIRE_CLI_TERMINAL_H
+#define PAKFIRE_CLI_TERMINAL_H
+
+#include <pakfire/pakfire.h>
+
+int cli_term_confirm(struct pakfire* pakfire,
+ void* data, const char* message, const char* question);
+
+#endif /* PAKFIRE_CLI_TERMINAL_H */
#include <pakfire/pakfire.h>
#include "command.h"
+#include "terminal.h"
+
#include "clean.h"
#include "info.h"
#include "install.h"
if (r)
goto ERROR;
+ // Configure callbacks
+ pakfire_set_confirm_callback(pakfire, cli_term_confirm, NULL);
+
// Enable repositories
for (unsigned int i = 0; i < config.num_enable_repos; i++)
cli_set_repo_enabled(pakfire, config.enable_repos[i], 1);
cli_transaction_callback callback, void* data) {
struct pakfire_transaction* transaction = NULL;
char* problems = NULL;
- char* dump = NULL;
int r;
// Create a new transaction
goto ERROR;
}
- // Dump the transaction
- dump = pakfire_transaction_dump(transaction, 0);
- if (dump)
- printf("%s\n", dump);
-
// Run the transaction
r = pakfire_transaction_run(transaction);
if (r)
pakfire_transaction_unref(transaction);
if (problems)
free(problems);
- if (dump)
- free(dump);
return r;
}