bool parseConfString(const string& conf, string &name, string &value) { size_t pos; pos = conf.find_first_of("="); if (pos==std::string::npos) return false; name = cutSpaces(conf.substr(0, pos)); if (pos>=conf.size()-1) value.clear(); else value = cutSpaces(conf.substr(pos+1)); return true; }
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; }
int mpkgSys::updatePackageDescriptions(const vector< pair<string, string> > &descriptions) { if (mConfig.getValue("disable_description_sync")=="yes") return 0; // Allow user to disable this functionality // First of all: create directory. The path is: SYS_MPKG_VAR_DIRECTORY + "/descriptions"; const string base_path = SYS_MPKG_VAR_DIRECTORY + "/descriptions"; system("mkdir -p \"" + base_path + "\" 2>/dev/null >/dev/null"); // Now download indexes. There are two methods: rsync and not rsync :) All these are configured via system config, and default is "rsync" // Also, user can choose language. Default is "all" string preferred_method = mConfig.getValue("description_preferred_method"); if (preferred_method != "rsync" && preferred_method != "archive") preferred_method = "rsync"; vector<string> methods; if (preferred_method == "rsync") { methods.push_back("rsync"); methods.push_back("archive"); } else if (preferred_method == "archive") { methods.push_back("archive"); methods.push_back("rsync"); } string _lang = mConfig.getValue("description_languages"); vector<string> preferred_languages = splitString(_lang, " "); for (size_t i=0; i<preferred_languages.size(); ++i) { if (cutSpaces(preferred_languages[i]).empty()) { preferred_languages.erase(preferred_languages.begin() + i); i--; } } if (preferred_languages.empty()) preferred_languages.push_back("all"); string this_method; bool lang_got; for (size_t l = 0; l < preferred_languages.size(); ++l) { lang_got = false; for (size_t m = 0; !lang_got && m < methods.size(); ++m) { for (size_t d=0; d<descriptions.size(); ++d) { if (descriptions[d].first != preferred_languages[l]) continue; if (descriptions[d].second.find("rsync://")==0) this_method = "rsync"; else this_method = "archive"; if (this_method == methods[m]) { if (this_method == "rsync") { rsyncDescriptions(descriptions[d].second, base_path); lang_got = true; } else if (this_method == "archive") { wgetDescriptions(descriptions[d].second, base_path); lang_got = true; } } } } } return 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; }
void PkgScanResults::parseNotFound(const string &filename, const string & data) { string libname = cutSpaces(data); libname = libname.substr(0, libname.find_first_of(" \t")); PkgNotFoundError sError; sError.filename = filename; sError.libname = libname; notFoundErrors.push_back(sError); }
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; }
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; }
int TextSetup::showPartitionMenu(const string& part) { vector<MenuItem> m, fs = getKnownFilesystems(); string mountinfo, fsinfo, fsoptionsinfo, partinfo; int ret = 0; string mount_point, filesystem, fs_options; ncInterface.setSubtitle(part + _(": options")); while (ret!=3 && ret>=0) { m.clear(); for (size_t i=0; i<mech.partitions.size(); ++i) { if (mech.partitions[i].devname!=part) continue; partinfo = mech.partitions[i].devname + " (" + humanizeSize((int64_t) atol(mech.partitions[i].size.c_str())*(int64_t) 1048576) + ", " + mech.partitions[i].fstype; if (!partitions[part]["mountpoint"].empty()) mountinfo = partitions[part]["mountpoint"]; else mountinfo = _("None"); if (partitions[part]["format"] == "1") fsinfo = partitions[part]["fs"]; else fsinfo = _("Keep data"); if (partitions[part]["options"] == "1") fsoptionsinfo = partitions[part]["options"]; else fsoptionsinfo = _("Defaults"); break; } m.push_back(MenuItem(_("Mount point:"), mountinfo)); m.push_back(MenuItem(_("Format to:"), fsinfo)); m.push_back(MenuItem(_("Mount options:"), fsoptionsinfo)); m.push_back(MenuItem(_("CONTINUE"), _("Continue"))); ret = ncInterface.showMenu(_("Select parameters for partition ") + partinfo, m, ret); switch(ret) { case 0: partitions[part]["mountpoint"] = cutSpaces(ncInterface.showInputBox(_("Enter mount point for partition ") + \ part + _(", for example: '/boot' (without quotes). For swap partition, enter 'swap'. For root partition, enter '/'. If you wish to leave partition unused, leave this field empty."), \ partitions[part]["mountpoint"])); if (partitions[part]["mountpoint"] == "swap") { partitions[part]["fs"] = "linux-swap(v1)"; partitions[part]["format"] = "0"; partitions[part]["options"] = ""; } break; case 1: if (partitions[part]["mountpoint"]=="swap") { ncInterface.showMsgBox(_("Not applicable for swap partitions")); break; } filesystem = ncInterface.showMenu2(_("Select filesystem for partition ") + \ part + " (" + partitions[part]["mountpoint"] + _("). Select 'NONE' if you wish to keep data. NOTE: IF YOU CREATE NEW FILESYSTEM HERE, ALL DATA ON PARTITION WILL BE DESTROYED!"), \ fs, partitions[part]["fs"]); if (filesystem=="NONE") { for (size_t i=0; i<mech.partitions.size(); ++i) { if (mech.partitions[i].devname == part) { partitions[part]["fs"]=mech.partitions[i].fstype; break; } } partitions[part]["format"] = "0"; } else { partitions[part]["fs"] = filesystem; partitions[part]["format"] = "1"; } break; case 2: if (partitions[part]["mountpoint"]=="swap") { ncInterface.showMsgBox(_("Not applicable for swap partitions")); break; } partitions[part]["options"] = ncInterface.showInputBox(_("Enter mount options for partition ") + \ part + "(" + partitions[part]["mountpoint"] + ", " + partitions[part]["fs"] + _("). If you don't know what this stuff means, it is STRONGLY RECOMMENDED to leave it empty (to use default values)."), \ partitions[part]["options"]); break; default: return 0; } } return 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; }
//XMLNode _rootFList; int slackpackages2list (string *packageslist, string *md5list, PACKAGE_LIST *pkglist, string server_url) { if (actionBus._abortActions) { actionBus._abortComplete=true; actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED); say("aborted\n"); return MPKGERROR_ABORTED; } if (packageslist->length()<20) { say("aborted\n"); return -1; // It's impossible if it has less size... } // Parsing slackware PACKAGES.TXT file // Keywords (in [] braces to show spaces: // [PACKAGE NAME: ] going first or after \n\n symbols. Until \n, contains package filename (that contains name, version, arch and build information) // [PACKAGE LOCATION: ] location of package (from repository root). Going after \n // [PACKAGE SIZE (compressed): ] // [PACKAGE SIZE (uncompressed): ] // [PACKAGE REQUIRED: ] // [PACKAGE SUGGESTS: ] // [PACKAGE DESCRIPTION:\n] Package description (max 11 lines starting with [package_name:]) PACKAGE *pkg = new PACKAGE; LOCATION *tmplocation = new LOCATION; #ifdef ENABLE_INTERNATIONAL DESCRIPTION *tmpDesc = new DESCRIPTION; tmpDesc->set_language("en"); #endif string *tmpDescStr = new string; string *tmpstr = packageslist; int tmpSize; int lines = 0; int name_start = 0; bool endReached = false; string slackPackageName; string slackPackageLocation; string slackCompressedSize; string slackUncompressedSize; string slackRequired; string slackSuggests; string slackDescription; string filename; string tmp; string md5tmp; string pkgNameKeyword = "PACKAGE NAME: "; string pkgLocationKeyword = "PACKAGE LOCATION: "; string pkgCompressedKeyword = "PACKAGE SIZE (compressed): "; string pkgUncompressedKeyword = "PACKAGE SIZE (uncompressed): "; string pkgRequiredKeyword = "PACKAGE REQUIRED: "; string pkgSuggestsKeyword = "PACKAGE SUGGESTS: "; string pkgDescriptionKeyword = "PACKAGE DESCRIPTION:"; unsigned int pos; unsigned int num=0; //tmpstr = packageslist; // Visualization actionBus.setActionProgress(ACTIONID_DBUPDATE, 0); unsigned int tmp_max = tmpstr->length(); actionBus.setActionProgressMaximum(ACTIONID_DBUPDATE, (double) tmpstr->length()); //progressEnabled = true; while (!endReached) { if (actionBus._abortActions) { actionBus._abortComplete=true; actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED); say("aborted\n"); return MPKGERROR_ABORTED; } actionBus.setActionProgress (ACTIONID_DBUPDATE, (double) tmp_max - tmpstr->length()); mDebug("Parsing "+IntToStr(num)+" package"); // Stage 1: retrieving dirty info pos = tmpstr->find(pkgNameKeyword); *tmpstr=tmpstr->substr(pos+pkgNameKeyword.length()); // Cuts off a header and keyword pos = tmpstr->find("\n"); // Searching end of line slackPackageName = tmpstr->substr(0,pos); // Filling package name (in full form) mDebug("slackPackageName = "+slackPackageName); pos = tmpstr->find(pkgLocationKeyword); *tmpstr = tmpstr->substr(pkgLocationKeyword.length()+pos); pos = tmpstr->find("\n"); slackPackageLocation = tmpstr->substr(0,pos); mDebug("slackPackageLocation = "+ slackPackageLocation); pos = tmpstr->find(pkgCompressedKeyword); *tmpstr = tmpstr->substr(pos + pkgCompressedKeyword.length()); pos = tmpstr->find("\n"); slackCompressedSize = tmpstr->substr(0,pos); mDebug("slackCompressedSize = " + slackCompressedSize); pos = tmpstr->find(pkgUncompressedKeyword); *tmpstr = tmpstr->substr(pos + pkgUncompressedKeyword.length()); pos = tmpstr->find("\n"); slackUncompressedSize = tmpstr->substr(0,pos); mDebug("slackUncompressedSize = " + slackUncompressedSize); pos = tmpstr->find(pkgRequiredKeyword); if (pos < tmpstr->find(pkgNameKeyword)) { mDebug("required list present!"); *tmpstr = tmpstr->substr(pos + pkgRequiredKeyword.length()); pos = tmpstr->find("\n"); slackRequired = tmpstr->substr(0,pos); mDebug("slackRequired = " + slackRequired); } else { mDebug("no required list"); slackRequired.clear(); } pos = tmpstr->find(pkgSuggestsKeyword); if (pos < tmpstr->find(pkgNameKeyword)) { mDebug("suggest list present!"); *tmpstr = tmpstr->substr(pos + pkgSuggestsKeyword.length()); pos = tmpstr->find("\n"); slackSuggests = tmpstr->substr(0,pos); mDebug("slackSuggests = " + slackSuggests); } else { slackSuggests.clear(); mDebug("no suggest list"); } pos = tmpstr->find(pkgDescriptionKeyword); *tmpstr = tmpstr->substr(pos + pkgSuggestsKeyword.length()+1); // +1 because there are newline pos = tmpstr->find(pkgNameKeyword); mDebug("searched end"); if (pos == std::string::npos) { mDebug("description end reached"); slackDescription = *tmpstr; mDebug("slackDescription = " + slackDescription); endReached = true; } else { slackDescription = tmpstr->substr(0,pos-1); mDebug("slackDescription = "+ slackDescription); } // Stage 2: info cleanup // Filename pkg->set_filename(&slackPackageName); if (md5list->find(slackPackageName) == std::string::npos) { mError("MD5 checksum not found for package " + slackPackageName +", skipping"); } else { mDebug("md5 found"); md5tmp = md5list->substr(0,md5list->find(slackPackageName)); } md5tmp = md5tmp.substr(0, md5tmp.find_last_of(" \t")); md5tmp = md5tmp.substr(md5tmp.rfind("\n")+1); md5tmp = cutSpaces(md5tmp); pkg->set_md5(&md5tmp); mDebug("MD5 = " + md5tmp); filename = slackPackageName; // Name, version, arch, build pos = slackDescription.find(":"); mDebug("pos = "+IntToStr(pos)); tmp.clear(); if (true) { name_start=0; for (int i=filename.length()-1; filename[i]!='/' && i>=0; i--) { name_start=i; } for (unsigned int i=name_start; i<filename.length()-1; i++) { if (filename[i]=='-') { if (filename[i+1]=='0' || \ filename[i+1] == '1' || \ filename[i+1] == '2' || \ filename[i+1] == '3' || \ filename[i+1] == '4' || \ filename[i+1] == '5' || \ filename[i+1] == '6' || \ filename[i+1] == '7' || \ filename[i+1] == '8' || \ filename[i+1] == '9') { pkg->set_name(&tmp); pos=i+2; break; } } tmp+=filename[i]; } tmp.clear(); //VERSION for (unsigned int i=pos-1; i< filename.length(); i++) { if (filename[i]=='-') { pkg->set_version(&tmp); pos=i+2; break; } tmp+=filename[i]; } tmp.clear(); //ARCH for (unsigned int i=pos-1; i< filename.length(); i++) { if (filename[i]=='-') { pkg->set_arch(&tmp); pos=i+2; break; } tmp+=filename[i]; } tmp.clear(); //BUILD for (unsigned int i=pos-1; i<filename.length()-4; i++) { tmp+=filename[i]; } pkg->set_build(&tmp); tmp.clear(); } mDebug("package name: "+ *pkg->get_name()); mDebug("package version: "+ *pkg->get_version()); mDebug("package arch: "+ *pkg->get_arch()); mDebug("package build: "+ *pkg->get_build()); // Location if (slackPackageLocation.find("./") == 0) { mDebug("DOTCUT:"); slackPackageLocation = slackPackageLocation.substr(2); } tmplocation->set_path(&slackPackageLocation); tmplocation->set_server_url(&server_url); pkg->get_locations()->push_back(*tmplocation); //mDebug("LOC_SET: "+*pkg->get_locations()->at(0)->get_path()); // Size tmpSize = atoi(slackCompressedSize.substr(0, slackCompressedSize.length()-2).c_str()); *pkg->get_compressed_size()=IntToStr(tmpSize*1024); mDebug("package size (compressed): "+ *pkg->get_compressed_size()); tmpSize = atoi(slackUncompressedSize.substr(0, slackUncompressedSize.length()-2).c_str()); *pkg->get_installed_size()=IntToStr(tmpSize*1024); mDebug("package size (uncompressed): "+ *pkg->get_installed_size()); mDebug("reached description"); // Description tmpDescStr->clear(); if (slackDescription.length()>0) { slackDescription = slackDescription.substr(1); if (slackDescription.length() >= slackDescription.find(*pkg->get_name()+": ") + pkg->get_name()->length()+2) { slackDescription = slackDescription.substr(slackDescription.find(*pkg->get_name()+": ")+pkg->get_name()->length()+2); //tmpDesc->set_shorttext(slackDescription.substr(0, slackDescription.find_first_of("\n"))); *pkg->get_short_description()=slackDescription.substr(0, slackDescription.find_first_of("\n")); //mDebug("short description: "+slackDescription.substr(0, slackDescription.find_first_of("\n"))); } pos = slackDescription.find("\n"); lines = 0; while (pos != std::string::npos && lines < 11) { pos = slackDescription.find(*pkg->get_name()+": "); if (pos == std::string::npos) { mDebug("Description end"); } else { slackDescription = slackDescription.substr(pos+pkg->get_name()->length()+2); *tmpDescStr = *tmpDescStr + slackDescription.substr(0,slackDescription.find("\n"))+"\n"; lines++; } } mDebug("Description: "+ *tmpDescStr); //tmpDesc->set_text(*tmpDescStr); pkg->set_description(tmpDescStr); #ifdef ENABLE_INTERNATIONAL pkg->get_descriptions()->add(tmpDesc); #endif } pkglist->add(pkg); pkg->clear(); num++; mDebug("done"); } delete pkg; delete tmplocation; //delete tmpDesc; delete tmpDescStr; //delete tmpstr; return 0; } // End slackpackages2list()