It is still experimental, needs SL DVD Edition (for now) and your gentoo system mounted into /mnt/gentoo.
upgrade.py (DO NOT COPY/PASTE --> grab it here:
- Code: Select all
#!/usr/bin/python
import os,sys
import time
import re
def listPackages(listing):
packages_counter = -1
packages = []
for package in listing:
package = package.strip()
packages.append(package)
packages_counter += 1
return packages, packages_counter
instPath = "/mnt/gentoo"
kdeversion = "3.5"
# Create a packages blacklist. These packages won't be touched
#blacklist = [ "portage", "eselect" ]
forced_upgrade_list = [ "grub" ]
# Create the Live system packages list
put, get = os.popen4("find /var/db/pkg/ -maxdepth 2 | sed 's/\/var\/db\/pkg\///' | grep '/'")
listing = get.readlines()
live_packages, live_packages_counter = listPackages(listing)
del listing
if not os.access(instPath+"/var/db/pkg",os.F_OK):
print "This is not Gentoo or Sabayon !"
sys.exit(1)
print "Live available packages number: "+str(live_packages_counter)
# otherwise collect installed packages
put, get = os.popen4("cd "+instPath+"/var/db/pkg/ && find ./ -maxdepth 2 | sed 's/.\///' | grep '/'")
listing = get.readlines()
installed_packages, installed_packages_counter = listPackages(listing)
del listing
if not installed_packages_counter > 0:
print "This is not Gentoo or Sabayon !"
sys.exit(2)
print "Installed packages number: "+str(installed_packages_counter)
# First of all, copy /etc/portage to the destination
os.system("rm -rf "+instPath+"/etc/portage && cp /etc/portage "+instPath+"/etc -Rp")
# copy /etc/make.conf to destination
os.system("cp /etc/make.conf.lxnaydesign "+instPath+"/etc/make.conf && cp /etc/make.conf.lxnaydesign /etc/make.conf")
# then we want to copy the overlays
# we have to parse PORTDIR_OVERLAY=""
make_conf_file = open(instPath+"/etc/make.conf","r")
make_conf = make_conf_file.readlines()
make_conf_file.close()
for line in make_conf:
line = line.strip()
if line.startswith("PORTDIR_OVERLAY"):
overlays = line.strip('"')
overlays = overlays[1].split(" ")
for overlay in overlays:
overlay = overlay.strip()
if overlay != "" and os.access(overlay,os.F_OK):
if os.access(instPath+overlay,os.F_OK):
os.system("rm -rf "+instPath+overlay)
os.system("cp -Rp "+overlay+" "+instPath+overlay)
print "copying "+overlay
# Copy over /etc/splash/ directory
if os.access(instPath+"/usr/splash",os.F_OK):
os.system("rm -rf "+instPath+"/usr/splash/*")
os.system("cp /etc/splash/* "+instPath+"/usr/splash/ -Rp")
else:
os.system("rm -rf "+instPath+"/etc/splash/*")
os.system("cp /etc/splash/* "+instPath+"/etc/splash/ -Rp")
# Now we need to upgrade the kernel and the splash theme manually
# something else? maybe /etc/rc.conf, /etc/udev/rules.d/, /etc/conf.d/rc ?
# check that eselect opengl show is the same as the beginning ?
# Prepare Linux sources /boot/grub and /lib/modules/ directory - Anaconda will do the rest
if os.path.islink(instPath+"/usr/src/linux"):
os.system("rm -rf "+instPath+"/usr/src/linux")
# GRUB config
if os.path.isfile(instPath+"/boot/grub/grub.conf"):
os.system("mv "+instPath+"/boot/grub/grub.conf "+instPath+"/boot/grub/grub.conf.upgrade_backup")
# Kernel binaries
os.system("mkdir "+instPath+"/boot/upgrade_backup &> /dev/null; mv -f "+instPath+"/boot/kernel-* "+instPath+"/boot/upgrade_backup/; mv -f "+instPath+"/boot/initramfs-* "+instPath+"/boot/upgrade_backup/; mv -f "+instPath+"/boot/System.map-* "+instPath+"/boot/upgrade_backup/")
os.system("cp /mnt/livecd/boot/kernel-* "+instPath+"/boot/ -Rp")
os.system("cp /mnt/livecd/boot/initramfs-* "+instPath+"/boot/ -Rp")
os.system("cp /mnt/livecd/boot/System.map-* "+instPath+"/boot/ -Rp")
# Kernel modules
if os.path.isdir(instPath+"/lib/modules-upgrade_backup"):
os.system("rm -rf "+instPath+"/lib/modules-upgrade_backup")
os.system("mkdir "+instPath+"/lib/modules-upgrade_backup &> /dev/null; mv -f "+instPath+"/lib/modules/* "+instPath+"/lib/modules-upgrade_backup/")
os.system("cp /mnt/livecd/lib/modules/* "+instPath+"/lib/modules/ -Rp")
# Fix stupid gconf stuff
if os.path.isdir(instPath+"/usr/gconf") and os.path.islink(instPath+"/etc/gconf"):
os.system("rm "+instPath+"/etc/gconf -rf && mv -f "+instPath+"/usr/gconf "+instPath+"/etc/")
# Copy /etc/gconf to system
if os.path.isdir("/usr/gconf"):
os.system("rm -rf "+instPath+"/etc/gconf; cp /usr/gconf "+instPath+"/etc -Rp")
elif os.path.isdir("/etc/gconf"):
os.system("rm -rf "+instPath+"/etc/gconf; cp /etc/gconf "+instPath+"/etc -Rp")
# Fix possible /var/tmp unexistance
if not os.path.isdir(instPath+"/var/tmp"):
os.system("mkdir -p "+instPath+"/var/tmp")
# Cleanup Portage db
os.system("for file in `find "+instPath+"/var/db/pkg/ -name -MERGING-*`; do rm -rf $file; done")
# Do we need to update the portage tree? Yes, we need portage tarfile from the DVD.
# Should the user select the path of it under Anaconda or force to use a DVD edition?
# Well, check if we have:
# a. an empty portage --> we need to fill that
# b. the portage db is available under /mnt/cdrom/snapshots/snapshot.tar.bz2
user_specified_path="/home/sabayonuser/snapshot.tar.bz2"
# Check if the tar file exists and start to update it
# There will be a file selector that let the user to specify a portage tarfile --> for the minis
if os.access("/mnt/cdrom/snapshots/snapshot.tar.bz2",os.F_OK):
# ok start to update the Portage tree.
os.system("rm -rf "+instPath+"/usr/portage && tar xjf /mnt/cdrom/snapshots/snapshot.tar.bz2 -C "+instPath+"/usr/")
os.system("mkdir -p "+instPath+"/usr/portage/packages")
elif os.access(user_specified_path,os.F_OK):
os.system("rm -rf "+instPath+"/usr/portage && tar xjf '"+user_specified_path+"' -C "+instPath+"/usr/")
os.system("mkdir -p "+instPath+"/usr/portage/packages")
else:
print "Cannot continue - snapshot.tar.bz2 is not valid"
sys.exit(1)
# Portage is prepared now.
# Prepare live portage links
os.system("rm -rf /usr/portage/eclass")
os.system("rm -rf /usr/portage/profiles")
os.system("ln -sf "+instPath+"/usr/portage/eclass /usr/portage/")
os.system("ln -sf "+instPath+"/usr/portage/profiles /usr/portage/")
# Now, we have to create two containers:
# 1. to_be_removed = packages that will be removed
# 2. to_be_updated = packages that will be updated
# 3. to_be_added = packages that will be added
to_be_removed = [] # this array will include packages that conflicts with others
to_be_updated = []
to_be_added = []
# Create to be updated container
for package in installed_packages:
# Compare each package with every package in live_packages
# but first, shrink down the package name, and remove the version number
package = package.strip()
package_sub = re.split('/',package,0)
# [0] --> package name
# [1] --> package version
# Filter packages like doom-data-1, where there's no "." after the version number
### !! we workaround this later, when we decide what packages need to be removed
#package_sub_filter_bad_packages = re.split('-',package_sub[1],0)
package_name = re.split('-\d.',package_sub[1],0)
package_name = package_name[0]
package_sub2 = re.split('-',package,0)
package_last_part = package_sub2[len(package_sub2)-1]
if package_last_part.startswith("r"):
package_version = package_sub2[len(package_sub2)-2]+"-"+package_sub2[len(package_sub2)-1]
else:
package_version = package_last_part
#need_upgrade = False
#need_add = False
need_remove = False
package_is_installed = False
package_installed_name = ""
#print package_name+" @ "+package_version
# Then we have to search this package into live_packages and decide what to do
for live_package in live_packages:
live_package = live_package.strip()
live_package_sub = re.split('/',live_package,0)
live_package_name = re.split('-\d.',live_package_sub[1],0)
live_package_name = live_package_name[0]
live_package_sub = re.split('-',live_package,0)
live_package_last_part = live_package_sub[len(live_package_sub)-1]
if live_package_last_part.startswith("r"):
live_package_version = live_package_sub[len(live_package_sub)-2]+"-"+live_package_sub[len(live_package_sub)-1]
else:
live_package_version = live_package_last_part
# start to search string package_name and package_version into the live packages
if live_package_name == package_name:
package_is_installed = True
package_installed_name = package_name
if package_is_installed == False:
if not package_name.startswith("-MERGING-"):
if package_version.find(".") == -1 and package_version.find("_") == -1 and len(package_version) < 2:
to_be_removed.append(package_sub[0]+"/"+package_name)
else:
to_be_removed.append(package_sub[0]+"/"+package_name+"-"+package_version)
# Create to_be_added and to_be_updated container
for live_package in live_packages:
live_package = live_package.strip()
live_package_sub = re.split('/',live_package,0)
live_package_name = re.split('-\d.',live_package_sub[1],0)
live_package_name = live_package_name[0]
live_package_sub2 = re.split('-',live_package,0)
live_package_last_part = live_package_sub2[len(live_package_sub2)-1]
if live_package_last_part.startswith("r"):
live_package_version = live_package_sub2[len(live_package_sub2)-2]+"-"+live_package_sub2[len(live_package_sub2)-1]
else:
live_package_version = live_package_last_part
need_add = False
need_upgrade = False
package_found = False
upgrade_package_version = ""
for package in installed_packages:
package = package.strip()
package_sub = re.split('/',package,0)
# [0] --> package name
# [1] --> package version
package_name = re.split('-\d.',package_sub[1],0)
package_name = package_name[0]
package_sub2 = re.split('-',package,0)
package_last_part = package_sub2[len(package_sub2)-1]
if package_last_part.startswith("r"):
package_version = package_sub2[len(package_sub2)-2]+"-"+package_sub2[len(package_sub2)-1]
else:
package_version = package_last_part
# Check if the package needs to be added
if live_package_name != package_name:
if package_found == False:
need_add = True
else:
need_add = False
else:
# Found !
package_found = True
need_add = False
if live_package_name == package_name:
package_is_installed = True
package_installed_version = package_version
# Found !
# so, we don't need to add or remove, just see if we need to upgrade or not
if live_package_version != package_version:
need_upgrade = True
if need_add == True:
# filter lila fscking stuff - I need to remove manually these packages...
if not live_package_name.startswith("lila-"):
if live_package_version.find(".") == -1 and live_package_version.find("_") == -1 and len(live_package_version) < 2:
to_be_added.append(live_package_sub[0]+"/"+live_package_name)
else:
to_be_added.append(live_package_sub[0]+"/"+live_package_name+"-"+live_package_version)
if need_upgrade == True:
if live_package_version.find(".") == -1 and live_package_version.find("_") == -1 and len(live_package_version) < 2:
to_be_updated.append(live_package_sub[0]+"/"+live_package_name)
else:
to_be_updated.append(live_package_sub[0]+"/"+live_package_name+"-"+live_package_version)
# We need to fill to_be_added properly now
# Now we have to filter the to_be_updated container because it contains slotted packages that don't need to be changed
# we have to_be_updated
to_be_really_updated = []
for package in to_be_updated:
need_upgrade = True
packages_match = False
for package_check in installed_packages:
package_check = package_check.strip()
package_check_sub = re.split('/',package_check,0)
package_check_name = re.split('-\d.',package_check_sub[1],0)
package_check_name = package_check_name[0]
package_check_sub2 = re.split('-',package_check,0)
package_check_last_part = package_check_sub2[len(package_check_sub2)-1]
if package_check_last_part.startswith("r"):
package_check_version = package_check_sub2[len(package_check_sub2)-2]+"-"+package_check_sub2[len(package_check_sub2)-1]
else:
package_check_version = package_check_last_part
if package != package_check:
# No match - no party ! :P
if packages_match == False:
need_upgrade == True
else:
# wow - they match !
packages_match = True
need_upgrade = False
if need_upgrade == True:
to_be_really_updated.append(package)
to_be_updated = to_be_really_updated
import string
# First, remove the packages:
if to_be_removed != []:
to_be_removed_string = []
for package in to_be_removed:
to_be_removed_string.append("="+package)
removal_string = string.join(to_be_removed_string)
print "to be removed: \n"+removal_string+"\n"
for package in to_be_removed_string:
os.system("echo emerge -C "+package+" | chroot "+instPath)
print "\n :: REMOVAL OK ::"
else:
print "\n no packages to remove \n"
if to_be_added != []:
to_be_added_string = []
for package in to_be_added:
to_be_added_string.append("="+package)
add_string = string.join(to_be_added)
add_string_with_version = string.join(to_be_added_string)
print "to be added: \n"+add_string_with_version+"\n"
for package in to_be_added_string:
os.system("rm -rf "+instPath+"/usr/portage/packages/*")
os.system('PKGDIR="'+instPath+'/usr/portage/packages" PORTAGE_TMPDIR="'+instPath+'/mnt/gentoo/var/tmp" quickpkg '+package)
os.system("PORTDIR="+instPath+"/usr/portage/ PORTAGE_TMPDIR="+instPath+"/var/tmp ROOT="+instPath+"/ PKGDIR="+instPath+"/usr/portage/packages emerge -K --nodeps "+package)
os.system("echo update-mime-database /usr/share/mime | chroot "+instPath)
else:
print "\n no packages to add \n"
if to_be_updated != []:
to_be_updated_string = []
for package in to_be_updated:
to_be_updated_string.append("="+package)
update_string = string.join(to_be_updated)
update_string_with_version = string.join(to_be_updated_string)
print "to be updated: \n"+update_string_with_version+"\n"
for package in to_be_updated_string:
os.system('PKGDIR="'+instPath+'/usr/portage/packages" quickpkg '+package)
os.system("PORTDIR="+instPath+"/usr/portage/ PORTAGE_TMPDIR="+instPath+"/var/tmp ROOT="+instPath+"/ PKGDIR="+instPath+"/usr/portage/packages emerge -K --nodeps "+package)
os.system("echo update-mime-database /usr/share/mime | chroot "+instPath)
for forced_package in forced_upgrade_list:
os.system("rm -rf "+instPath+"/usr/portage/packages/*")
os.system('PKGDIR="'+instPath+'/usr/portage/packages" quickpkg '+forced_package)
os.system("PORTDIR="+instPath+"/usr/portage/ PORTAGE_TMPDIR="+instPath+"/var/tmp ROOT="+instPath+"/ PKGDIR="+instPath+"/usr/portage/packages emerge -K --nodeps "+forced_package)
os.system("echo update-mime-database /usr/share/mime | chroot "+instPath)
else:
print "\n no packages to update \n"
# Fixing weird bugs that I've found:
os.system("rm -rf "+instPath+"/usr/kde/"+kdeversion+"/bin/amarok*")
os.system("rm -rf "+instPath+"/usr/kde/"+kdeversion+"/lib/libamarok*")
os.system("rm -rf "+instPath+"/usr/kde/"+kdeversion+"/lib64/libamarok*")
os.system("cp /lib/libgcc_s* "+instPath+"/lib/ -Rp")
# fscking bug... bah... just make a symlink
if not os.access(instPath+"/usr/lib/libXaw.7",os.F_OK):
os.system("echo ln -sf /usr/lib/libXaw.7.so /usr/lib/libXaw.7 | chroot "+instPath)
# Fixup compiler selection
# Configure GCC - yay ! or... banzaiiiii ! (Fantozzi way...)
os.system("echo emerge -P gcc | chroot "+instPath)
os.system("rm -rf "+instPath+"/etc/eselect/compiler/*")
os.system("cp /etc/eselect/compiler/* "+instPath+"/etc/eselect/compiler/ -Rp")
os.system("echo gcc-config 1 | chroot "+instPath)
# Now we have to find if there are still broken packages by running broken-apps-test.sh
# NEEDFIX: change the .sh path when you'll import that into anaconda - for now the path
# is hardcoded to /home/sabayonuser/broken-apps-test.sh
if os.access(instPath+"/tmp/broken-apps-test.txt",os.F_OK):
os.system("rm -rf "+instPath+"/tmp/broken-apps-test.txt")
os.system("cp /home/sabayonuser/broken-apps-test.sh "+instPath+"/")
os.system("echo /broken-apps-test.sh | chroot "+instPath)
if os.access(instPath+"/tmp/broken-apps-test.txt",os.F_OK):
# we need to fix something
put, get = os.popen4("cat "+instPath+"/tmp/broken-apps-test.txt")
broken_bins = get.readlines()
broken_packages = []
for binary in broken_bins:
binary = binary.strip()
put, get = os.popen4("equery -en belongs "+binary)
pkg = get.readlines()
if pkg != []:
pkg = pkg[0].strip()
if pkg != "":
broken_packages.append("="+pkg)
# Filter duplicates
broken_packages = list(set(broken_packages))
print "Broken packages to fix:\n"
print broken_packages
print "\n"
for package in broken_packages:
os.system('PKGDIR="'+instPath+'/usr/portage/packages" quickpkg '+package)
os.system("PORTDIR="+instPath+"/usr/portage/ PORTAGE_TMPDIR="+instPath+"/var/tmp ROOT="+instPath+"/ PKGDIR="+instPath+"/usr/portage/packages emerge -K --nodeps "+package)
os.system("rm -f "+instPath+"/tmp/broken-apps-test.txt")
os.system("rm -f "+instPath+"/broken-apps-test.sh")
# copy xorg.conf
os.system("cp /etc/X11/xorg.conf "+instPath+"/etc/X11/xorg.conf")
# manage system services
os.system("rm -rf "+instPath+"/etc/runlevels ; cp /etc/runlevels "+instPath+"/etc/ -Rp")
# Configuring configuration files --> LOL
# removing unused init files
os.system("echo rc-update del internetkiosk | chroot "+instPath)
os.system("echo rc-update del installer-gui | chroot "+instPath)
os.system("echo rc-update del installer-text | chroot "+instPath)
os.system("echo rc-update del localit | chroot "+instPath)
# config mDNSResponder if not set
if not os.access(instPath+"/etc/init.d/mDNSResponder",os.F_OK) and os.access(instPath+"/etc/init.d/mDNSResponderPosix",os.F_OK):
os.system("echo ln -sf /etc/init.d/mDNSResponderPosix /etc/init.d/mDNSResponder | chroot "+instPath)
# removing updates not needed --> ._cfg*
os.system("rm -rf "+instPath+"/etc/dbus-1/system.d/._cfg00*NetworkManager.conf")
os.system("rm -rf "+instPath+"/usr/kde/"+kdeversion+"/share/config/kdm/._cfg*")
os.system("rm -rf "+instPath+"/etc/init.d/._cfg000*_x-setup")
os.system("rm -rf "+instPath+"/etc/conf.d/._cfg000*_local.start")
# copy KDM X config files
os.system("cp /usr/kde/"+kdeversion+"/share/config/kdm/X* "+instPath+"/usr/kde/"+kdeversion+"/share/config/kdm/ -Rp")
# copying config files over
os.system("rm -rf "+instPath+"/etc/pango; cp /etc/pango "+instPath+"/etc/ -Rp")
os.system("cp /dev/* "+instPath+"/dev/ -Rp &> /dev/null")
# Cleanup Portage db
os.system("for file in `find "+instPath+"/var/db/pkg/ -name -MERGING-*`; do rm -rf $file; done")
# copy /usr/lib/locale
os.system("cp /usr/lib/locale/* "+instPath+"/usr/lib/locale/ -Rp")
# fixes to /etc/fstab
if os.access(instPath+"/etc/fstab",os.F_OK):
fstab_out = []
file = open(instPath+"/etc/fstab","r")
fstab = file.readlines()
file.close()
for line in fstab:
line = line.strip()
if line.find("binfmt_misc") == -1:
fstab_out.append(line)
file = open(instPath+"/etc/fstab","w")
file.writelines(fstab_out)
file.flush()
file.close()
# Setup java
# for 2: java-config-2 -L | tail --lines 1 | grep -o [0-9]") " | cut -d")" -f1
# for 1: java-config-1 -L | tail --lines 1
# do etc-update, and good luck!
os.system("echo 'echo -5 | etc-update' | chroot "+instPath)
# Always set RC_DEVICE_TARBALL to yes in /etc/conf.d/rc
os.system("sed -i 's/RC_DEVICE_TARBALL=\".*\"/RC_DEVICE_TARBALL=\"yes\"/' "+instPath+"/etc/conf.d/rc")
broken-apps-test.sh:
- Code: Select all
#!/bin/sh
rm -rf /tmp/a /tmp/b /tmp/c /tmp/d /tmp/e /tmp/f /tmp/g /tmp/h
touch /tmp/a
touch /tmp/b
touch /tmp/c
touch /tmp/d
touch /tmp/e
touch /tmp/f
touch /tmp/g
touch /tmp/h
if [ -e "/usr/lib" ];then
if [ -e "/usr/lib64" ]; then
find /usr/lib64 -maxdepth 15 -perm 755 -type f -fprint /tmp/a
else
find /usr/lib -maxdepth 15 -perm 755 -type f -fprint /tmp/a
fi
fi
if [ -e "/usr/lib32" ];then
find /usr/lib32 -maxdepth 15 -perm 755 -type f -fprint /tmp/b
fi
find /usr/bin -maxdepth 15 -perm 755 -type f -fprint /tmp/c
find /usr/sbin -maxdepth 15 -perm 755 -type f -fprint /tmp/d
find /sbin -maxdepth 15 -perm 755 -type f -fprint /tmp/e
find /bin -maxdepth 15 -perm 755 -type f -fprint /tmp/f
find /usr/kde/3.5/bin -maxdepth 15 -perm 755 -type f -fprint /tmp/g
find /usr/kde/3.5/lib64 -maxdepth 15 -perm 755 -type f -fprint /tmp/h
cat /tmp/a /tmp/b /tmp/c /tmp/d /tmp/e /tmp/f /tmp/g /tmp/h > /tmp/test-results.txt
rm -rf /tmp/a /tmp/b /tmp/c /tmp/d /tmp/e /tmp/f /tmp/g /tmp/h
for line in `cat /tmp/test-results.txt`; do
data=$(ldd $line | grep "not found")
if [ "$data" != "" ]; then
echo $line >> /tmp/broken-apps-test.txt
fi
done
rm -rf /tmp/test-results.txt
For the braves...
You'll need to put these files into /home/sabayonuser and run ./upgrade.py as root.
NOTE: they are not clean I KNOW! But for now, they work.

