diff --git a/data/Makefile.am b/data/Makefile.am index 5f4751b23..ef9881b5e 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -5,7 +5,7 @@ SUBDIRS += lcd endif configdir = $(CONFIGDIR) -config_DATA = cables.xml satellites.xml encoding.conf tobackup.conf providermap.xml settingsupdate.conf terrestrial.xml +config_DATA = cables.xml satellites.xml encoding.conf tobackup.conf providermap.xml settingsupdate.conf terrestrial.xml bad_package_pattern.list.sample install-data-hook: $(INSTALL) -d $(DESTDIR)/$(CONFIGDIR)/zapit diff --git a/data/bad_package_pattern.list.sample b/data/bad_package_pattern.list.sample new file mode 100644 index 000000000..221ffa8f7 --- /dev/null +++ b/data/bad_package_pattern.list.sample @@ -0,0 +1,11 @@ +-dev$ +-doc$ +-dbg$ +-ptest$ +-staticdev$ +-locale- +-charmap- +-gconv- +-localedata- +^locale-base- +^perl-module- diff --git a/src/gui/opkg_manager.cpp b/src/gui/opkg_manager.cpp index ea6e917e9..2c1542481 100644 --- a/src/gui/opkg_manager.cpp +++ b/src/gui/opkg_manager.cpp @@ -55,13 +55,14 @@ #include #include #include +#include #define OPKG_CL "opkg" #define OPKG_TMP_DIR "/tmp/.opkg" #define OPKG_TEST_DIR OPKG_TMP_DIR "/test" #define OPKG_CL_CONFIG_OPTIONS " -V2 --tmp-dir=/tmp --cache=" OPKG_TMP_DIR - +#define OPKG_BAD_PATTERN_LIST_FILE "/var/tuxbox/config/bad_package_pattern.list" #define OPKG_CONFIG_FILE "/etc/opkg/opkg.conf" using namespace std; @@ -113,8 +114,8 @@ COPKGManager::COPKGManager(): opkg_conf('\t') list_upgradeable_done = false; expert_mode = false; local_dir = &g_settings.update_dir_opkg; + v_bad_pattern = getBadPackagePatternList(); CFileHelpers::createDir(OPKG_TMP_DIR); - } COPKGManager::~COPKGManager() @@ -305,29 +306,38 @@ static const struct button_label COPKGManagerFooterButtonsExpert[COPKGManagerFoo { NEUTRINO_ICON_BUTTON_BLUE, LOCALE_OPKG_BUTTON_UNINSTALL } }; -/* TODO: this should go into a config file... */ -static std::string bad_pattern[] = { - "-dev$", - "-doc$", - "-dbg$", - "-ptest$", - "-staticdev$", - "-locale-", - "-charmap-", - "-gconv-", - "-localedata-", - "^locale-base-", - "^perl-module-", - "" -}; +vector COPKGManager::getBadPackagePatternList() +{ + vector v_ret; + + ifstream in (OPKG_BAD_PATTERN_LIST_FILE, ios::in); + if (!in){ + dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] can't open %s, %s\n", __func__, __LINE__, OPKG_BAD_PATTERN_LIST_FILE, strerror(errno)); + return v_ret; + } + string line; + + while(getline(in, line)){ + v_ret.push_back(line); + } + in.close(); + + return v_ret; +} bool COPKGManager::badpackage(std::string &s) { - int i; + if(v_bad_pattern.empty()) + return false; + + size_t i; string st = ""; - for (i = 0; !bad_pattern[i].empty(); i++) + for (i = 0; i < v_bad_pattern.size(); i++) { - string p = bad_pattern[i]; + string p = v_bad_pattern[i]; + if (p.empty()) + continue; + size_t patlen = p.length() - 1; bool res = false; /* poor man's regex :-) only supported are "^" and "$" */ diff --git a/src/gui/opkg_manager.h b/src/gui/opkg_manager.h index 6d81e3428..4979c9c9b 100644 --- a/src/gui/opkg_manager.h +++ b/src/gui/opkg_manager.h @@ -56,6 +56,9 @@ class COPKGManager : public CMenuTarget std::string config_src[OPKG_MAX_FEEDS]; std::vector config_dest; + //filter + std::vector v_bad_pattern; + std::map pkg_map; std::vector pkg_vec; @@ -107,7 +110,7 @@ class COPKGManager : public CMenuTarget bool isInstalled(const std::string& pkg_name); bool isUpgradable(const std::string& pkg_name); - /* + /*! * Gets an info from opkg command info or status from a package via keywords as std::string * 1st parameter is name of package as string eg. "gdb", without file extension or version data * 2nd parameter needs a keyword like: @@ -125,7 +128,25 @@ class COPKGManager : public CMenuTarget void showMenuConfigFeed(CMenuWidget *feed_menu); void updateMenu(); void refreshMenu(); + + //!Returns a vector with possible filter entries from OPKG_BAD_PATTERN_LIST_FILE + static std::vector getBadPackagePatternList(); + /*! + * Returns true if found a ''bad'' package, Parameter: package name as std::string by rev + * To detect bad packages, it must be exist a matching pattern list file. + * Path is defined in OPKG_BAD_PATTERN_LIST_FILE. + * This provides the option to filter some unwanted entries in the package list menue. + * This makes sense eg. to hinder that the user could change important system packages. + * NOTE: a sample file you should find here as : "/var/tuxbox/config/bad_package_pattern.list.sample" + * If required, remove the ".sample" extension and change the entries for your requirements + * howto: a simple way to filter a package is to add the pure name, if you want + * to hide a package (even which name) then add this name to a line. Eg. if you want to hide + * package wget then add this and this package is not displayed at the gui. + * Also a few place holders should work, see the badpackage() function, but this + * can be inaccurately because it could filter innocent packages. + */ bool badpackage(std::string &s); + void showError(const char* local_msg, char* err_msg = NULL, const std::string& additional_text = std::string()); int doUpdate(); void handleShellOutput(std::string* cur_line, int* res, bool* ok);