- misc bug fixes git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@975 cd1c1023-2f26-0410-ae45-c471fc1f0318
1381 lines
55 KiB
Python
1381 lines
55 KiB
Python
#!/usr/bin/python
|
|
'''
|
|
# DESCRIPTION:
|
|
# Equo general purpose triggering scripts for pre/post install and remove
|
|
|
|
Copyright (C) 2007 Fabio Erculiani
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
'''
|
|
|
|
from commands import getoutput
|
|
from outputTools import *
|
|
from entropyConstants import *
|
|
import entropyTools
|
|
# Logging initialization
|
|
import logTools
|
|
import shutil
|
|
equoLog = logTools.LogFile(level = etpConst['equologlevel'],filename = etpConst['equologfile'], header = "[Equo]")
|
|
if etpConst['gentoo-compat']:
|
|
import portageTools
|
|
|
|
global Equo
|
|
Equo = None
|
|
|
|
'''
|
|
@ description: Gentoo toolchain variables
|
|
'''
|
|
MODULEDB_DIR="/var/lib/module-rebuild/"
|
|
INITSERVICES_DIR="/var/lib/init.d/"
|
|
|
|
'''
|
|
@description: pkgdata parser that collects post-install scripts that would be run
|
|
'''
|
|
def postinstall(pkgdata, EquoInterface):
|
|
|
|
global Equo
|
|
Equo = EquoInterface
|
|
|
|
functions = set()
|
|
|
|
# Gentoo hook
|
|
if etpConst['gentoo-compat']:
|
|
functions.add('ebuild_postinstall')
|
|
|
|
if pkgdata['trigger']:
|
|
functions.add('call_ext_postinstall')
|
|
|
|
# triggers that are not needed when gentoo-compat is enabled
|
|
if not etpConst['gentoo-compat']:
|
|
|
|
if "gnome2" in pkgdata['eclasses']:
|
|
functions.add('iconscache')
|
|
functions.add('gconfinstallschemas')
|
|
functions.add('gconfreload')
|
|
|
|
if pkgdata['name'] == "pygobject":
|
|
functions.add('pygtksetup')
|
|
|
|
# fonts configuration
|
|
if pkgdata['category'] == "media-fonts":
|
|
functions.add("fontconfig")
|
|
|
|
# gcc configuration
|
|
if pkgdata['category']+"/"+pkgdata['name'] == "sys-devel/gcc":
|
|
functions.add("gccswitch")
|
|
|
|
# binutils configuration
|
|
if pkgdata['category']+"/"+pkgdata['name'] == "sys-devel/binutils":
|
|
functions.add("binutilsswitch")
|
|
|
|
# kde package ?
|
|
if "kde" in pkgdata['eclasses']:
|
|
functions.add("kbuildsycoca")
|
|
|
|
if "kde4-base" in pkgdata['eclasses'] or "kde4-meta" in pkgdata['eclasses']:
|
|
functions.add("kbuildsycoca4")
|
|
|
|
# update mime
|
|
if "fdo-mime" in pkgdata['eclasses']:
|
|
functions.add('mimeupdate')
|
|
functions.add('mimedesktopupdate')
|
|
|
|
if pkgdata['category']+"/"+pkgdata['name'] == "dev-db/sqlite":
|
|
functions.add('sqliteinst')
|
|
|
|
# python configuration
|
|
if pkgdata['category']+"/"+pkgdata['name'] == "dev-lang/python":
|
|
functions.add("pythoninst")
|
|
|
|
# opengl configuration
|
|
if (pkgdata['category'] == "x11-drivers") and (pkgdata['name'].startswith("nvidia-") or pkgdata['name'].startswith("ati-")):
|
|
try:
|
|
functions.remove("ebuild_postinstall") # disabling gentoo postinstall since we reimplemented it
|
|
except:
|
|
pass
|
|
functions.add("openglsetup")
|
|
|
|
# load linker paths
|
|
ldpaths = entropyTools.collectLinkerPaths()
|
|
|
|
# prepare content
|
|
for x in pkgdata['content']:
|
|
if not etpConst['gentoo-compat']:
|
|
if x.startswith("/usr/share/icons") and x.endswith("index.theme"):
|
|
functions.add('iconscache')
|
|
if x.startswith("/usr/share/mime"):
|
|
functions.add('mimeupdate')
|
|
if x.startswith("/usr/share/applications"):
|
|
functions.add('mimedesktopupdate')
|
|
if x.startswith("/usr/share/omf"):
|
|
functions.add('scrollkeeper')
|
|
if x.startswith("/etc/gconf/schemas"):
|
|
functions.add('gconfreload')
|
|
if x == '/bin/su':
|
|
functions.add("susetuid")
|
|
if x.startswith('/usr/share/java-config-2/vm/'):
|
|
functions.add('add_java_config_2')
|
|
else:
|
|
if x.startswith('/lib/modules/'):
|
|
try:
|
|
functions.remove("ebuild_postinstall") # disabling gentoo postinstall since we reimplemented it
|
|
except:
|
|
pass
|
|
functions.add('kernelmod')
|
|
if x.startswith('/boot/kernel-'):
|
|
functions.add('addbootablekernel')
|
|
if x.startswith('/usr/src/'):
|
|
functions.add('createkernelsym')
|
|
if x.startswith('/etc/env.d/'):
|
|
functions.add('env_update')
|
|
if os.path.dirname(x) in ldpaths:
|
|
if x.find(".so") > -1:
|
|
functions.add('run_ldconfig')
|
|
|
|
del ldpaths
|
|
return functions
|
|
|
|
'''
|
|
@description: pkgdata parser that collects pre-install scripts that would be run
|
|
'''
|
|
def preinstall(pkgdata, EquoInterface):
|
|
|
|
global Equo
|
|
Equo = EquoInterface
|
|
|
|
functions = set()
|
|
|
|
if pkgdata['trigger']:
|
|
functions.add('call_ext_preinstall')
|
|
|
|
# Gentoo hook
|
|
if etpConst['gentoo-compat']:
|
|
functions.add('ebuild_preinstall')
|
|
|
|
for x in pkgdata['content']:
|
|
if x.startswith("/etc/init.d/"):
|
|
functions.add('initinform')
|
|
if x.startswith("/boot"):
|
|
functions.add('mountboot')
|
|
|
|
return functions
|
|
|
|
'''
|
|
@description: pkgdata parser that collects post-remove scripts that would be run
|
|
'''
|
|
def postremove(pkgdata, EquoInterface):
|
|
|
|
global Equo
|
|
Equo = EquoInterface
|
|
|
|
functions = set()
|
|
|
|
if pkgdata['trigger']:
|
|
functions.add('call_ext_postremove')
|
|
|
|
if not etpConst['gentoo-compat']:
|
|
|
|
# kde package ?
|
|
if "kde" in pkgdata['eclasses']:
|
|
functions.add("kbuildsycoca")
|
|
|
|
if "kde4-base" in pkgdata['eclasses'] or "kde4-meta" in pkgdata['eclasses']:
|
|
functions.add("kbuildsycoca4")
|
|
|
|
if pkgdata['name'] == "pygtk":
|
|
functions.add('pygtkremove')
|
|
|
|
if pkgdata['category']+"/"+pkgdata['name'] == "dev-db/sqlite":
|
|
functions.add('sqliteinst')
|
|
|
|
# python configuration
|
|
if pkgdata['category']+"/"+pkgdata['name'] == "dev-lang/python":
|
|
functions.add("pythoninst")
|
|
|
|
# fonts configuration
|
|
if pkgdata['category'] == "media-fonts":
|
|
functions.add("fontconfig")
|
|
|
|
# load linker paths
|
|
ldpaths = entropyTools.collectLinkerPaths()
|
|
|
|
for x in pkgdata['removecontent']:
|
|
if not etpConst['gentoo-compat']:
|
|
if x.startswith("/usr/share/icons") and x.endswith("index.theme"):
|
|
functions.add('iconscache')
|
|
if x.startswith("/usr/share/mime"):
|
|
functions.add('mimeupdate')
|
|
if x.startswith("/usr/share/applications"):
|
|
functions.add('mimedesktopupdate')
|
|
if x.startswith("/usr/share/omf"):
|
|
functions.add('scrollkeeper')
|
|
if x.startswith("/etc/gconf/schemas"):
|
|
functions.add('gconfreload')
|
|
else:
|
|
if x.startswith('/boot/kernel-'):
|
|
functions.add('removebootablekernel')
|
|
if x.startswith('/etc/init.d/'):
|
|
functions.add('removeinit')
|
|
if x.endswith('.py'):
|
|
functions.add('cleanpy')
|
|
if x.startswith('/etc/env.d/'):
|
|
functions.add('env_update')
|
|
if os.path.dirname(x) in ldpaths:
|
|
if x.find(".so") > -1:
|
|
functions.add('run_ldconfig')
|
|
|
|
del ldpaths
|
|
return functions
|
|
|
|
'''
|
|
@description: pkgdata parser that collects pre-remove scripts that would be run
|
|
'''
|
|
def preremove(pkgdata, EquoInterface):
|
|
|
|
global Equo
|
|
Equo = EquoInterface
|
|
|
|
functions = set()
|
|
|
|
if pkgdata['trigger']:
|
|
functions.add('call_ext_preremove')
|
|
|
|
# Gentoo hook
|
|
if etpConst['gentoo-compat']:
|
|
functions.add('ebuild_preremove')
|
|
functions.add('ebuild_postremove') # doing here because we need /var/db/pkg stuff in place and also because doesn't make any difference
|
|
|
|
# opengl configuration
|
|
if (pkgdata['category'] == "x11-drivers") and (pkgdata['name'].startswith("nvidia-") or pkgdata['name'].startswith("ati-")):
|
|
try:
|
|
functions.remove("ebuild_preremove") # disabling gentoo postinstall since we reimplemented it
|
|
functions.remove("ebuild_postremove")
|
|
except:
|
|
pass
|
|
functions.add("openglsetup_xorg")
|
|
|
|
for x in pkgdata['removecontent']:
|
|
if x.startswith("/etc/init.d/"):
|
|
functions.add('initdisable')
|
|
if x.startswith("/boot"):
|
|
functions.add('mountboot')
|
|
|
|
return functions
|
|
|
|
########################################################
|
|
####
|
|
## External triggers support functions
|
|
#
|
|
|
|
def call_ext_preinstall(pkgdata):
|
|
rc = call_ext_generic(pkgdata,'preinstall')
|
|
return rc
|
|
|
|
def call_ext_postinstall(pkgdata):
|
|
rc = call_ext_generic(pkgdata,'postinstall')
|
|
return rc
|
|
|
|
def call_ext_preremove(pkgdata):
|
|
rc = call_ext_generic(pkgdata,'preremove')
|
|
return rc
|
|
|
|
def call_ext_postremove(pkgdata):
|
|
rc = call_ext_generic(pkgdata,'postremove')
|
|
return rc
|
|
|
|
def call_ext_generic(pkgdata, stage):
|
|
|
|
# if mute, supress portage output
|
|
if etpUi['mute']:
|
|
oldsystderr = sys.stderr
|
|
oldsysstdout = sys.stdout
|
|
stdfile = open("/dev/null","w")
|
|
sys.stdout = stdfile
|
|
sys.stderr = stdfile
|
|
|
|
triggerfile = etpConst['entropyunpackdir']+"/trigger-"+str(entropyTools.getRandomNumber())
|
|
while os.path.isfile(triggerfile):
|
|
triggerfile = etpConst['entropyunpackdir']+"/trigger-"+str(entropyTools.getRandomNumber())
|
|
f = open(triggerfile,"w")
|
|
for x in pkgdata['trigger']:
|
|
f.write(x)
|
|
f.close()
|
|
|
|
# if mute, restore old stdout/stderr
|
|
if etpUi['mute']:
|
|
sys.stderr = oldsystderr
|
|
sys.stdout = oldsysstdout
|
|
stdfile.close()
|
|
|
|
|
|
my_ext_status = 0
|
|
|
|
execfile(triggerfile)
|
|
|
|
os.remove(triggerfile)
|
|
return my_ext_status
|
|
|
|
########################################################
|
|
####
|
|
## Public functions
|
|
#
|
|
|
|
def fontconfig(pkgdata):
|
|
fontdirs = set()
|
|
for xdir in pkgdata['content']:
|
|
xdir = etpConst['systemroot']+xdir
|
|
if xdir.startswith(etpConst['systemroot']+"/usr/share/fonts"):
|
|
origdir = xdir[len(etpConst['systemroot'])+16:]
|
|
if origdir:
|
|
if origdir.startswith("/"):
|
|
origdir = origdir.split("/")[1]
|
|
if os.path.isdir(xdir[:16]+"/"+origdir):
|
|
fontdirs.add(xdir[:16]+"/"+origdir)
|
|
if (fontdirs):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring fonts directory...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring fonts directory..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
for fontdir in fontdirs:
|
|
setup_font_dir(fontdir)
|
|
setup_font_cache(fontdir)
|
|
|
|
def gccswitch(pkgdata):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring GCC Profile...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring GCC Profile..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
# get gcc profile
|
|
pkgsplit = entropyTools.catpkgsplit(pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version'])
|
|
profile = pkgdata['chost']+"-"+pkgsplit[2]
|
|
set_gcc_profile(profile)
|
|
|
|
def iconscache(pkgdata):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating icons cache...")
|
|
Equo.updateProgress(
|
|
brown(" Updating icons cache..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
for item in pkgdata['content']:
|
|
item = etpConst['systemroot']+item
|
|
if item.startswith(etpConst['systemroot']+"/usr/share/icons") and item.endswith("index.theme"):
|
|
cachedir = os.path.dirname(item)
|
|
generate_icons_cache(cachedir)
|
|
|
|
def mimeupdate(pkgdata = None):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating shared mime info database...")
|
|
Equo.updateProgress(
|
|
brown(" Updating shared mime info database..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
update_mime_db()
|
|
|
|
def mimedesktopupdate(pkgdata = None):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating desktop mime database...")
|
|
Equo.updateProgress(
|
|
brown(" Updating desktop mime database..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
update_mime_desktop_db()
|
|
|
|
def scrollkeeper(pkgdata = None):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating scrollkeeper database...")
|
|
Equo.updateProgress(
|
|
brown(" Updating scrollkeeper database..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
update_scrollkeeper_db()
|
|
|
|
def gconfreload(pkgdata = None):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reloading GConf2 database...")
|
|
Equo.updateProgress(
|
|
brown(" Reloading GConf2 database..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
reload_gconf_db()
|
|
|
|
def binutilsswitch(pkgdata):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring Binutils Profile...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring Binutils Profile..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
# get binutils profile
|
|
pkgsplit = entropyTools.catpkgsplit(pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version'])
|
|
profile = pkgdata['chost']+"-"+pkgsplit[2]
|
|
set_binutils_profile(profile)
|
|
|
|
def kernelmod(pkgdata):
|
|
if pkgdata['category'] != "sys-kernel":
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Updating moduledb...")
|
|
Equo.updateProgress(
|
|
brown(" Updating moduledb..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
item = 'a:1:'+pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']
|
|
update_moduledb(item)
|
|
Equo.updateProgress(
|
|
brown(" Running depmod..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
# get kernel modules dir name
|
|
name = ''
|
|
for item in pkgdata['content']:
|
|
item = etpConst['systemroot']+item
|
|
if item.startswith(etpConst['systemroot']+"/lib/modules/"):
|
|
name = item[len(etpConst['systemroot']):]
|
|
name = name.split("/")[3]
|
|
break
|
|
if name:
|
|
run_depmod(name)
|
|
|
|
def pythoninst(pkgdata):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring Python...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring Python..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
python_update_symlink()
|
|
|
|
def sqliteinst(pkgdata):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring SQLite...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring SQLite..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
sqlite_update_symlink()
|
|
|
|
def initdisable(pkgdata):
|
|
for item in pkgdata['removecontent']:
|
|
item = etpConst['systemroot']+item
|
|
if item.startswith(etpConst['systemroot']+"/etc/init.d/") and os.path.isfile(item):
|
|
# running?
|
|
running = os.path.isfile(etpConst['systemroot']+INITSERVICES_DIR+'/started/'+os.path.basename(item))
|
|
if not etpConst['systemroot']:
|
|
myroot = "/"
|
|
else:
|
|
myroot = etpConst['systemroot']+"/"
|
|
scheduled = not os.system('ROOT="'+myroot+'" rc-update show | grep '+os.path.basename(item)+'&> /dev/null')
|
|
initdeactivate(item, running, scheduled)
|
|
|
|
def initinform(pkgdata):
|
|
for item in pkgdata['content']:
|
|
item = etpConst['systemroot']+item
|
|
if item.startswith(etpConst['systemroot']+"/etc/init.d/") and not os.path.isfile(etpConst['systemroot']+item):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] A new service will be installed: "+item)
|
|
Equo.updateProgress(
|
|
brown(" A new service will be installed: ")+item,
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
|
|
def removeinit(pkgdata):
|
|
for item in pkgdata['removecontent']:
|
|
item = etpConst['systemroot']+item
|
|
if item.startswith(etpConst['systemroot']+"/etc/init.d/") and os.path.isfile(item):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Removing boot service: "+os.path.basename(item))
|
|
Equo.updateProgress(
|
|
brown(" Removing boot service: ")+os.path.basename(item),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
if not etpConst['systemroot']:
|
|
myroot = "/"
|
|
else:
|
|
myroot = etpConst['systemroot']+"/"
|
|
try:
|
|
os.system('ROOT="'+myroot+'" rc-update del '+os.path.basename(item)+' &> /dev/null')
|
|
except:
|
|
pass
|
|
|
|
def openglsetup(pkgdata):
|
|
opengl = "xorg-x11"
|
|
if pkgdata['name'] == "nvidia-drivers":
|
|
opengl = "nvidia"
|
|
elif pkgdata['name'] == "ati-drivers":
|
|
opengl = "ati"
|
|
# is there eselect ?
|
|
eselect = os.system("eselect opengl &> /dev/null")
|
|
if eselect == 0:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reconfiguring OpenGL to "+opengl+" ...")
|
|
Equo.updateProgress(
|
|
brown(" Reconfiguring OpenGL..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
quietstring = ''
|
|
if etpUi['quiet']: quietstring = " &>/dev/null"
|
|
if etpConst['systemroot']:
|
|
os.system('echo "eselect opengl set --use-old '+opengl+'" | chroot '+etpConst['systemroot']+quietstring)
|
|
else:
|
|
os.system('eselect opengl set --use-old '+opengl+quietstring)
|
|
else:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Eselect NOT found, cannot run OpenGL trigger")
|
|
Equo.updateProgress(
|
|
brown(" Eselect NOT found, cannot run OpenGL trigger"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
|
|
def openglsetup_xorg(pkgdata):
|
|
eselect = os.system("eselect opengl &> /dev/null")
|
|
if eselect == 0:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Reconfiguring OpenGL to fallback xorg-x11 ...")
|
|
Equo.updateProgress(
|
|
brown(" Reconfiguring OpenGL..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
quietstring = ''
|
|
if etpUi['quiet']: quietstring = " &>/dev/null"
|
|
if etpConst['systemroot']:
|
|
os.system('echo "eselect opengl set xorg-x11" | chroot '+etpConst['systemroot']+quietstring)
|
|
else:
|
|
os.system('eselect opengl set xorg-x11'+quietstring)
|
|
else:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Eselect NOT found, cannot run OpenGL trigger")
|
|
Equo.updateProgress(
|
|
brown(" Eselect NOT found, cannot run OpenGL trigger"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
|
|
# FIXME: this only supports grub (no lilo support)
|
|
def addbootablekernel(pkgdata):
|
|
kernels = [x for x in pkgdata['content'] if x.startswith("/boot/kernel-")]
|
|
for kernel in kernels:
|
|
initramfs = "/boot/initramfs-"+kernel[13:]
|
|
if initramfs not in pkgdata['content']:
|
|
initramfs = ''
|
|
# configure GRUB
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring GRUB bootloader. Adding the new kernel...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring GRUB bootloader. Adding the new kernel..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
configure_boot_grub(kernel,initramfs)
|
|
|
|
|
|
# FIXME: this only supports grub (no lilo support)
|
|
def removebootablekernel(pkgdata):
|
|
kernels = [x for x in pkgdata['content'] if x.startswith("/boot/kernel-")]
|
|
for kernel in kernels:
|
|
initramfs = "/boot/initramfs-"+kernel[13:]
|
|
if initramfs not in pkgdata['content']:
|
|
initramfs = ''
|
|
# configure GRUB
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring GRUB bootloader. Removing the selected kernel...")
|
|
Equo.updateProgress(
|
|
brown(" Configuring GRUB bootloader. Removing the selected kernel..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
remove_boot_grub(kernel,initramfs)
|
|
|
|
def mountboot(pkgdata):
|
|
# is in fstab?
|
|
if etpConst['systemroot']:
|
|
return
|
|
if os.path.isfile("/etc/fstab"):
|
|
f = open("/etc/fstab","r")
|
|
fstab = f.readlines()
|
|
fstab = entropyTools.listToUtf8(fstab)
|
|
f.close()
|
|
for line in fstab:
|
|
fsline = line.split()
|
|
if len(fsline) > 1:
|
|
if fsline[1] == "/boot":
|
|
if not os.path.ismount("/boot"):
|
|
# trigger mount /boot
|
|
rc = os.system("mount /boot &> /dev/null")
|
|
if rc == 0:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] Mounted /boot successfully")
|
|
Equo.updateProgress(
|
|
brown(" Mounted /boot successfully"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
elif rc != 8192: # already mounted
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] Cannot mount /boot automatically !!")
|
|
Equo.updateProgress(
|
|
brown(" Cannot mount /boot automatically !!"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
break
|
|
|
|
def kbuildsycoca(pkgdata):
|
|
if etpConst['systemroot']:
|
|
return
|
|
kdedirs = ''
|
|
try:
|
|
kdedirs = os.environ['KDEDIRS']
|
|
except:
|
|
pass
|
|
if kdedirs:
|
|
dirs = kdedirs.split(":")
|
|
for builddir in dirs:
|
|
if os.access(builddir+"/bin/kbuildsycoca",os.X_OK):
|
|
if not os.path.isdir("/usr/share/services"):
|
|
os.makedirs("/usr/share/services")
|
|
os.chown("/usr/share/services",0,0)
|
|
os.chmod("/usr/share/services",0755)
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Running kbuildsycoca to build global KDE database")
|
|
Equo.updateProgress(
|
|
brown(" Running kbuildsycoca to build global KDE database"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
os.system(builddir+"/bin/kbuildsycoca --global --noincremental &> /dev/null")
|
|
|
|
def kbuildsycoca4(pkgdata):
|
|
if etpConst['systemroot']:
|
|
return
|
|
kdedirs = ''
|
|
try:
|
|
kdedirs = os.environ['KDEDIRS']
|
|
except:
|
|
pass
|
|
if kdedirs:
|
|
dirs = kdedirs.split(":")
|
|
for builddir in dirs:
|
|
if os.access(builddir+"/bin/kbuildsycoca4",os.X_OK):
|
|
if not os.path.isdir("/usr/share/services"):
|
|
os.makedirs("/usr/share/services")
|
|
os.chown("/usr/share/services",0,0)
|
|
os.chmod("/usr/share/services",0755)
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Running kbuildsycoca4 to build global KDE4 database")
|
|
Equo.updateProgress(
|
|
brown(" Running kbuildsycoca to build global KDE database"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
# do it
|
|
kbuild4cmd = """
|
|
|
|
# Thanks to the hard work of kde4 gentoo overlay maintainers
|
|
|
|
for i in $(dbus-launch); do
|
|
export "$i"
|
|
done
|
|
|
|
# This is needed because we support multiple kde versions installed together.
|
|
XDG_DATA_DIRS="/usr/share:${KDEDIRS}/share:/usr/local/share"
|
|
"""+builddir+"""/bin/kbuildsycoca4 --global --noincremental &> /dev/null
|
|
kill ${DBUS_SESSION_BUS_PID}
|
|
|
|
"""
|
|
os.system(kbuild4cmd)
|
|
|
|
def gconfinstallschemas(pkgdata):
|
|
gtest = os.system("which gconftool-2 &> /dev/null")
|
|
if gtest == 0 or etpConst['systemroot']:
|
|
schemas = [x for x in pkgdata['content'] if x.startswith("/etc/gconf/schemas") and x.endswith(".schemas")]
|
|
Equo.updateProgress(
|
|
brown(" Installing GConf2 schemas..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
for schema in schemas:
|
|
if not etpConst['systemroot']:
|
|
os.system("""
|
|
unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
|
|
export GCONF_CONFIG_SOURCE=$(gconftool-2 --get-default-source)
|
|
gconftool-2 --makefile-install-rule """+schema+""" 1>/dev/null
|
|
""")
|
|
else:
|
|
os.system(""" echo "
|
|
unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
|
|
export GCONF_CONFIG_SOURCE=$(gconftool-2 --get-default-source)
|
|
gconftool-2 --makefile-install-rule """+schema+""" " | chroot """+etpConst['systemroot']+""" &>/dev/null
|
|
""")
|
|
|
|
def pygtksetup(pkgdata):
|
|
python_sym_files = [x for x in pkgdata['content'] if x.endswith("pygtk.py-2.0") or x.endswith("pygtk.pth-2.0")]
|
|
for item in python_sym_files:
|
|
item = etpConst['systemroot']+item
|
|
filepath = item[:-4]
|
|
sympath = os.path.basename(item)
|
|
if os.path.isfile(item):
|
|
try:
|
|
if os.path.lexists(filepath):
|
|
os.remove(filepath)
|
|
os.symlink(sympath,filepath)
|
|
except OSError:
|
|
pass
|
|
|
|
def pygtkremove(pkgdata):
|
|
python_sym_files = [x for x in pkgdata['content'] if x.startswith("/usr/lib/python") and (x.endswith("pygtk.py-2.0") or x.endswith("pygtk.pth-2.0"))]
|
|
for item in python_sym_files:
|
|
item = etpConst['systemroot']+item
|
|
if os.path.isfile(item[:-4]):
|
|
os.remove(item[:-4])
|
|
|
|
def susetuid(pkgdata):
|
|
if os.path.isfile(etpConst['systemroot']+"/bin/su"):
|
|
Equo.updateProgress(
|
|
brown(" Configuring '"+etpConst['systemroot']+"/bin/su' executable SETUID"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
os.chown(etpConst['systemroot']+"/bin/su",0,0)
|
|
os.system("chmod 4755 "+etpConst['systemroot']+"/bin/su")
|
|
#os.chmod("/bin/su",4755) #FIXME: probably there's something I don't know here since, masks?
|
|
|
|
def cleanpy(pkgdata):
|
|
pyfiles = [x for x in pkgdata['content'] if x.endswith(".py")]
|
|
for item in pyfiles:
|
|
item = etpConst['systemroot']+item
|
|
if os.path.isfile(item+"o"):
|
|
try: os.remove(item+"o")
|
|
except OSError: pass
|
|
if os.path.isfile(item+"c"):
|
|
try: os.remove(item+"c")
|
|
except OSError: pass
|
|
|
|
def createkernelsym(pkgdata):
|
|
for item in pkgdata['content']:
|
|
item = etpConst['systemroot']+item
|
|
if item.startswith(etpConst['systemroot']+"/usr/src/"):
|
|
# extract directory
|
|
try:
|
|
todir = item[len(etpConst['systemroot']):]
|
|
todir = todir.split("/")[3]
|
|
except:
|
|
continue
|
|
if os.path.isdir(etpConst['systemroot']+"/usr/src/"+todir):
|
|
# link to /usr/src/linux
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Creating kernel symlink "+etpConst['systemroot']+"/usr/src/linux for /usr/src/"+todir)
|
|
Equo.updateProgress(
|
|
brown(" Creating kernel symlink "+etpConst['systemroot']+"/usr/src/linux for /usr/src/"+todir),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
if os.path.isfile(etpConst['systemroot']+"/usr/src/linux") or os.path.islink(etpConst['systemroot']+"/usr/src/linux"):
|
|
os.remove(etpConst['systemroot']+"/usr/src/linux")
|
|
if os.path.isdir(etpConst['systemroot']+"/usr/src/linux"):
|
|
mydir = etpConst['systemroot']+"/usr/src/linux."+str(entropyTools.getRandomNumber())
|
|
while os.path.isdir(mydir):
|
|
mydir = etpConst['systemroot']+"/usr/src/linux."+str(entropyTools.getRandomNumber())
|
|
shutil.move(etpConst['systemroot']+"/usr/src/linux",mydir)
|
|
try:
|
|
os.symlink(todir,etpConst['systemroot']+"/usr/src/linux")
|
|
except OSError: # not important in the end
|
|
pass
|
|
break
|
|
|
|
def run_ldconfig(pkgdata):
|
|
if not etpConst['systemroot']:
|
|
myroot = "/"
|
|
else:
|
|
myroot = etpConst['systemroot']+"/"
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Running ldconfig")
|
|
Equo.updateProgress(
|
|
brown(" Regenerating /etc/ld.so.cache"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
os.system("ldconfig -r "+myroot+" &> /dev/null")
|
|
|
|
def env_update(pkgdata):
|
|
# clear linker paths cache
|
|
linkerPaths.clear()
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Running env-update")
|
|
if os.access(etpConst['systemroot']+"/usr/sbin/env-update",os.X_OK):
|
|
Equo.updateProgress(
|
|
brown(" Updating environment using env-update"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
if etpConst['systemroot']:
|
|
os.system("echo 'env-update --no-ldconfig' | chroot "+etpConst['systemroot']+" &> /dev/null")
|
|
else:
|
|
os.system('env-update --no-ldconfig &> /dev/null')
|
|
|
|
def add_java_config_2(pkgdata):
|
|
vms = set()
|
|
for vm in pkgdata['content']:
|
|
vm = etpConst['systemroot']+vm
|
|
if vm.startswith(etpConst['systemroot']+"/usr/share/java-config-2/vm/") and os.path.isfile(vm):
|
|
vms.add(vm)
|
|
# sort and get the latter
|
|
if vms:
|
|
vms = list(vms)
|
|
vms.reverse()
|
|
myvm = vms[0].split("/")[-1]
|
|
if myvm:
|
|
if os.access(etpConst['systemroot']+"/usr/bin/java-config",os.X_OK):
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] Configuring JAVA using java-config with VM: "+myvm)
|
|
# set
|
|
Equo.updateProgress(
|
|
brown(" Setting system VM to ")+bold(myvm)+brown("..."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
if not etpConst['systemroot']:
|
|
os.system("java-config -S "+myvm)
|
|
else:
|
|
os.system("echo 'java-config -S "+myvm+"' | chroot "+etpConst['systemroot']+" &> /dev/null")
|
|
else:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] ATTENTION /usr/bin/java-config does not exist. I was about to set JAVA VM: "+myvm)
|
|
Equo.updateProgress(
|
|
bold(" Attention: ")+brown("/usr/bin/java-config does not exist. Cannot set JAVA VM."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
del vms
|
|
|
|
def ebuild_postinstall(pkgdata):
|
|
myebuild = [pkgdata['xpakdir']+"/"+x for x in os.listdir(pkgdata['xpakdir']) if x.endswith(".ebuild")]
|
|
if myebuild:
|
|
myebuild = myebuild[0]
|
|
portage_atom = pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']
|
|
Equo.updateProgress(
|
|
brown(" Ebuild: pkg_postinst()"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
try:
|
|
if not os.path.isfile(pkgdata['unpackdir']+"/portage/"+portage_atom+"/temp/environment"): # if environment is not yet created, we need to run pkg_setup()
|
|
# if linux-mod is found, we just disable doebuild output since will surely fail
|
|
if "linux-mod" in pkgdata['eclasses'] \
|
|
or "linux-info" in pkgdata['eclasses']:
|
|
oldsysstdout = sys.stdout
|
|
oldsysstderr = sys.stderr
|
|
sys.stdout = open("/dev/null","w")
|
|
sys.stdout = open("/dev/null","w")
|
|
rc = portageTools.portage_doebuild(myebuild, mydo = "setup", tree = "bintree", cpv = portage_atom, portage_tmpdir = pkgdata['unpackdir'])
|
|
if rc == 1:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] ATTENTION Cannot properly run Gentoo postinstall (pkg_setup()) trigger for "+str(portage_atom)+". Something bad happened.")
|
|
if "linux-mod" in pkgdata['eclasses'] \
|
|
or "linux-info" in pkgdata['eclasses']:
|
|
sys.stdout = oldsysstdout
|
|
sys.stderr = oldsysstderr
|
|
rc = portageTools.portage_doebuild(myebuild, mydo = "postinst", tree = "bintree", cpv = portage_atom, portage_tmpdir = pkgdata['unpackdir'])
|
|
if rc == 1:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] ATTENTION Cannot properly run Gentoo postinstall (pkg_postinst()) trigger for "+str(portage_atom)+". Something bad happened.")
|
|
except Exception, e:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[POST] ATTENTION Cannot run Gentoo postinst trigger for "+portage_atom+"!! "+str(Exception)+": "+str(e))
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("Cannot run Gentoo postint trigger for ")+bold(portage_atom)+brown(". Please report."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return 0
|
|
|
|
def ebuild_preinstall(pkgdata):
|
|
myebuild = [pkgdata['xpakdir']+"/"+x for x in os.listdir(pkgdata['xpakdir']) if x.endswith(".ebuild")]
|
|
if myebuild:
|
|
myebuild = myebuild[0]
|
|
portage_atom = pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']
|
|
Equo.updateProgress(
|
|
brown(" Ebuild: pkg_preinst()"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
try:
|
|
if "linux-mod" in pkgdata['eclasses'] \
|
|
or "linux-info" in pkgdata['eclasses']:
|
|
oldsysstdout = sys.stdout
|
|
oldsysstderr = sys.stderr
|
|
sys.stdout = open("/dev/null","w")
|
|
sys.stdout = open("/dev/null","w")
|
|
rc = portageTools.portage_doebuild(myebuild, mydo = "setup", tree = "bintree", cpv = portage_atom, portage_tmpdir = pkgdata['unpackdir']) # create mysettings["T"]+"/environment"
|
|
if rc == 1:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot properly run Gentoo preinstall (pkg_setup()) trigger for "+str(portage_atom)+". Something bad happened.")
|
|
if "linux-mod" in pkgdata['eclasses'] \
|
|
or "linux-info" in pkgdata['eclasses']:
|
|
sys.stdout = oldsysstdout
|
|
sys.stderr = oldsysstderr
|
|
rc = portageTools.portage_doebuild(myebuild, mydo = "preinst", tree = "bintree", cpv = portage_atom, portage_tmpdir = pkgdata['unpackdir'])
|
|
if rc == 1:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot properly run Gentoo preinstall (pkg_preinst()) trigger for "+str(portage_atom)+". Something bad happened.")
|
|
except Exception, e:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot run Gentoo preinst trigger for "+portage_atom+"!! "+str(Exception)+": "+str(e))
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("Cannot run Gentoo preinst trigger for ")+bold(portage_atom)+brown(". Please report."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return 0
|
|
|
|
def ebuild_preremove(pkgdata):
|
|
portage_atom = pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']
|
|
myebuild = portageTools.getPortageAppDbPath()+portage_atom+"/"+pkgdata['name']+"-"+pkgdata['version']+".ebuild"
|
|
if os.path.isfile(myebuild):
|
|
Equo.updateProgress(
|
|
brown(" Ebuild: pkg_prerm()"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
try:
|
|
rc = portageTools.portage_doebuild(myebuild, mydo = "prerm", tree = "bintree", cpv = portage_atom, portage_tmpdir = etpConst['entropyunpackdir']+"/"+portage_atom)
|
|
if rc == 1:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot properly run Gentoo preremove trigger for "+str(portage_atom)+". Something bad happened.")
|
|
except Exception, e:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot run Gentoo preremove trigger for "+portage_atom+"!! "+str(Exception)+": "+str(e))
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("Cannot run Gentoo preremove trigger for ")+bold(portage_atom)+brown(". Please report."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return 0
|
|
|
|
def ebuild_postremove(pkgdata):
|
|
from portageTools import getPortageAppDbPath, portage_doebuild
|
|
portage_atom = pkgdata['category']+"/"+pkgdata['name']+"-"+pkgdata['version']
|
|
myebuild = getPortageAppDbPath()+portage_atom+"/"+pkgdata['name']+"-"+pkgdata['version']+".ebuild"
|
|
if os.path.isfile(myebuild):
|
|
Equo.updateProgress(
|
|
brown(" Ebuild: pkg_postrm()"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
try:
|
|
rc = portage_doebuild(myebuild, mydo = "postrm", tree = "bintree", cpv = portage_atom, portage_tmpdir = etpConst['entropyunpackdir']+"/"+portage_atom)
|
|
if rc == 1:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot properly run Gentoo postremove trigger for "+str(portage_atom)+". Something bad happened.")
|
|
except Exception, e:
|
|
equoLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_NORMAL,"[PRE] ATTENTION Cannot run Gentoo postremove trigger for "+portage_atom+"!! "+str(Exception)+": "+str(e))
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("Cannot run Gentoo postremove trigger for ")+bold(portage_atom)+brown(". Please report."),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return 0
|
|
|
|
########################################################
|
|
####
|
|
## Internal functions
|
|
#
|
|
|
|
'''
|
|
@description: creates Xfont files
|
|
@output: returns int() as exit status
|
|
'''
|
|
def setup_font_dir(fontdir):
|
|
# mkfontscale
|
|
if os.access('/usr/bin/mkfontscale',os.X_OK):
|
|
os.system('/usr/bin/mkfontscale '+unicode(fontdir))
|
|
# mkfontdir
|
|
if os.access('/usr/bin/mkfontdir',os.X_OK):
|
|
os.system('/usr/bin/mkfontdir -e '+etpConst['systemroot']+'/usr/share/fonts/encodings -e '+etpConst['systemroot']+'/usr/share/fonts/encodings/large '+unicode(fontdir))
|
|
return 0
|
|
|
|
'''
|
|
@description: creates font cache
|
|
@output: returns int() as exit status
|
|
'''
|
|
def setup_font_cache(fontdir):
|
|
# fc-cache -f gooooo!
|
|
if os.access('/usr/bin/fc-cache',os.X_OK):
|
|
os.system('/usr/bin/fc-cache -f '+unicode(fontdir))
|
|
return 0
|
|
|
|
'''
|
|
@description: set chosen gcc profile
|
|
@output: returns int() as exit status
|
|
'''
|
|
def set_gcc_profile(profile):
|
|
if os.access(etpConst['systemroot']+'/usr/bin/gcc-config',os.X_OK):
|
|
redirect = ""
|
|
if etpUi['quiet']:
|
|
redirect = " &> /dev/null"
|
|
if etpConst['systemroot']:
|
|
os.system("echo '/usr/bin/gcc-config "+profile+"' | chroot "+etpConst['systemroot']+redirect)
|
|
else:
|
|
os.system('/usr/bin/gcc-config '+profile+redirect)
|
|
return 0
|
|
|
|
'''
|
|
@description: set chosen binutils profile
|
|
@output: returns int() as exit status
|
|
'''
|
|
def set_binutils_profile(profile):
|
|
if os.access(etpConst['systemroot']+'/usr/bin/binutils-config',os.X_OK):
|
|
redirect = ""
|
|
if etpUi['quiet']:
|
|
redirect = " &> /dev/null"
|
|
if etpConst['systemroot']:
|
|
os.system("echo '/usr/bin/binutils-config "+profile+"' | chroot "+etpConst['systemroot']+redirect)
|
|
else:
|
|
os.system('/usr/bin/binutils-config '+profile+redirect)
|
|
return 0
|
|
|
|
'''
|
|
@description: creates/updates icons cache
|
|
@output: returns int() as exit status
|
|
'''
|
|
def generate_icons_cache(cachedir):
|
|
if not etpConst['systemroot']:
|
|
myroot = "/"
|
|
else:
|
|
myroot = etpConst['systemroot']+"/"
|
|
if os.access('/usr/bin/gtk-update-icon-cache',os.X_OK):
|
|
os.system('ROOT="'+myroot+'" /usr/bin/gtk-update-icon-cache -qf '+cachedir)
|
|
return 0
|
|
|
|
'''
|
|
@description: updates /usr/share/mime database
|
|
@output: returns int() as exit status
|
|
'''
|
|
def update_mime_db():
|
|
|
|
if os.access(etpConst['systemroot']+'/usr/bin/update-mime-database',os.X_OK):
|
|
if not etpConst['systemroot']:
|
|
os.system('/usr/bin/update-mime-database /usr/share/mime')
|
|
else:
|
|
os.system("echo '/usr/bin/update-mime-database /usr/share/mime' | chroot "+etpConst['systemroot']+" &> /dev/null")
|
|
return 0
|
|
|
|
'''
|
|
@description: updates /usr/share/applications database
|
|
@output: returns int() as exit status
|
|
'''
|
|
def update_mime_desktop_db():
|
|
if os.access(etpConst['systemroot']+'/usr/bin/update-desktop-database',os.X_OK):
|
|
if not etpConst['systemroot']:
|
|
os.system('/usr/bin/update-desktop-database -q /usr/share/applications')
|
|
else:
|
|
os.system("echo '/usr/bin/update-desktop-database -q /usr/share/applications' | chroot "+etpConst['systemroot']+" &> /dev/null")
|
|
return 0
|
|
|
|
'''
|
|
@description: updates /var/lib/scrollkeeper database
|
|
@output: returns int() as exit status
|
|
'''
|
|
def update_scrollkeeper_db():
|
|
|
|
if os.access(etpConst['systemroot']+'/usr/bin/scrollkeeper-update',os.X_OK):
|
|
|
|
if not os.path.isdir(etpConst['systemroot']+'/var/lib/scrollkeeper'):
|
|
os.makedirs(etpConst['systemroot']+'/var/lib/scrollkeeper')
|
|
|
|
if not etpConst['systemroot']:
|
|
os.system('/usr/bin/scrollkeeper-update -q -p /var/lib/scrollkeeper')
|
|
else:
|
|
os.system("echo '/usr/bin/scrollkeeper-update -q -p /var/lib/scrollkeeper' | chroot "+etpConst['systemroot']+" &> /dev/null")
|
|
|
|
return 0
|
|
|
|
'''
|
|
@description: respawn gconfd-2 if found
|
|
@output: returns int() as exit status
|
|
'''
|
|
def reload_gconf_db():
|
|
if etpConst['systemroot']:
|
|
return 0
|
|
rc = os.system('pgrep -x gconfd-2')
|
|
if (rc == 0):
|
|
pids = getoutput('pgrep -x gconfd-2').split("\n")
|
|
pidsstr = ''
|
|
for pid in pids:
|
|
if pid:
|
|
pidsstr += pid+' '
|
|
pidsstr = pidsstr.strip()
|
|
if pidsstr:
|
|
os.system('kill -HUP '+pidsstr)
|
|
return 0
|
|
|
|
'''
|
|
@description: updates moduledb
|
|
@output: returns int() as exit status
|
|
'''
|
|
def update_moduledb(item):
|
|
if os.access(etpConst['systemroot']+'/usr/sbin/module-rebuild',os.X_OK):
|
|
if os.path.isfile(etpConst['systemroot']+MODULEDB_DIR+'moduledb'):
|
|
f = open(etpConst['systemroot']+MODULEDB_DIR+'moduledb',"r")
|
|
moduledb = f.readlines()
|
|
moduledb = entropyTools.listToUtf8(moduledb)
|
|
f.close()
|
|
avail = [x for x in moduledb if x.strip() == item]
|
|
if (not avail):
|
|
f = open(etpConst['systemroot']+MODULEDB_DIR+'moduledb',"aw")
|
|
f.write(item+"\n")
|
|
f.flush()
|
|
f.close()
|
|
return 0
|
|
|
|
'''
|
|
@description: insert kernel object into kernel modules db
|
|
@output: returns int() as exit status
|
|
'''
|
|
def run_depmod(name):
|
|
if os.access('/sbin/depmod',os.X_OK):
|
|
if not etpConst['systemroot']:
|
|
myroot = "/"
|
|
else:
|
|
myroot = etpConst['systemroot']+"/"
|
|
os.system('/sbin/depmod -a -b '+myroot+' -r '+name+' &> /dev/null')
|
|
return 0
|
|
|
|
'''
|
|
@description: update /usr/bin/python and /usr/bin/python2 symlink
|
|
@output: returns int() as exit status
|
|
'''
|
|
def python_update_symlink():
|
|
bins = [x for x in os.listdir("/usr/bin") if x.startswith("python2.")]
|
|
if bins: # don't ask me why but it happened...
|
|
bins.sort()
|
|
latest = bins[-1]
|
|
|
|
latest = etpConst['systemroot']+"/usr/bin/"+latest
|
|
filepath = os.path.dirname(latest)+"/python"
|
|
sympath = os.path.basename(latest)
|
|
if os.path.isfile(latest):
|
|
try:
|
|
if os.path.lexists(filepath):
|
|
os.remove(filepath)
|
|
os.symlink(sympath,filepath)
|
|
except OSError:
|
|
pass
|
|
|
|
return 0
|
|
|
|
'''
|
|
@description: update /usr/bin/lemon symlink
|
|
@output: returns int() as exit status
|
|
'''
|
|
def sqlite_update_symlink():
|
|
bins = [x for x in os.listdir("/usr/bin") if x.startswith("lemon-")]
|
|
if bins:
|
|
bins.sort()
|
|
latest = bins[-1]
|
|
latest = etpConst['systemroot']+"/usr/bin/"+latest
|
|
|
|
filepath = os.path.dirname(latest)+"/lemon"
|
|
sympath = os.path.basename(latest)
|
|
if os.path.isfile(latest):
|
|
try:
|
|
if os.path.lexists(filepath):
|
|
os.remove(filepath)
|
|
os.symlink(sympath,filepath)
|
|
except OSError:
|
|
pass
|
|
|
|
return 0
|
|
|
|
'''
|
|
@description: shuts down selected init script, and remove from runlevel
|
|
@output: returns int() as exit status
|
|
'''
|
|
def initdeactivate(item, running, scheduled):
|
|
|
|
if not etpConst['systemroot']:
|
|
myroot = "/"
|
|
if (running):
|
|
os.system(item+' stop --quiet')
|
|
else:
|
|
myroot = etpConst['systemroot']+"/"
|
|
|
|
if (scheduled):
|
|
os.system('ROOT="'+myroot+'" rc-update del '+os.path.basename(item))
|
|
|
|
return 0
|
|
|
|
'''
|
|
@description: append kernel entry to grub.conf
|
|
@output: returns int() as exit status
|
|
'''
|
|
def configure_boot_grub(kernel,initramfs):
|
|
|
|
if not os.path.isdir(etpConst['systemroot']+"/boot/grub"):
|
|
os.makedirs(etpConst['systemroot']+"/boot/grub")
|
|
if os.path.isfile(etpConst['systemroot']+"/boot/grub/grub.conf"):
|
|
# open in append
|
|
grub = open(etpConst['systemroot']+"/boot/grub/grub.conf","aw")
|
|
# get boot dev
|
|
boot_dev = get_grub_boot_dev()
|
|
# test if entry has been already added
|
|
grubtest = open(etpConst['systemroot']+"/boot/grub/grub.conf","r")
|
|
content = grubtest.readlines()
|
|
content = entropyTools.listToUtf8(content)
|
|
for line in content:
|
|
try: # handle stupidly encoded text
|
|
if line.find("title="+etpConst['systemname']+" ("+os.path.basename(kernel)+")\n") != -1:
|
|
grubtest.close()
|
|
return
|
|
except UnicodeDecodeError:
|
|
continue
|
|
else:
|
|
# create
|
|
boot_dev = "(hd0,0)"
|
|
grub = open(etpConst['systemroot']+"/boot/grub/grub.conf","w")
|
|
# write header - guess (hd0,0)... since it is weird having a running system without a bootloader, at least, grub.
|
|
grub_header = '''
|
|
default=0
|
|
timeout=10
|
|
'''
|
|
grub.write(grub_header)
|
|
cmdline = ' '
|
|
if os.path.isfile("/proc/cmdline"):
|
|
f = open("/proc/cmdline","r")
|
|
cmdline = " "+f.readline().strip()
|
|
params = cmdline.split()
|
|
if "dolvm" not in params: # support new kernels >= 2.6.23
|
|
cmdline += " dolvm "
|
|
f.close()
|
|
grub.write("title="+etpConst['systemname']+" ("+os.path.basename(kernel)+")\n")
|
|
grub.write("\troot "+boot_dev+"\n")
|
|
grub.write("\tkernel "+kernel+cmdline+"\n")
|
|
if initramfs:
|
|
grub.write("\tinitrd "+initramfs+"\n")
|
|
grub.write("\n")
|
|
grub.flush()
|
|
grub.close()
|
|
|
|
def remove_boot_grub(kernel,initramfs):
|
|
if os.path.isdir(etpConst['systemroot']+"/boot/grub") and os.path.isfile(etpConst['systemroot']+"/boot/grub/grub.conf"):
|
|
f = open(etpConst['systemroot']+"/boot/grub/grub.conf","r")
|
|
grub_conf = f.readlines()
|
|
grub_conf = entropyTools.listToUtf8(grub_conf)
|
|
# validate file encodings - damn what a crap
|
|
kernel, initramfs = entropyTools.listToUtf8([kernel,initramfs])
|
|
kernelname = os.path.basename(kernel)
|
|
new_conf = []
|
|
found = False
|
|
for count in range(len(grub_conf)):
|
|
line = grub_conf[count].strip()
|
|
if (line.find(kernelname) != -1) or (line.find(kernelname) != -1):
|
|
found = True
|
|
# remove previous content up to title
|
|
rlines = 0
|
|
for x in range(len(new_conf))[::-1]:
|
|
rlines += 1
|
|
if new_conf[x].strip().startswith("title"):
|
|
break
|
|
new_conf = new_conf[::-1][rlines:][::-1]
|
|
if (found):
|
|
# check if the parameter belongs to title or it is something else
|
|
try:
|
|
line = grub_conf[count].strip().split()[0]
|
|
except IndexError: # in case of weird stuff (happened...)
|
|
new_conf.append(grub_conf[count])
|
|
continue
|
|
if line: # skip empty lines
|
|
if line in ["root","kernel","initrd","hide","unhide","chainloader","makeactive","rootnoverify"]:
|
|
# skip write
|
|
continue
|
|
else:
|
|
# skip completed
|
|
found = False
|
|
new_conf.append(grub_conf[count])
|
|
f = open(etpConst['systemroot']+"/boot/grub/grub.conf","w")
|
|
f.writelines(new_conf)
|
|
f.flush()
|
|
f.close()
|
|
|
|
def get_grub_boot_dev():
|
|
if etpConst['systemroot']:
|
|
return "(hd0,0)"
|
|
import re
|
|
df_avail = os.system("which df &> /dev/null")
|
|
if df_avail != 0:
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("cannot find df!! Cannot properly configure kernel! Defaulting to (hd0,0)"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return "(hd0,0)"
|
|
grub_avail = os.system("which grub &> /dev/null")
|
|
if grub_avail != 0:
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("cannot find grub!! Cannot properly configure kernel! Defaulting to (hd0,0)"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return "(hd0,0)"
|
|
|
|
gboot = getoutput("df /boot").split("\n")[-1].split()[0]
|
|
if gboot.startswith("/dev/"):
|
|
# it's ok - handle /dev/md
|
|
if gboot.startswith("/dev/md"):
|
|
md = os.path.basename(gboot)
|
|
if not md.startswith("md"):
|
|
md = "md"+md
|
|
f = open("/proc/mdstat","r")
|
|
mdstat = f.readlines()
|
|
mdstat = [x for x in mdstat if x.startswith(md)]
|
|
f.close()
|
|
if mdstat:
|
|
mdstat = mdstat[0].strip().split()
|
|
mddevs = []
|
|
for x in mdstat:
|
|
if x.startswith("sd"):
|
|
mddevs.append(x[:-3])
|
|
mddevs.sort()
|
|
if mddevs:
|
|
gboot = "/dev/"+mddevs[0]
|
|
else:
|
|
gboot = "/dev/sda1"
|
|
else:
|
|
gboot = "/dev/sda1"
|
|
# get disk
|
|
match = re.subn("[0-9]","",gboot)
|
|
gdisk = match[0]
|
|
match = re.subn("[a-z/]","",gboot)
|
|
gpartnum = str(int(match[0])-1)
|
|
# now match with grub
|
|
device_map = etpConst['packagestmpdir']+"/grub.map"
|
|
if os.path.isfile(device_map):
|
|
os.remove(device_map)
|
|
# generate device.map
|
|
os.system('echo "quit" | grub --device-map='+device_map+' --no-floppy --batch &> /dev/null')
|
|
if os.path.isfile(device_map):
|
|
f = open(device_map,"r")
|
|
device_map_file = f.readlines()
|
|
f.close()
|
|
grub_dev = [x for x in device_map_file if (x.find(gdisk) != -1)]
|
|
if grub_dev:
|
|
grub_disk = grub_dev[0].strip().split()[0]
|
|
grub_dev = grub_disk[:-1]+","+gpartnum+")"
|
|
return grub_dev
|
|
else:
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("cannot match grub device with linux one!! Cannot properly configure kernel! Defaulting to (hd0,0)"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return "(hd0,0)"
|
|
else:
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("cannot find generated device.map!! Cannot properly configure kernel! Defaulting to (hd0,0)"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return "(hd0,0)"
|
|
else:
|
|
Equo.updateProgress(
|
|
bold(" QA Warning: ")+brown("cannot run df /boot!! Cannot properly configure kernel! Defaulting to (hd0,0)"),
|
|
importance = 0,
|
|
header = red(" ##")
|
|
)
|
|
return "(hd0,0)"
|