mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 23:42:58 +02:00
* Software Update with apply the settings (Part10)
- Blacklist added to exclude files - Files are marked by a prefixed '-' in the settingsupdate.conf
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
#:LogFile=/tmp/update.log
|
#:LogFile=/tmp/update.log
|
||||||
|
|
||||||
|
|
||||||
## M<>gliche Eintr<74>ge:
|
## M<>gliche Eintr<74>ge f<>r Sicherungen:
|
||||||
#====================
|
#====================================
|
||||||
# ganzes Verzeichnis
|
# ganzes Verzeichnis
|
||||||
#-------------------
|
#-------------------
|
||||||
# /var/etc
|
# /var/etc
|
||||||
@@ -26,3 +26,14 @@
|
|||||||
/etc/wpa_supplicant.conf
|
/etc/wpa_supplicant.conf
|
||||||
/var/etc
|
/var/etc
|
||||||
/var/tuxbox/config
|
/var/tuxbox/config
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------
|
||||||
|
## von der Sicherung auszuschlie<69>ende Dateien, gekennzeichnet durch ein vorangestelltes -
|
||||||
|
#----------------------------------------------------------------------------------------
|
||||||
|
-/var/tuxbox/config/cables.xml
|
||||||
|
-/var/tuxbox/config/encoding.conf
|
||||||
|
-/var/tuxbox/config/providermap.xml
|
||||||
|
-/var/tuxbox/config/radio-stations.xml
|
||||||
|
-/var/tuxbox/config/satellites.xml
|
||||||
|
-/var/tuxbox/config/settingsupdate.conf
|
||||||
|
-/var/tuxbox/config/tobackup.conf
|
||||||
|
@@ -25,8 +25,8 @@
|
|||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define UPDATE_DEBUG_TIMER
|
//#define UPDATE_DEBUG_TIMER
|
||||||
#define UPDATE_DEBUG
|
//#define UPDATE_DEBUG
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -73,6 +73,7 @@ CExtUpdate::CExtUpdate()
|
|||||||
fLogfile = "/tmp/update.log";
|
fLogfile = "/tmp/update.log";
|
||||||
mountPkt = "/tmp/image_mount";
|
mountPkt = "/tmp/image_mount";
|
||||||
FileHelpers = NULL;
|
FileHelpers = NULL;
|
||||||
|
BlackList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CExtUpdate::~CExtUpdate()
|
CExtUpdate::~CExtUpdate()
|
||||||
@@ -81,6 +82,7 @@ CExtUpdate::~CExtUpdate()
|
|||||||
delete[] MTDBuf;
|
delete[] MTDBuf;
|
||||||
if(FileHelpers)
|
if(FileHelpers)
|
||||||
delete[] FileHelpers;
|
delete[] FileHelpers;
|
||||||
|
BlackList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CExtUpdate* CExtUpdate::getInstance()
|
CExtUpdate* CExtUpdate::getInstance()
|
||||||
@@ -159,10 +161,10 @@ bool CExtUpdate::applySettings(const std::string & filename, int mode)
|
|||||||
|
|
||||||
bool CExtUpdate::isMtdramLoad()
|
bool CExtUpdate::isMtdramLoad()
|
||||||
{
|
{
|
||||||
char buf[256] = "";
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
FILE* f = fopen("/proc/modules", "r");
|
FILE* f = fopen("/proc/modules", "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
|
char buf[256] = "";
|
||||||
while(fgets(buf, sizeof(buf), f) != NULL) {
|
while(fgets(buf, sizeof(buf), f) != NULL) {
|
||||||
if (strstr(buf, "mtdram") != NULL) {
|
if (strstr(buf, "mtdram") != NULL) {
|
||||||
ret = true;
|
ret = true;
|
||||||
@@ -294,7 +296,8 @@ bool CExtUpdate::applySettings()
|
|||||||
if (res)
|
if (res)
|
||||||
return ErrorReset(RESET_UNLOAD, "mount error");
|
return ErrorReset(RESET_UNLOAD, "mount error");
|
||||||
|
|
||||||
readBackupList(mountPkt);
|
if (!readBackupList(mountPkt))
|
||||||
|
return ErrorReset(0, "error readBackupList");
|
||||||
|
|
||||||
res = umount(mountPkt.c_str());
|
res = umount(mountPkt.c_str());
|
||||||
if (res)
|
if (res)
|
||||||
@@ -359,7 +362,6 @@ bool CExtUpdate::copyFileList(const std::string & fileList, const std::string &
|
|||||||
struct dirent **namelist;
|
struct dirent **namelist;
|
||||||
std::string fList = fileList, dst;
|
std::string fList = fileList, dst;
|
||||||
static struct stat FileInfo;
|
static struct stat FileInfo;
|
||||||
char buf[PATH_MAX];
|
|
||||||
|
|
||||||
size_t pos = fileList.find_last_of("/");
|
size_t pos = fileList.find_last_of("/");
|
||||||
fList = fileList.substr(0, pos);
|
fList = fileList.substr(0, pos);
|
||||||
@@ -373,6 +375,7 @@ bool CExtUpdate::copyFileList(const std::string & fileList, const std::string &
|
|||||||
std::string dName = namelist[n]->d_name;
|
std::string dName = namelist[n]->d_name;
|
||||||
if (lstat((fList+"/"+dName).c_str(), &FileInfo) != -1) {
|
if (lstat((fList+"/"+dName).c_str(), &FileInfo) != -1) {
|
||||||
if (S_ISLNK(FileInfo.st_mode)) {
|
if (S_ISLNK(FileInfo.st_mode)) {
|
||||||
|
char buf[PATH_MAX];
|
||||||
int len = readlink((fList+"/"+dName).c_str(), buf, sizeof(buf)-1);
|
int len = readlink((fList+"/"+dName).c_str(), buf, sizeof(buf)-1);
|
||||||
if (len != -1) {
|
if (len != -1) {
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
@@ -383,7 +386,8 @@ bool CExtUpdate::copyFileList(const std::string & fileList, const std::string &
|
|||||||
else
|
else
|
||||||
if (S_ISREG(FileInfo.st_mode)) {
|
if (S_ISREG(FileInfo.st_mode)) {
|
||||||
WRITE_UPDATE_LOG("copy %s => %s\n", (fList+"/"+dName).c_str(), (dst+"/"+dName).c_str());
|
WRITE_UPDATE_LOG("copy %s => %s\n", (fList+"/"+dName).c_str(), (dst+"/"+dName).c_str());
|
||||||
if (!FileHelpers->copyFile((fList+"/"+dName).c_str(), (dst+"/"+dName).c_str(), FileInfo.st_mode & 0x0FFF))
|
std::string save = (isBlacklistEntry(fList+"/"+dName)) ? ".save" : "";
|
||||||
|
if (!FileHelpers->copyFile((fList+"/"+dName).c_str(), (dst + "/" + dName + save).c_str(), FileInfo.st_mode & 0x0FFF))
|
||||||
return ErrorReset(0, "copyFile error");
|
return ErrorReset(0, "copyFile error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,6 +428,18 @@ bool CExtUpdate::readConfig(const std::string & line)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CExtUpdate::isBlacklistEntry(const std::string & file)
|
||||||
|
{
|
||||||
|
for(vector<std::string>::iterator it = BlackList.begin(); it != BlackList.end(); ++it) {
|
||||||
|
if (*it == file) {
|
||||||
|
DBG_MSG("BlacklistEntry %s\n", (*it).c_str());
|
||||||
|
WRITE_UPDATE_LOG("BlacklistEntry: %s\n", (*it).c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CExtUpdate::readBackupList(const std::string & dstPath)
|
bool CExtUpdate::readBackupList(const std::string & dstPath)
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
@@ -452,10 +468,37 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
|
|||||||
if (fz.__pos == 0)
|
if (fz.__pos == 0)
|
||||||
return ErrorReset(RESET_F1, "backuplist filesize is 0");
|
return ErrorReset(RESET_F1, "backuplist filesize is 0");
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
// read blacklist
|
||||||
|
BlackList.clear();
|
||||||
while(fgets(buf, sizeof(buf), f1) != NULL) {
|
while(fgets(buf, sizeof(buf), f1) != NULL) {
|
||||||
std::string line = buf;
|
line = buf;
|
||||||
line = trim(line);
|
line = trim(line);
|
||||||
// remove comments
|
// ignore comments
|
||||||
|
if (line.find_first_of("#") == 0)
|
||||||
|
continue;
|
||||||
|
pos = line.find_first_of("#");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
line = line.substr(0, pos);
|
||||||
|
line = trim(line);
|
||||||
|
}
|
||||||
|
// find blacklist entry
|
||||||
|
if (line.find_first_of("-") == 0) {
|
||||||
|
line = line.substr(1);
|
||||||
|
if ((line.length() > 1) && (lstat(line.c_str(), &FileInfo) != -1)) {
|
||||||
|
if (S_ISREG(FileInfo.st_mode))
|
||||||
|
BlackList.push_back(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read backuplist
|
||||||
|
fseek(f1, 0, SEEK_SET);
|
||||||
|
while(fgets(buf, sizeof(buf), f1) != NULL) {
|
||||||
|
line = buf;
|
||||||
|
line = trim(line);
|
||||||
|
// ignore comments
|
||||||
if (line.find_first_of("#") == 0) {
|
if (line.find_first_of("#") == 0) {
|
||||||
if (line.find_first_of(":") == 1) { // config vars
|
if (line.find_first_of(":") == 1) { // config vars
|
||||||
if (line.length() > 1)
|
if (line.length() > 1)
|
||||||
@@ -468,6 +511,19 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
|
|||||||
line = line.substr(0, pos);
|
line = line.substr(0, pos);
|
||||||
line = trim(line);
|
line = trim(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// '+' add entry = default
|
||||||
|
if (line.find_first_of("+") == 0)
|
||||||
|
line = line.substr(1);
|
||||||
|
|
||||||
|
// '-' blacklist entry
|
||||||
|
if (line.find_first_of("-") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Entry '~' (delete) ignore currently still
|
||||||
|
if (line.find_first_of("~") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
// special folders
|
// special folders
|
||||||
else if ((line == "/") || (line == "/*") || (line == "/*.*") || (line.find("/dev") == 0) || (line.find("/proc") == 0) ||
|
else if ((line == "/") || (line == "/*") || (line == "/*.*") || (line.find("/dev") == 0) || (line.find("/proc") == 0) ||
|
||||||
(line.find("/sys") == 0) || (line.find("/mnt") == 0) || (line.find("/tmp") == 0)) {
|
(line.find("/sys") == 0) || (line.find("/mnt") == 0) || (line.find("/tmp") == 0)) {
|
||||||
@@ -501,7 +557,8 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
|
|||||||
WRITE_UPDATE_LOG("\n");
|
WRITE_UPDATE_LOG("\n");
|
||||||
WRITE_UPDATE_LOG("file: %s => %s\n", line.c_str(), dst.c_str());
|
WRITE_UPDATE_LOG("file: %s => %s\n", line.c_str(), dst.c_str());
|
||||||
WRITE_UPDATE_LOG("--------------------\n");
|
WRITE_UPDATE_LOG("--------------------\n");
|
||||||
if (!FileHelpers->copyFile(line.c_str(), dst.c_str(), FileInfo.st_mode & 0x0FFF))
|
std::string save = (isBlacklistEntry(line)) ? ".save" : "";
|
||||||
|
if (!FileHelpers->copyFile(line.c_str(), (dst + save).c_str(), FileInfo.st_mode & 0x0FFF))
|
||||||
return ErrorReset(0, "copyFile error");
|
return ErrorReset(0, "copyFile error");
|
||||||
}
|
}
|
||||||
else if (S_ISDIR(FileInfo.st_mode)) {
|
else if (S_ISDIR(FileInfo.st_mode)) {
|
||||||
@@ -510,7 +567,7 @@ bool CExtUpdate::readBackupList(const std::string & dstPath)
|
|||||||
WRITE_UPDATE_LOG("\n");
|
WRITE_UPDATE_LOG("\n");
|
||||||
WRITE_UPDATE_LOG("directory: %s => %s\n", line.c_str(), dst.c_str());
|
WRITE_UPDATE_LOG("directory: %s => %s\n", line.c_str(), dst.c_str());
|
||||||
WRITE_UPDATE_LOG("--------------------\n");
|
WRITE_UPDATE_LOG("--------------------\n");
|
||||||
FileHelpers->copyDir(line.c_str(), dst.c_str());
|
FileHelpers->copyDir(line.c_str(), dst.c_str(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ class CExtUpdate
|
|||||||
std::string backupList, defaultBackup;
|
std::string backupList, defaultBackup;
|
||||||
std::string mountPkt;
|
std::string mountPkt;
|
||||||
CFileHelpers* FileHelpers;
|
CFileHelpers* FileHelpers;
|
||||||
|
std::vector<std::string> BlackList;
|
||||||
|
|
||||||
bool applySettings(void);
|
bool applySettings(void);
|
||||||
bool readBackupList(const std::string & dstPath);
|
bool readBackupList(const std::string & dstPath);
|
||||||
@@ -80,6 +81,7 @@ class CExtUpdate
|
|||||||
|
|
||||||
bool applySettings(const std::string & filename, int mode);
|
bool applySettings(const std::string & filename, int mode);
|
||||||
bool ErrorReset(bool modus, const std::string & msg1="", const std::string & msg2="");
|
bool ErrorReset(bool modus, const std::string & msg1="", const std::string & msg2="");
|
||||||
|
bool isBlacklistEntry(const std::string & file);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include <zapit/debug.h>
|
#include <zapit/debug.h>
|
||||||
|
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
|
#include <gui/ext_update.h>
|
||||||
|
|
||||||
bool file_exists(const char *filename)
|
bool file_exists(const char *filename)
|
||||||
{
|
{
|
||||||
@@ -339,7 +340,7 @@ bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t mode)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileHelpers::copyDir(const char *Src, const char *Dst)
|
bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode)
|
||||||
{
|
{
|
||||||
DIR *Directory;
|
DIR *Directory;
|
||||||
struct dirent *CurrentFile;
|
struct dirent *CurrentFile;
|
||||||
@@ -402,7 +403,10 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst)
|
|||||||
}
|
}
|
||||||
// is file
|
// is file
|
||||||
else if (S_ISREG(FileInfo.st_mode)) {
|
else if (S_ISREG(FileInfo.st_mode)) {
|
||||||
copyFile(srcPath, dstPath, FileInfo.st_mode & 0x0FFF);
|
std::string save = "";
|
||||||
|
if (backupMode && (CExtUpdate::getInstance()->isBlacklistEntry(srcPath)))
|
||||||
|
save = ".save";
|
||||||
|
copyFile(srcPath, (dstPath + save).c_str(), FileInfo.st_mode & 0x0FFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@ class CFileHelpers
|
|||||||
bool doCopyFlag;
|
bool doCopyFlag;
|
||||||
|
|
||||||
bool copyFile(const char *Src, const char *Dst, mode_t mode);
|
bool copyFile(const char *Src, const char *Dst, mode_t mode);
|
||||||
bool copyDir(const char *Src, const char *Dst);
|
bool copyDir(const char *Src, const char *Dst, bool backupMode=false);
|
||||||
bool createDir(const char *Dir, mode_t mode);
|
bool createDir(const char *Dir, mode_t mode);
|
||||||
bool removeDir(const char *Dir);
|
bool removeDir(const char *Dir);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user