Exemplo n.º 1
0
int LocalPackage::fill_filelist(PACKAGE *package, bool)
{
	if (!package) package=&data;
	//mDebug("fill_filelist start");
	// Retrieving regular files
	// For setup mode, we can try to enable cached filelists
	vector<string> file_names;
	string fname;
	bool fname_temp = false;
	if (setupMode && FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist")) {
		fname = getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist";
	}
	else {
		fname = get_tmp_file();
		fname_temp = true;
		system("tar tf "+filename+" --exclude install " +" > "+fname + " 2>/dev/null");
	}
	// Parsing file list
	file_names=ReadFileStrings(fname);
	if (fname_temp) unlink(fname.c_str());
	if (file_names.size()>2) file_names.erase(file_names.begin(), file_names.begin()+2);
	else {
		mWarning("Empty file list in package " + package->get_name());
		file_names.clear();
	}
	package->set_files(file_names);
	// Retrieving symlinks (from doinst.sh).
	string dt;
	bool dt_temp=false;
	// Extracting file to the temp dir
	if (setupMode && FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/doinst.sh")) {
		dt = getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/doinst.sh";
	}
	else if (!setupMode || !FileExists(getAbsolutePath(getDirectory(filename))+"/.fcache/" + getFilename(filename) + "/flist")) { // Assuming that doinst.sh isn't present if flist is cached
		dt = get_tmp_file();
		extractFromTgz(filename, "install/doinst.sh", dt);
		dt_temp = true;
	}

	
	if (!dt.empty() && FileExists(dt)) {
		string lnfname=get_tmp_file();
		string sed_cmd = "sed -n 's,^( *cd \\([^ ;][^ ;]*\\) *; *rm -rf \\([^ )][^ )]*\\) *) *$,\\1/\\2,p' < ";
		sed_cmd += dt + " > " + lnfname;
		system(sed_cmd);
		vector<string>link_names=ReadFileStrings(lnfname);
		for (size_t i=0; i<link_names.size(); ++i) {
			if (!link_names[i].empty()) package->get_files_ptr()->push_back(link_names[i]);
		}
		if (dt_temp) unlink(dt.c_str());
		unlink(lnfname.c_str());
	}

	delete_tmp_files();
	return 0;
}
Exemplo n.º 2
0
int driverSelectionMenu(CursesInterface &ncInterface) {
	// First, detect hardware for which we have to install drivers.
	string tmp_hw = get_tmp_file();
	system("lspci > " + tmp_hw);
	vector<string> hw = ReadFileStrings(tmp_hw);
	// Check for VirtualBox
	bool hasVirtualBox=false;
	int hasNvidia=-1;
	int hasRadeon=-1;
	for(size_t i=0; i<hw.size(); ++i) {
		if (hw[i].find("VirtualBox")!=std::string::npos) hasVirtualBox = true;
		if (hw[i].find("VGA compatible controller")!=std::string::npos && hw[i].find("nVidia")!=std::string::npos) hasNvidia = i;
		if (hw[i].find("VGA compatible controller")!=std::string::npos && hw[i].find("Radeon")!=std::string::npos) hasRadeon = i;
	}
	if (hasNvidia==-1) return 1;
	vector<MenuItem> menuItems;
	menuItems.push_back(MenuItem(_("Latest"), _("Latest GeForce (series 6xxx and later)")));
	menuItems.push_back(MenuItem("173", _("GeForce FX series")));
	menuItems.push_back(MenuItem("96", _("GeForce 4 series")));
	menuItems.push_back(MenuItem(_("Skip"), _("Do not install driver")));

	string ret = ncInterface.showMenu2(_("Videocard detected: ") + hw[hasNvidia] + _("\nChoose driver for it:"), menuItems);
	if (!ret.empty() && ret != _("Skip")) {
		if (ret!=_("Latest")) {
			WriteFile(SETUPCONFIG_NVIDIA, string("legacy" + ret));
		}
		else {
			WriteFile(SETUPCONFIG_NVIDIA, "generic");
			
		}
	}
	return 0;
}
Exemplo n.º 3
0
string getCdromVolname(string *rep_location)
{
	bool hasMountedHere=false;
	if (!isMounted(CDROM_MOUNTPOINT))
	{
		system("mount " + CDROM_DEVICE + " " + CDROM_MOUNTPOINT + " 2>/dev/null >/dev/null");
		hasMountedHere=true;
	}
	string Svolname, repLoc;
	// check_volname:
	if (FileExists(CDROM_MOUNTPOINT + "/.volume_id")) {
		vector<string> tmp = ReadFileStrings(CDROM_MOUNTPOINT + "/.volume_id");
		if (!tmp.empty()) {
			Svolname = cutSpaces(tmp[0]);
		}
	}
	if (rep_location!=NULL)
	{
		if (FileExists(CDROM_MOUNTPOINT + "/.repository")) {
			vector<string> tmp = ReadFileStrings(CDROM_MOUNTPOINT + "/.repository");
			if (!tmp.empty()) {
				repLoc = cutSpaces(tmp[0]);
			}
		}
	}
	if (hasMountedHere) system("umount " + CDROM_MOUNTPOINT + " 2>/dev/null >/dev/null");
	// Validating
	if (Svolname.find_first_of("\n\t/><| !@#$%%^&*()`\"\'")!=std::string::npos)
	{
		return "";
	}
	if (rep_location!=NULL)
	{
		*rep_location = repLoc;
	}
	
	return Svolname;

}
Exemplo n.º 4
0
int TextSetup::setAdditionalRepositories() {
	if (repositories.empty() && !ncInterface.showYesNo(_("Do you want to specify additional repositories?"))) return 0;
	ncInterface.showMsgBox(_("Edit file and place each repository on separate line"));
	string tmp_file = get_tmp_file();
	WriteFileStrings(tmp_file, repositories);
	ncInterface.uninit();
	system("mcedit " + tmp_file);
	vector<string> reps = ReadFileStrings(tmp_file);
	for (size_t i=0; i<reps.size(); ++i) {
		if (cutSpaces(reps[i]).empty()) continue;
		if (cutSpaces(reps[i])[0]=='#') continue;
		repositories.push_back(reps[i]);
	}
	unlink(tmp_file.c_str());
	return 0;
}
Exemplo n.º 5
0
bool TextSetupMechanics::checkNvidiaLoad() {
	int hasNvidia = -1;

	if (hasNvidia==-1) {
		string tmp_hw = get_tmp_file();
		system("lspci > " + tmp_hw);
		vector<string> hw = ReadFileStrings(tmp_hw);
		for(size_t i=0; i<hw.size(); ++i) {
			if (hw[i].find("VGA compatible controller")!=std::string::npos && hw[i].find("nVidia")!=std::string::npos) hasNvidia = i;
		}
		if (hasNvidia == -1) hasNvidia = 0;
	}
	// For debugging reasons, check for /tmp/nvidia_force file
	if (FileExists("/tmp/nvidia_force")) hasNvidia = 1;

	return hasNvidia > 0;
}
Exemplo n.º 6
0
int TextSetup::setTimezone() {
	// TODO: implement some easy way to find your timezone from this f****n' large list
	string tmpfile = get_tmp_file();
	system("( cd /usr/share/zoneinfo && find . -type f | sed -e 's/\\.\\///g') > " + tmpfile);
	vector<string> tz = ReadFileStrings(tmpfile);
	unlink(tmpfile.c_str());
	vector<MenuItem> m;
	for (size_t i=0; i<tz.size(); ++i) {
		m.push_back(MenuItem(tz[i], ""));
	}
	settings["timezone"] = ncInterface.showMenu2(_("Select your timezone:"), m, "Europe/Moscow");

	if (ncInterface.showYesNo(_("Does your hardware clock stores time in UTC instead of localtime?"))) settings["time_utc"]="1";
	else settings["time_utc"]="0";

	return 0;
}
Exemplo n.º 7
0
int main(int argc, char **argv) {
	int mode = MODE_HELP;
	if (argc==2 && string(argv[1])=="--show") mode = MODE_SHOW;
	if (argc>3 && string(argv[1])=="--set") mode = MODE_SET;

	string mName = mConfig.getValue("maintainer_name");
	string mEmail = mConfig.getValue("maintainer_email");

	if (getuid() && FileExists(getenv("HOME") + string("/.mpkg-maintainer"))) {
		vector<string> mdata = ReadFileStrings(getenv("HOME") + string("/.mpkg-maintainer"));
		if (mdata.size()>0) mName=cutSpaces(mdata[0]);
		if (mdata.size()>1) mEmail=cutSpaces(mdata[1]);
	}

	switch (mode) {
		case MODE_HELP:
			fprintf(stderr, _("%s: shows or sets maintainer name and email\nSyntax:\n"), argv[0]);
			fprintf(stderr, _("%s --help              show this help\n"), argv[0]);
			fprintf(stderr, _("%s --show              show maintainer name and email\n"), argv[0]);
			fprintf(stderr, _("%s --set NAME EMAIL    set name and email appropriately\n"), argv[0]);
			return 1;
		case MODE_SET:
			mName = argv[2];
			mEmail = argv[3];
			if (getuid()) {
				printf("Writing user maintainer\n");
				system("echo " + mName + " > ~/.mpkg-maintainer");
				system("echo " + mEmail + " >> ~/.mpkg-maintainer");
			}
			else {
				mConfig.setValue("maintainer_name", mName);
				mConfig.setValue("maintainer_email", mEmail);
			}
			// Doesn't break here, let's show data

		case MODE_SHOW:
			printf("MaintainerName: %s\nMaintainerEmail: %s\n", mName.c_str(), mEmail.c_str());
			return 0;

	}
	return 0;

}
Exemplo n.º 8
0
vector<RaidArray> getActiveRaidArrays() {
    vector<RaidArray> ret;
    string raw = get_tmp_file();
    system("cat /proc/mdstat | grep md | grep active > " + raw);
    vector<string> mdstat = ReadFileStrings(raw);
    vector<string> extra;
    RaidArray *array;
    string tmp;
    for (unsigned int i=0; i<mdstat.size(); ++i) {
        if (mdstat[i].find("md")==0) {
            ret.push_back(RaidArray());
            array = &ret[ret.size()-1];
            array->md_dev = "/dev/" + mdstat[i].substr(0, mdstat[i].find(" : "));
            tmp = mdstat[i].substr(mdstat[i].find(" active ") + strlen(" active "));
            array->level = tmp.substr(0, tmp.find(" "));
            array->extra_description = tmp.substr(tmp.find(" "));
            if (array->extra_description.empty()) continue;
            tmp = array->extra_description.substr(1);
            tmp = cutSpaces(tmp);
            while(!tmp.empty() && tmp.find_first_not_of("][ ")!=std::string::npos) {
                tmp = tmp.substr(tmp.find_first_not_of("][ "));
                if (tmp.find("[")==std::string::npos) break;
                array->devices.push_back("/dev/" + tmp.substr(0, tmp.find("[")));
                if (tmp.find(" ")==std::string::npos) break;
                else {
                    tmp = tmp.substr(tmp.find(" "));
                }
            }

        }
    }
    for (unsigned int i=0; i<ret.size(); ++i) {
        ret[i].extra_description = "RAID-массив " + ret[i].level + " [";
        for (unsigned int d=0; d<ret[i].devices.size(); ++d) {
            if (ret[i].devices[d].length()>strlen("/dev/")) ret[i].extra_description += ret[i].devices[d].substr(strlen("/dev/"));
            else ret[i].extra_description += ret[i].devices[d];
            if (d != ret[i].devices.size()-1) ret[i].extra_description += "|";
        }
        ret[i].extra_description += "]";
    }
    return ret;
}
Exemplo n.º 9
0
int loadSettings(const string& filename, map<string, string> &settings, vector<string> &repositories, map<string, map<string, string> > &partitions) {
	// Load settings until we found brackets
	vector<string> conf = ReadFileStrings(filename);
	string name, value;
	for (size_t i=0; i<conf.size(); ++i) {
		if (conf[i].empty()) continue;
		if (cutSpaces(conf[i])[0]=='#') continue;
		if (cutSpaces(conf[i])[0]=='[') break;
		if (parseConfString(conf[i], name, value)) settings[name]=value;
	}

	// Now, find repos
	bool found = false;
	for (size_t i=0; i<conf.size(); ++i) {
		if (conf[i].empty()) continue;
		if (cutSpaces(conf[i])[0]=='#') continue;
		if (!found) {
			if (cutSpaces(conf[i])=="[repositories]") found = true;
			continue;
		}
		if (cutSpaces(conf[i])[0]=='[') break;
		repositories.push_back(cutSpaces(conf[i]));
	}

	// Partitions
	found = false;
	name.clear();
	value.clear();
	string part;
	for (size_t i=0; i<conf.size(); ++i) {
		if (conf[i].empty()) continue;
		if (cutSpaces(conf[i])[0]=='#') continue;
		if (cutSpaces(conf[i]).find("[/")==0 && cutSpaces(conf[i]).size()>2) {
			found = true;	
			part = cutSpaces(conf[i]).substr(1, cutSpaces(conf[i]).size()-2);
			continue;
		}
		if (found && parseConfString(conf[i], name, value)) partitions[part][name]=value;
	}
	return 0;
}
Exemplo n.º 10
0
vector<RaidArray> detectRaidArrays() {
    vector<string> gp;
    vector<pEntry> pList;
    vector<string> raw;
    vector<RaidArray> ret;
    RaidArray *array = NULL;
    string tmp;
    pList= getGoodPartitions(gp);
    string mdout = get_tmp_file();
    for (unsigned int i=0; i<pList.size(); ++i) {
        if (!pList[i].raid) continue;
        system("mdadm -Q " + pList[i].devname + " | grep undetected | grep /dev/md > " + mdout + " 2>/dev/tty4");
        raw = ReadFileStrings(mdout);
        if (raw.empty()) continue;
        if (raw[0].find("/dev/md")==std::string::npos) continue;
        tmp = raw[0].substr(raw[0].find("/dev/md"));
        if (tmp.find(".")==std::string::npos) continue;
        tmp = tmp.substr(0, tmp.find_first_of("."));
        //ncInterface.showMsgBox("FOUND: " + tmp);
        array = NULL;
        for (unsigned int r=0; r<ret.size(); ++r) {
            if (ret[r].md_dev == tmp) {
                array = &ret[r];
                break;
            }
        }

        //ncInterface.showMsgBox("Total ret: " + IntToStr(ret.size()) + " but can't find " + tmp);
        if (!array) {
            ret.push_back(RaidArray());
            array = &ret[ret.size()-1];
            array->md_dev = tmp;
        }
        array->devices.push_back(pList[i].devname);
        //ncInterface.showMsgBox("Total ret: " + IntToStr(ret.size()) + " found li " + tmp);
    }
    return ret;
}
Exemplo n.º 11
0
int main(int, char **) {
	dialogMode = true;
	CursesInterface ncInterface;
	ncInterface.setTitle(_("AgiliaLinux setup"));
	ncInterface.setSubtitle(_("Language selection"));
	vector<string> availableLanguages = ReadFileStrings(SETUP_LANGUAGES);
	vector<MenuItem> menuItems;
	string arg, value;
	for (size_t i=1; i<availableLanguages.size(); i=i+2) {
		arg=availableLanguages[i-1];
		value=availableLanguages[i];
		menuItems.push_back(MenuItem(arg, value));
	}
	if (menuItems.empty()) {
		ncInterface.showMsgBox(_("No languages available to select. Choosing english (en_US) as default option"));
		WriteFile(SETUP_LANGUAGES, "en_US");
		return 0;
	}
	string language = ncInterface.showMenu2(_("Select language:"), menuItems);
	if (language.empty()) return 1;
	WriteFile(SETUPCONFIG_LANGUAGE, language);
	return 0;
}
Exemplo n.º 12
0
int loadGlobalConfig(string config_file)
{
#ifdef HTTP_LIB
    mError("error: core running non-core code\n");
#endif

    currentStatus = "Loading configuration...";
    removeBlacklist = ReadFileStrings("/etc/mpkg-remove-blacklist");
    string run_scripts="yes";
    string cdrom_device="/dev/cdrom";
    string cdrom_mountpoint="/mnt/cdrom";
    string check_files = "preinstall";
    string sys_root="/";
    string sys_cache="/var/mpkg/cache/";
    string db_url="sqlite:///var/log/mpkg/packages.db";
    string scripts_dir="/var/log/mpkg/scripts/";
    string sql_type;
    vector<string> repository_list;
    vector<string> disabled_repository_list;
    bool conf_init=false;
    XMLResults xmlErrCode;
    if (access(config_file.c_str(), R_OK)==0)
    {
        XMLNode config=XMLNode::parseFile(config_file.c_str(), "mpkgconfig", &xmlErrCode);

        if (xmlErrCode.error != eXMLErrorNone)
        {
            mError("config parse error!\n");
            mpkgErrorReturn errRet = waitResponce(MPKG_SUBSYS_XMLCONFIG_READ_ERROR);
            if (errRet == MPKG_RETURN_REINIT)
            {
                conf_init = true;
            }
        }

        if (!conf_init)
        {
            if (config.nChildNode("run_scripts")!=0)
                run_scripts=(string) config.getChildNode("run_scripts").getText();
            if (config.nChildNode("checkFileConflicts")!=0)
                check_files = (string) config.getChildNode("checkFileConflicts").getText();
            if (config.nChildNode("sys_root")!=0)
                sys_root=(string) config.getChildNode("sys_root").getText();
            if (config.nChildNode("sys_cache")!=0)
                sys_cache=(string) config.getChildNode("sys_cache").getText();
            if (config.nChildNode("cdrom_device")!=0)
                cdrom_device=(string) config.getChildNode("cdrom_device").getText();
            if (config.nChildNode("cdrom_mountpoint")!=0)
                cdrom_mountpoint = (string) config.getChildNode("cdrom_mountpoint").getText();
            if (config.nChildNode("database_url")!=0)
                db_url=(string) config.getChildNode("database_url").getText();
            if (config.nChildNode("repository_list")!=0)
            {
                string tmp_r;
                for (int i=0; i<config.getChildNode("repository_list").nChildNode("repository"); i++)
                {
                    tmp_r = (string) config.getChildNode("repository_list").getChildNode("repository",i).getText();
                    if (tmp_r[tmp_r.length()-1]!='/') tmp_r += "/";
                    repository_list.push_back(tmp_r);
                }
                for (int i=0; i<config.getChildNode("repository_list").nChildNode("disabled_repository"); i++)
                {
                    disabled_repository_list.push_back((string) config.getChildNode("repository_list").getChildNode("disabled_repository",i).getText());
                }
            }
            if (config.nChildNode("scripts_dir")!=0)
            {
                scripts_dir = (string) config.getChildNode("scripts_dir").getText();
            }
        }

    }
    else
    {
        conf_init=true;
        mError("Configuration file /etc/mpkg.xml not found, using defaults and creating config\n");
    }
    // parsing results

    // run_scripts
    if (run_scripts=="yes")
        DO_NOT_RUN_SCRIPTS=false;
    if (run_scripts=="no")
        DO_NOT_RUN_SCRIPTS=true;
    if (run_scripts!="yes" && run_scripts!="no")
    {
        mError("Error in config file, option <run_scripts> should be \"yes\" or \"no\", without quotes");
        return -1; // CONFIG ERROR in scripts
    }
    if (check_files == "preinstall")
        fileConflictChecking = CHECKFILES_PREINSTALL;
    if (check_files == "postinstall")
        fileConflictChecking = CHECKFILES_POSTINSTALL;
    if (check_files == "disable")
        fileConflictChecking = CHECKFILES_DISABLE;
    if (cdrom_device.empty())
    {
        mError("empty cd-rom, using default\n");
#ifndef HTTP_LIB
        CDROM_DEVICE="/dev/cdrom";
#else
        DL_CDROM_DEVICE="/dev/cdrom";
#endif
    }
    else
    {
#ifndef HTTP_LIB
        CDROM_DEVICE=cdrom_device;
#else
        DL_CDROM_DEVICE=cdrom_device;
#endif
    }

    if (cdrom_mountpoint.empty())
    {
#ifndef HTTP_LIB
        CDROM_MOUNTPOINT="/mnt/cdrom";
#else
        DL_CDROM_MOUNTPOINT="/mnt/cdrom";
#endif
    }

    else
    {
#ifndef HTTP_LIB
        CDROM_MOUNTPOINT=cdrom_mountpoint;
#else
        DL_CDROM_MOUNTPOINT=cdrom_mountpoint;
#endif
    }

    // sys_root
    SYS_ROOT=sys_root;
    //sys_cache
    SYS_CACHE=sys_cache;
    SCRIPTS_DIR=scripts_dir;
    SYS_BACKUP = mConfig.getValue("sys_backup");
    if (SYS_BACKUP.empty()) {
        SYS_BACKUP = "/var/mpkg/backup/";
        mConfig.setValue("sys_backup", SYS_BACKUP);
    }
    if (db_url.find("sqlite://")==0)
    {
        sql_type="sqlite://";

        DATABASE=DB_SQLITE_LOCAL;
        DB_FILENAME=db_url.substr(strlen("sqlite:/"));
    }
    else {
        mError("CRITICAL: cannot find database, check config!");
        abort();
    }
    REPOSITORY_LIST=repository_list;
    DISABLED_REPOSITORY_LIST = disabled_repository_list;
#ifdef DEBUG
    say("System configuration:\n\trun_scripts: %s\n\tsys_root: %s\n\tsys_cache: %s\n\tSQL type: %s\n\tSQL filename: %s\n", \
        run_scripts.c_str(), sys_root.c_str(), sys_cache.c_str(), sql_type.c_str(), db_url.c_str());
#endif
    if (conf_init) mpkgconfig::initConfig();

    currentStatus = "Settings loaded";
    initDirectoryStructure();
    return 0;
}
Exemplo n.º 13
0
XMLNode mpkgconfig::getXMLConfig(string conf_file)
{
    mDebug("getXMLConfig");
    XMLNode config;
    XMLResults xmlErrCode;
    bool conf_init = false;
    removeBlacklist = ReadFileStrings("/etc/mpkg-remove-blacklist");
    if (access(conf_file.c_str(), R_OK)==0)
    {
        config=XMLNode::parseFile(conf_file.c_str(), "mpkgconfig", &xmlErrCode);
        if (xmlErrCode.error != eXMLErrorNone)
        {
            mError("config parse error!\n");
            mpkgErrorReturn errRet = waitResponce(MPKG_SUBSYS_XMLCONFIG_READ_ERROR);
            if (errRet == MPKG_RETURN_REINIT)
            {
                conf_init = true;
            }
        }

    }
    else conf_init = true;
    if (conf_init) config=XMLNode::createXMLTopNode("mpkgconfig");

    if (config.nChildNode("run_scripts")==0)
    {
        config.addChild("run_scripts");
        if (get_runscripts()) config.getChildNode("run_scripts").addText("yes");
        else config.getChildNode("run_scripts").addText("no");
    }
    if (config.nChildNode("checkFileConflicts")==0)
    {
        config.addChild("checkFileConflicts");
        if (get_checkFiles()==CHECKFILES_PREINSTALL) config.getChildNode("checkFileConflicts").addText("preinstall");
        if (get_checkFiles()==CHECKFILES_POSTINSTALL) config.getChildNode("checkFileConflicts").addText("postinstall");
        if (get_checkFiles()==CHECKFILES_DISABLE) config.getChildNode("checkFileConflicts").addText("disable");

    }

    if (config.nChildNode("sys_root")==0)
    {
        config.addChild("sys_root");
        config.getChildNode("sys_root").addText(get_sysroot().c_str());
    }

    if (config.nChildNode("sys_cache")==0)
    {
        config.addChild("sys_cache");
        config.getChildNode("sys_cache").addText(get_syscache().c_str());
    }

    if (config.nChildNode("database_url")==0)
    {
        config.addChild("database_url");
        config.getChildNode("database_url").addText(get_dburl().c_str());
    }

    if (config.nChildNode("repository_list")==0)
    {
        config.addChild("repository_list");
    }

    if (config.nChildNode("cdrom_device")==0)
    {
        mError("CD not detected\n");
        config.addChild("cdrom_device");
        config.getChildNode("cdrom_device").addText(get_cdromdevice().c_str());
    }


    if (config.nChildNode("cdrom_mountpoint")==0)
    {
        config.addChild("cdrom_mountpoint");
        config.getChildNode("cdrom_mountpoint").addText(get_cdrommountpoint().c_str());
    }

    if (config.nChildNode("scripts_dir")==0)
    {
        config.addChild("scripts_dir");
        config.getChildNode("scripts_dir").addText(get_scriptsdir().c_str());
    }
    mDebug("getXMLConfig end");
    return config;
}
Exemplo n.º 14
0
void generateDeps(string tgz_filename, bool updateOnly)
{
	if (mConfig.getValue("add_deps_in_build")=="yes") updateOnly=false;
	if (tgz_filename.empty()) {
		mError("No filename specified");
		return;
	}
	say("Generating dependencies for %s\n",tgz_filename.c_str());
	string current_dir = (string) get_current_dir_name();
	// Create a temporary directory
	string tmpdir = get_tmp_file();
	string dep_out = get_tmp_file();
	unlink(tmpdir.c_str());
	system("mkdir -p " + tmpdir);
	say("Extracting\n");
	system("tar zxf " + tgz_filename + " -C " + tmpdir);
	PackageConfig *p = new PackageConfig(tmpdir+"/install/data.xml");
	PACKAGE pkg;
	if (p->parseOk) xml2package(p->getXMLNode(), &pkg);
	delete p;
	say("Building dependencies\n");
	
	system("env LC_ALL=C requiredbuilder -n -v " + tgz_filename + " > "+ dep_out);
	vector<string> data = ReadFileStrings(dep_out);
	
	string tmp;
	string tail;
	DEPENDENCY d;
	//pkg.get_dependencies()->clear();
	string condptr;
	for (unsigned int i=0; i<data.size(); i++)
	{
		tmp = data[i].substr(0,data[i].find_first_of(" "));
		tail = data[i].substr(tmp.length()+1);
		d.set_package_name(&tmp);

		tmp = tail.substr(0, tail.find_first_of(" "));
		tail = tail.substr(tmp.length()+1);
		condptr=IntToStr(condition2int(hcondition2xml(tmp)));
		d.set_condition(&condptr);

		tmp = tail.substr(0,tail.find_first_of("-"));
		d.set_package_version(&tmp);
		if (*d.get_package_name()!=*pkg.get_name()) {
			// Checking existing dependencies
			bool added=false;
			for (unsigned int t=0; t<pkg.get_dependencies()->size(); t++) {
				if (*d.get_package_name()==*pkg.get_dependencies()->at(t).get_package_name()) {
					pkg.get_dependencies()->at(t) = d;
					added=true;
				}
			}
			if (!added) {
				if (updateOnly) mWarning("Found (possible) missing dependencies: " + d.getDepInfo());
				else pkg.get_dependencies()->push_back(d);
			}
		}
	}
	say(_("Got %d dependencies\n"), pkg.get_dependencies()->size());
	p = new PackageConfig(tmpdir+"/install/data.xml");
	dumpPackage(&pkg, p, tmpdir+"/install/data.xml");
	delete p;
	if (tgz_filename[0]!='/') tgz_filename = current_dir + "/"+getDirectory(tgz_filename);
	system ("cd " + tmpdir + "; buildpkg " + tgz_filename );
	system("rm -rf " + tmpdir);
	delete_tmp_files();
}