home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
boot
/
i386
/
root
/
usr
/
share
/
YaST2
/
modules
/
Update.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
13KB
|
456 lines
/**
* Module: Update.ycp
*
* Authors: Anas Nashif <nashif@suse.de>
* Arvin Schnell <arvin@suse.de>
*
* Purpose: Update module
*
* $Id: Update.ycp 34202 2006-11-09 12:31:44Z locilka $
*/
{
module "Update";
import "Installation";
import "Packages";
import "ProductFeatures";
import "Stage";
import "SuSERelease";
import "Mode";
// number of packages to install
global integer packages_to_install = 0;
// number of packages to update
global integer packages_to_update = 0;
// number of packages to remove
global integer packages_to_remove = 0;
// number of packages unknown (problematic) by update
global integer unknown_packages = 0;
// number of errors (packages?) returned by solver
global integer solve_errors = 0;
// Flag is set true if the user decides to delete unmaintained packages
global boolean deleteOldPackages = ProductFeatures::GetBooleanFeature ("software", "delete_old_packages");
// don't allow upgrade only update
global boolean disallow_upgrade = false;
global boolean did_init1 = false;
global boolean did_init2 = false;
global integer last_runlevel = -1;
global boolean backup_modified = true;
global boolean backup_sysconfig = true;
global boolean remove_old_backups = false;
global string backup_path = "/var/adm/backup";
// Only an update, NOT an upgrade
global boolean onlyUpdateInstalled = ProductFeatures::GetBooleanFeature ("software", "only_update_installed");
global string selected_selection = "";
global boolean products_incompatible = false;
/*
* Information about old and new product.
*
* They do contain:
* name (string), e.g. "SuSE Linux"
* version (string), e.g. "9.1"
* nameandversion (string), e.g. "SuSE Linux 9.1"
*
* They may contain:
* major (integer), e.g. "9"
* minor (integer), e.g. "1"
*/
// Version of the targetsystem
global map <string, any> installedVersion = $[];
// Version of the source medium
global map <string, any> updateVersion = $[];
// Flag, if the basesystem have to be installed
global boolean updateBasePackages = false;
// counter for installed packages
global integer packagesInstalled = 0;
// see bug #40358
global boolean manual_interaction = false;
// are the products (installed and to update) compatible?
boolean _products_compatible = nil;
/*-----------------------------------------------------------------------
* GLOBAL FUNCTIONS
*-----------------------------------------------------------------------*/
global list<string> SelectedProducts () {
list<map<string,any> > selected
= Pkg::ResolvableProperties ("", `product, "");
selected = filter (map<string,any> p, selected, {
return p["status"]:nil == `selected;
});
return maplist (map<string,any> p, selected, {
return p["summary"]:"";
});
}
/**
* Check if installed product and product to upgrade to are compatible
* @return boolean true if update is possible
*/
global boolean ProductsCompatible () {
if (_products_compatible == nil)
{
if (Stage::normal ())
{
// check if name of one of the products on the installation
// media is same as one of the installed products
// assuming that multiple products on installation media
// are compatible and compatibility is transitive
list<map<string,any> > inst =
Pkg::ResolvableProperties ("", `product, "");
inst = filter (map<string,any> p, inst, {
return p["status"]:nil == `installed;
});
list<string> inst_names = maplist (map<string,any> p, inst, {
return p["name"]:"";
});
list<string> to_install = maplist (integer src,
Pkg::SourceGetCurrent (true),
{
map<string,string> prod_info = Pkg::SourceProduct (src);
return prod_info["name"]:"";
});
// filter out empty products
to_install = filter (string o_p, to_install, { return o_p != ""; });
y2milestone ("Installed products: %1", inst_names);
y2milestone ("Products on installation media: %1", to_install);
// at least one product name found
if (size (to_install) > 0) {
string equal_product = find (string i, inst_names, {
string found = find (string u, to_install, {
return u == i;
});
return found != nil;
});
_products_compatible = equal_product != nil;
// no product name found
// bugzilla #218720, valid without testing according to comment #10
} else {
y2warning ("No products found, setting product-compatible to 'true'");
_products_compatible = true;
}
}
else
{
_products_compatible = true; // FIXME this is temporary
}
y2milestone ("Products found compatible: %1", _products_compatible);
}
return _products_compatible;
}
global void IgnoreProductCompatibility () {
_products_compatible = true;
}
/**
*
*/
global define void Reset ()
{
deleteOldPackages = ProductFeatures::GetBooleanFeature ("software", "delete_old_packages");
disallow_upgrade = false;
manual_interaction = false;
products_incompatible = false;
_products_compatible = nil;
backup_modified = true;
backup_sysconfig = true;
remove_old_backups = false;
backup_path = "/var/adm/backup";
}
/**
*
*/
global define void fill_version_map (map <string, any>& data)
{
data["nameandversion"] = data["name"]:"?" + " " + data["version"]:"?";
list <string> tmp0 = [];
if (regexpmatch (data["version"]:"", " -")) {
splitstring (data["version"]:"", " -");
}
list <string> tmp1 = [];
if (regexpmatch (tmp0[0]:"", "\.")) {
splitstring (tmp0[0]:"", ".");
}
integer tmp2 = tointeger (tmp1[0]:"-1");
if (tmp2 >= 0)
data["major"] = tmp2;
integer tmp3 = tointeger (tmp1[1]:"-1");
if (tmp3 >= 0)
data["minor"] = tmp3;
}
/**
* Read product name and version for the old and new release.
* Fill installedVersion and updateVersion.
* @return success
*/
global define boolean GetProductName ()
{
installedVersion = $[];
updateVersion = $[];
// get old product name
// cannot use product information from package manager
// for pre-zypp products
// #153576
string old_name = SuSERelease::ReleaseInformation
(Installation::destdir);
y2milestone("SuSERelease::ReleaseInformation: %1", old_name);
// Remove 'Beta...' from product release
if (regexpmatch (old_name, "Beta")) {
old_name = regexpsub (old_name, "^(.*)[ \t]+Beta.*$", "\\1");
// Remove 'Alpha...' from product release
} else if (regexpmatch (old_name, "Alpha")) {
old_name = regexpsub (old_name, "^(.*)[ \t]+Alpha.*$", "\\1");
}
integer p = findlastof (old_name, " ");
if (p == nil)
{
y2error ("release info <%1> is screwed", old_name);
installedVersion = $[];
}
else
{
installedVersion["name"] = substring (old_name, 0, p);
installedVersion["version"] = substring (old_name, p + 1);
fill_version_map (installedVersion);
}
// "minor" and "major" version keys
// bug #153576, "version" == "9" or "10.1" or ...
string inst_ver = installedVersion["version"]:"";
if (inst_ver != "" && inst_ver != nil) {
// SLE, SLD, OES...
if (regexpmatch (inst_ver, "^[0123456789]+$")) {
installedVersion["major"] = tointeger (inst_ver);
// openSUSE
} else if (regexpmatch (inst_ver, "^[0123456789]+\.[0123456789]+$")) {
installedVersion["major"] = tointeger (regexpsub (inst_ver, "^([0123456789]+)\.[0123456789]+$", "\\1"));
installedVersion["minor"] = tointeger (regexpsub (inst_ver, "^[0123456789]+\.([0123456789]+)$", "\\1"));
} else {
y2error("Cannot find out major/minor from >%1<", inst_ver);
}
} else {
y2error("Cannot find out version: %1", installedVersion);
}
if (Mode::test()) {
y2error ("Skipping detection of new system");
return true;
}
// get new product name
integer num = size (Packages::theSources);
if (num <= 0)
{
y2error ("No source");
updateVersion["name"] = "?";
updateVersion["version"] = "?";
fill_version_map (updateVersion);
return false;
}
map new_product = Pkg::SourceProductData (Packages::theSources[num-1]:0);
y2milestone ("First source product %1", new_product);
if (new_product == nil)
{
updateVersion["name"] = "?";
updateVersion["version"] = "?";
y2error("Cannot find out source details: %1", updateVersion);
fill_version_map (updateVersion);
return false;
}
updateVersion["name"] = new_product["productname"]:"?";
updateVersion["version"] = new_product["productversion"]:"?";
fill_version_map (updateVersion);
string new_ver = updateVersion["version"]:"";
if (new_ver != "" && new_ver != nil) {
// SLE, SLD, OES...
if (regexpmatch (new_ver, "^[0123456789]+$")) {
updateVersion["major"] = tointeger (new_ver);
// openSUSE
} else if (regexpmatch (new_ver, "^[0123456789]+\.[0123456789]$")) {
updateVersion["major"] = tointeger (regexpsub (new_ver, "^([0123456789]+)\.[0123456789]$", "\\1"));
updateVersion["minor"] = tointeger (regexpsub (new_ver, "^[0123456789]+\.([0123456789])$", "\\1"));
} else {
y2error("Cannot find out major/minor from %1", new_ver);
}
} else {
y2error("Cannot find out version: %1", updateVersion);
}
y2milestone ("update from %1 to %2", installedVersion, updateVersion);
return true;
}
global list<string> GetBasePatterns ()
{
// get available base patterns
list<map<string,any> > patterns = Pkg::ResolvableProperties ("", `pattern, "");
patterns = filter (map<string,any> p, patterns, {
if (p["status"]:nil != `selected && p["status"]:nil != `available)
return false;
// if type != base
return true;
});
return maplist (map<string,any> p, patterns, {
return p["name"]:"";
});
}
/**
* Get all available base selections sorted in reverse order
* (highest ordered bases selection comes first).
*/
global define list<string> GetBaseSelections ()
{
list<string> available_base_selections = sort (string x, string y, Pkg::GetSelections (`available, "base"), {
map xmap = Pkg::SelectionData(x);
map ymap = Pkg::SelectionData(y);
return (xmap["order"]:"" > ymap["order"]:"");
});
y2milestone ("available_base_selections %1", available_base_selections);
return available_base_selections;
}
string ReadInstalledDesktop() {
SCR::Execute (.target.bash, "/bin/mv -f /etc/sysconfig/windowmanager /etc/sysconfig/windowmanager.old");
SCR::Execute (.target.bash, "/bin/ln -s /mnt/etc/sysconfig/windowmanager /etc/sysconfig/windowmanager");
string ret = (string)SCR::Read (.sysconfig.windowmanager.DEFAULT_WM);
SCR::Execute (.target.bash, "/bin/rm -f /etc/sysconfig/windowmanager");
SCR::Execute (.target.bash, "/bin/mv -f /etc/sysconfig/windowmanager.old /etc/sysconfig/windowmanager");
return ret;
}
global void SetDesktopPattern() {
string desktop = ReadInstalledDesktop();
if (desktop == "kde" || desktop == "gnome")
{
y2milestone ("Selecting pattern to install: %1", desktop);
Pkg::ResolvableInstall (desktop, `pattern);
}
}
/**
* Propose a selection for the update and save it's name in
* Update::selected_selection.
*/
global define void ProposeSelection ()
{
selected_selection = "";
list available_selections = GetBaseSelections ();
// nulth try: teh default desktop
string desktop = ReadInstalledDesktop();
map wm2sel = $[
"kde" : "default",
"gnome" : "default-Gnome",
];
selected_selection = wm2sel[desktop]:"";
if (!contains (available_selections, selected_selection))
selected_selection = "";
if (selected_selection != "")
{
y2milestone ("using default desktop %1 to define selection: %2",
desktop, selected_selection);
return;
}
// first try: installed one
list tmp1 = Pkg::GetSelections (`installed, "base");
if (tmp1 != nil && tmp1 != [])
selected_selection = tmp1[0]:"";
if (!contains (available_selections, selected_selection))
selected_selection = "";
if (selected_selection != "") {
y2milestone ("using installed selection: %1", selected_selection);
return;
}
// second try: available selection with highest order
if (size (available_selections) > 0)
selected_selection = available_selections[0]:"";
if (selected_selection != "") {
y2milestone ("using highest order selection: %1", selected_selection);
return;
}
// error: no selection available
y2error ("no selection available");
}
/**
*
*/
global define void Detach ()
{
Pkg::TargetFinish ();
did_init1 = false;
did_init2 = false;
}
}