aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2019-08-16 12:19:43 -0400
committerJason Woodward2019-08-16 14:27:37 -0400
commit525b39ec47a5b52a4cb8c2228ed0b56cbddaf2f1 (patch)
treea847098fb65c532fa6bc2c75be1550995d076f42
parent9136a89ba857ce44763f6c75c40381b891225022 (diff)
downloadslapt-src-525b39ec47a5b52a4cb8c2228ed0b56cbddaf2f1.tar.gz
prompt to continue after presenting %README% information
-rw-r--r--src/main.c10
-rw-r--r--src/source.c64
-rw-r--r--src/source.h9
3 files changed, 56 insertions, 27 deletions
diff --git a/src/main.c b/src/main.c
index c33a381..aa0e87e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -279,6 +279,7 @@ int main(int argc, char *argv[])
/* honor command line option */
config->do_dep = do_dep;
+ config->prompt = prompt;
config->postcmd = postcmd; /* to be freed in slapt_src_config_free */
init_builddir(config);
@@ -353,6 +354,8 @@ int main(int argc, char *argv[])
case FETCH_OPT:
;
+ bool old_prompt = config->prompt;
+ config->prompt = false;
slapt_vector_t_foreach(slapt_src_slackbuild *, fetch_sb, sbs) {
if (simulate) {
printf(gettext("FETCH: %s\n"), fetch_sb->name);
@@ -360,6 +363,7 @@ int main(int argc, char *argv[])
} else
slapt_src_fetch_slackbuild(config, fetch_sb);
}
+ config->prompt = old_prompt;
break;
case BUILD_OPT:
@@ -378,7 +382,8 @@ int main(int argc, char *argv[])
continue;
}
- slapt_src_fetch_slackbuild(config, build_sb);
+ if (!slapt_src_fetch_slackbuild(config, build_sb))
+ exit(EXIT_FAILURE);
slapt_src_build_slackbuild(config, build_sb);
/* XXX we assume if we didn't request the slackbuild, then it is a dependency, and needs to be installed */
@@ -404,7 +409,8 @@ int main(int argc, char *argv[])
continue;
}
- slapt_src_fetch_slackbuild(config, install_sb);
+ if (!slapt_src_fetch_slackbuild(config, install_sb))
+ exit(EXIT_FAILURE);
slapt_src_build_slackbuild(config, install_sb);
slapt_src_install_slackbuild(config, install_sb);
}
diff --git a/src/source.c b/src/source.c
index 822cad8..94e5146 100644
--- a/src/source.c
+++ b/src/source.c
@@ -46,6 +46,7 @@ slapt_src_config *slapt_src_config_init(void)
config->pkgtag = NULL;
config->postcmd = NULL;
config->do_dep = false;
+ config->prompt = true;
return config;
}
@@ -169,9 +170,9 @@ void slapt_src_slackbuild_free(slapt_src_slackbuild *sb)
free(sb);
}
-int slapt_src_update_slackbuild_cache(slapt_src_config *config)
+bool slapt_src_update_slackbuild_cache(slapt_src_config *config)
{
- int rval = 0;
+ bool rval = true;
slapt_config_t *slapt_config = slapt_config_t_init();
slapt_vector_t *slackbuilds = slapt_vector_t_init((slapt_vector_t_free_function)slapt_src_slackbuild_free);
@@ -211,12 +212,12 @@ int slapt_src_update_slackbuild_cache(slapt_src_config *config)
} else {
fprintf(stderr, gettext("Download failed: %s\n"), err);
slapt_clear_head_cache(filename);
- rval = 1;
+ rval = false;
}
} else {
if (strcmp(files[fc], SLAPT_SRC_SOURCES_LIST_GZ) != 0) {
fprintf(stderr, gettext("Download failed: %s\n"), "404");
- rval = 1;
+ rval = false;
}
}
@@ -473,11 +474,12 @@ static char *add_part_to_url(char *url, char *part)
return new;
}
-int slapt_src_fetch_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
+bool slapt_src_fetch_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
{
slapt_vector_t *download_parts = NULL, *md5sum_parts = NULL;
slapt_config_t *slapt_config = slapt_config_t_init();
char *sb_location = add_part_to_url(sb->sb_source_url, sb->location);
+ bool rv = true;
/* need to mkdir and chdir to sb->location */
slapt_create_dir_structure(sb->location);
@@ -595,12 +597,32 @@ int slapt_src_fetch_slackbuild(slapt_src_config *config, slapt_src_slackbuild *s
slapt_config_t_free(slapt_config);
free(sb_location);
+ /* maybe show the README here */
+ if (sb->requires && strstr(sb->requires, "%README%") != NULL) {
+ printf("%%README%%\n");
+ FILE *readme = slapt_open_file("README", "r");
+ if (readme == NULL)
+ exit(EXIT_FAILURE);
+ ssize_t read_size;
+ size_t read_len = 0;
+ char *buffer = NULL;
+ while ((read_size = getline(&buffer, &read_len, readme)) != EOF) {
+ buffer[read_size - 1] = '\0';
+ printf("%s\n", buffer);
+ }
+ if (buffer)
+ free(buffer);
+ if (config->prompt && slapt_ask_yes_no(gettext("Do you want to continue? [y/N] ")) != 1) {
+ rv = false;
+ }
+ }
+
/* go back */
if (chdir(config->builddir) != 0) {
printf(gettext("Failed to chdir to %s\n"), config->builddir);
exit(EXIT_FAILURE);
}
- return 0;
+ return rv;
}
/* reads directory listing of current directory for a package */
@@ -657,7 +679,7 @@ static char *_get_pkg_filename(const char *version, const char *pkgtag)
return filename;
}
-int slapt_src_build_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
+bool slapt_src_build_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
{
char *cwd = NULL;
char *command = NULL;
@@ -745,14 +767,14 @@ int slapt_src_build_slackbuild(slapt_src_config *config, slapt_src_slackbuild *s
exit(EXIT_FAILURE);
}
- return 0;
+ return true;
}
-int slapt_src_install_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
+bool slapt_src_install_slackbuild(slapt_src_config *config, slapt_src_slackbuild *sb)
{
char *filename = NULL;
char *command = NULL;
- int command_len = 38, r = 0;
+ int command_len = 44, r = 0;
if (chdir(sb->location) != 0) {
printf(gettext("Failed to chdir to %s\n"), sb->location);
@@ -762,7 +784,7 @@ int slapt_src_install_slackbuild(slapt_src_config *config, slapt_src_slackbuild
if ((filename = _get_pkg_filename(sb->version, config->pkgtag)) != NULL) {
command_len += strlen(filename);
command = slapt_malloc(sizeof *command * command_len);
- r = snprintf(command, command_len, "upgradepkg --reinstall --install-new %s", filename);
+ r = snprintf(command, command_len, "/sbin/upgradepkg --reinstall --install-new %s", filename);
if (r + 1 != command_len) {
printf(gettext("Failed to construct command string\n"));
exit(EXIT_FAILURE);
@@ -786,7 +808,7 @@ int slapt_src_install_slackbuild(slapt_src_config *config, slapt_src_slackbuild
printf(gettext("Failed to chdir to %s\n"), config->builddir);
exit(EXIT_FAILURE);
}
- return 0;
+ return true;
}
slapt_src_slackbuild *slapt_src_get_slackbuild(slapt_vector_t *sbs, const char *name, const char *version)
@@ -822,7 +844,7 @@ slapt_src_slackbuild *slapt_src_get_slackbuild(slapt_vector_t *sbs, const char *
return NULL;
}
-static int slapt_src_resolve_dependencies(
+static bool slapt_src_resolve_dependencies(
slapt_vector_t *available,
slapt_src_slackbuild *sb,
slapt_vector_t *deps,
@@ -831,7 +853,7 @@ static int slapt_src_resolve_dependencies(
{
slapt_vector_t *requires = NULL;
if (sb->requires == NULL)
- return 0;
+ return true;
if (strstr(sb->requires, ",") != NULL)
requires = slapt_parse_delimited_list(sb->requires, ',');
@@ -839,7 +861,7 @@ static int slapt_src_resolve_dependencies(
requires = slapt_parse_delimited_list(sb->requires, ' ');
if (requires == NULL)
- return 0;
+ return true;
slapt_vector_t_foreach(const char *, dep_name, requires) {
slapt_src_slackbuild *sb_dep = NULL;
@@ -859,9 +881,9 @@ static int slapt_src_resolve_dependencies(
continue;
}
- int dep_check = slapt_src_resolve_dependencies(available, sb_dep, deps, installed, errors);
+ bool dep_check = slapt_src_resolve_dependencies(available, sb_dep, deps, installed, errors);
- if (dep_check != 0) {
+ if (!dep_check) {
slapt_vector_t_free(requires);
return dep_check;
}
@@ -877,13 +899,13 @@ static int slapt_src_resolve_dependencies(
if (slapt_get_newest_pkg(installed, dep_name) == NULL) {
slapt_vector_t_add(errors, slapt_pkg_err_t_init(strdup(sb->name), strdup((char *)dep_name)));
slapt_vector_t_free(requires);
- return 1;
+ return false;
}
}
}
slapt_vector_t_free(requires);
- return 0;
+ return true;
}
slapt_vector_t *slapt_src_names_to_slackbuilds(
@@ -909,9 +931,9 @@ slapt_vector_t *slapt_src_names_to_slackbuilds(
slapt_vector_t *deps = slapt_vector_t_init(NULL);
slapt_vector_t *errors = slapt_vector_t_init((slapt_vector_t_free_function)slapt_pkg_err_t_free);
slapt_vector_t_add(deps, sb); /* mark self as dep to prevent recursion */
- int dep_check = slapt_src_resolve_dependencies(available, sb, deps, installed, errors);
+ bool dep_check = slapt_src_resolve_dependencies(available, sb, deps, installed, errors);
- if (dep_check != 0) {
+ if (!dep_check) {
slapt_vector_t_foreach(slapt_pkg_err_t *, err, errors) {
fprintf(stderr, gettext("Missing slackbuild: %s requires %s\n"), err->pkg, err->error);
}
diff --git a/src/source.h b/src/source.h
index c600cb8..a382bfa 100644
--- a/src/source.h
+++ b/src/source.h
@@ -37,6 +37,7 @@ typedef struct _slapt_src_config_ {
char *pkgtag;
char *postcmd;
bool do_dep;
+ bool prompt;
} slapt_src_config;
slapt_src_config *slapt_src_config_init(void);
void slapt_src_config_free(slapt_src_config *config);
@@ -58,11 +59,11 @@ typedef struct _slapt_src_slackbuild_ {
slapt_src_slackbuild *slapt_src_slackbuild_init(void);
void slapt_src_slackbuild_free(slapt_src_slackbuild *);
-int slapt_src_update_slackbuild_cache(slapt_src_config *);
+bool slapt_src_update_slackbuild_cache(slapt_src_config *);
slapt_vector_t *slapt_src_get_available_slackbuilds(void);
-int slapt_src_fetch_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
-int slapt_src_build_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
-int slapt_src_install_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
+bool slapt_src_fetch_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
+bool slapt_src_build_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
+bool slapt_src_install_slackbuild(slapt_src_config *, slapt_src_slackbuild *);
slapt_vector_t *slapt_src_names_to_slackbuilds(slapt_src_config *, slapt_vector_t *, slapt_vector_t *, slapt_vector_t *);
slapt_vector_t *slapt_src_get_slackbuilds_from_file(const char *);
void slapt_src_write_slackbuilds_to_file(slapt_vector_t *, const char *);