From 9dbf79c3e3810c593c6f14ecb2b6d6eb16b326a5 Mon Sep 17 00:00:00 2001 From: Patrick Gaskin Date: Mon, 1 Jun 2020 11:45:15 -0400 Subject: [PATCH] Implemented NM_UNINSTALL_CONFIGDIR build option (closes #34) (#37) This option allows NickelMenu to be uninstalled by deleting the config dir. --- .drone.yml | 24 ++++++++++++++++-------- Makefile | 9 ++++++++- src/config.c | 8 -------- src/config.h | 8 ++++++++ src/init.c | 20 ++++++++++++++++++-- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/.drone.yml b/.drone.yml index 1b838a0..f55038d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,8 +11,18 @@ steps: when: event: [push, pull_request, tag] commands: + - make clean - make all koboroot - mkdir out && mv KoboRoot.tgz src/libnm.so out/ +- name: build-NM_UNINSTALL_CONFIGDIR + image: docker.io/geek1011/nickeltc:1.0 + when: + event: [push, pull_request, tag] + commands: + - make clean + - make all koboroot NM_UNINSTALL_CONFIGDIR=1 + - mkdir out/with-NM_UNINSTALL_CONFIGDIR && mv KoboRoot.tgz src/libnm.so out/with-NM_UNINSTALL_CONFIGDIR/ + depends_on: [build] - name: test-syms image: golang:1.14 when: @@ -30,9 +40,9 @@ steps: access_key: nickelmenu secret_key: {from_secret: S3_SECRET_NICKELMENU} target: artifacts/build/${DRONE_BUILD_NUMBER} - source: out/* + source: out/**/* strip_prefix: out/ - depends_on: [build] + depends_on: [build, build-NM_UNINSTALL_CONFIGDIR] - name: upload-tag image: plugins/s3 when: @@ -42,11 +52,9 @@ steps: access_key: nickelmenu secret_key: {from_secret: S3_SECRET_NICKELMENU} target: artifacts/tag/${DRONE_TAG} - source: out/* + source: out/**/* strip_prefix: out/ - when: - event: [tag] - depends_on: [build] + depends_on: [build, build-NM_UNINSTALL_CONFIGDIR] - name: upload-commit image: plugins/s3 when: @@ -57,6 +65,6 @@ steps: access_key: nickelmenu secret_key: {from_secret: S3_SECRET_NICKELMENU} target: artifacts/commit/${DRONE_COMMIT} - source: out/* + source: out/**/* strip_prefix: out/ - depends_on: [build] + depends_on: [build, build-NM_UNINSTALL_CONFIGDIR] diff --git a/Makefile b/Makefile index 2dcdc20..d987660 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,14 @@ override LDFLAGS += -Wl,--no-undefined -Wl,-rpath,/usr/local/Kobo -Wl,-rpath,/u NM_VERSION := $(shell git describe --tags --always --dirty) # Only use it if we got something useful out of git describe... ifdef NM_VERSION - override CPPFLAGS += -DNM_VERSION='"$(NM_VERSION)"' + override CPPFLAGS += -DNM_VERSION='"$(NM_VERSION)"' +endif + +ifeq ($(NM_UNINSTALL_CONFIGDIR),1) + $(info -- NM_UNINSTALL_CONFIGDIR... enabled) + override CPPFLAGS += -DNM_UNINSTALL_CONFIGDIR +else + $(info -- NM_UNINSTALL_CONFIGDIR... disabled) endif endif diff --git a/src/config.c b/src/config.c index 026cdbc..57e96a9 100644 --- a/src/config.c +++ b/src/config.c @@ -15,14 +15,6 @@ #include "menu.h" #include "util.h" -#ifndef NM_CONFIG_DIR -#define NM_CONFIG_DIR "/mnt/onboard/.adds/nm" -#endif - -#ifndef NM_CONFIG_MAX_MENU_ITEMS_PER_MENU -#define NM_CONFIG_MAX_MENU_ITEMS_PER_MENU 50 -#endif - typedef enum { NM_CONFIG_TYPE_MENU_ITEM = 1, NM_CONFIG_TYPE_GENERATOR = 2, diff --git a/src/config.h b/src/config.h index 7adfd10..864bd8f 100644 --- a/src/config.h +++ b/src/config.h @@ -7,6 +7,14 @@ extern "C" { #include #include "menu.h" +#ifndef NM_CONFIG_DIR +#define NM_CONFIG_DIR "/mnt/onboard/.adds/nm" +#endif + +#ifndef NM_CONFIG_MAX_MENU_ITEMS_PER_MENU +#define NM_CONFIG_MAX_MENU_ITEMS_PER_MENU 50 +#endif + typedef struct nm_config_t nm_config_t; // nm_config_parse parses the configuration files in /mnt/onboard/.adds/nm. diff --git a/src/init.c b/src/init.c index 290c91c..2cd71cd 100644 --- a/src/init.c +++ b/src/init.c @@ -22,6 +22,13 @@ __attribute__((constructor)) void nm_init() { char *err; NM_LOG("version: " NM_VERSION); + #ifdef NM_UNINSTALL_CONFIGDIR + NM_LOG("feature: NM_UNINSTALL_CONFIGDIR: true"); + #else + NM_LOG("feature: NM_UNINSTALL_CONFIGDIR: false"); + #endif + NM_LOG("config dir: %s", NM_CONFIG_DIR); + NM_LOG("init: creating failsafe"); nm_failsafe_t *fs; if (!(fs = nm_failsafe_create(&err)) && err) { @@ -31,13 +38,22 @@ __attribute__((constructor)) void nm_init() { } NM_LOG("init: checking for uninstall flag"); - if (!access("/mnt/onboard/.adds/nm/uninstall", F_OK)) { + if (!access(NM_CONFIG_DIR "/uninstall", F_OK)) { NM_LOG("init: flag found, uninstalling"); nm_failsafe_uninstall(fs); - unlink("/mnt/onboard/.adds/nm/uninstall"); + unlink(NM_CONFIG_DIR "/uninstall"); goto stop; } + #ifdef NM_UNINSTALL_CONFIGDIR + NM_LOG("init: NM_UNINSTALL_CONFIGDIR: checking if config dir exists"); + if (access(NM_CONFIG_DIR, F_OK) && errno == ENOENT) { + NM_LOG("init: config dir does not exist, uninstalling"); + nm_failsafe_uninstall(fs); + goto stop; + } + #endif + NM_LOG("init: parsing config"); size_t items_n; nm_menu_item_t **items;