Merge branch 'yhkylin/v101' into 'openkylin/yangtze'

Yhkylin/v101

See merge request kylinos-src/update-manager-group/kylin-system-updater!524
This commit is contained in:
网松 2022-10-31 01:14:42 +00:00
commit ba10dab2d9
8 changed files with 357 additions and 288 deletions

View File

@ -220,218 +220,221 @@ class Sqlite3Server(object):
status_cn = '失败'
changeLog = ""
# 判断更新方式
if mode == InstallBackend.MODE_INSTALL_PARTIAL: # 部分更新
pkg_adj = ""
# 判断更新包为单包或更新组
if pkg_group:
# 更新组
pkgname = pkg_group.pop(0)
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(pkgname)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkgname:
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(pkgversion)
#移除step-two标记
self._removal_of_marker()
try:
# 判断更新方式
if mode == InstallBackend.MODE_INSTALL_PARTIAL: # 部分更新
pkg_adj = ""
# 判断更新包为单包或更新组
if pkg_group:
# 更新组
pkgname = pkg_group.pop(0)
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(pkgname)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkgname:
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(pkgversion)
#移除step-two标记
self._removal_of_marker()
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(pkgname) + ".yaml")
with open(file_path, "r") as stream:
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(pkgname) + ".yaml")
with open(file_path, "r") as stream:
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
elif pkg_list:
changeLog = " "
# 单包更新 # 获取单包数据插入数据库
pkgname = pkg_list.pop(0)
for adj in adjust_pkg:
if pkgname in adj:
# 该部分升级的单包为调整版本,与候选版本不一致
pkg_adj = adj
break
if pkg_adj: # 有调整的情况
try:
pkg = self.window_main.cache[pkg_adj.split("=")[0]]
for ver in pkg.versions:
if ver.version == pkg_adj.split("=")[1]:
pkg_inst_ver = ver
break
pkgname = pkg_adj.split("=")[0]
pkgversion = str(pkg_inst_ver.source_version)
pkgdescription = str(pkg_inst_ver.description)
except Exception as e:
logging.error(_("%s could not be detected in the source because the source was changed or for other reasons."), \
str(pkgname))
logging.error(str(e))
else: # 没有调整的情况
try:
pkg = self.window_main.cache[pkgname]
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
except Exception as e:
logging.error(str(e))
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(pkgname))
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
try:
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 发送插入数据库成功的信号local_upgrade_list
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 这里也需要, 发送插入数据库成功的信号
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
elif mode == InstallBackend.MODE_INSTALL_ALL: # 系统全部升级
# # insert signal deb first
for i in pkg_list:
changeLog = ""
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
elif pkg_list:
changeLog = " "
# 单包更新 # 获取单包数据插入数据库
pkgname = pkg_list.pop(0)
for adj in adjust_pkg:
if pkgname in adj:
# 该部分升级的单包为调整版本,与候选版本不一致
pkg_adj = adj
break
if pkg_adj: # 有调整的情况
try:
pkg = self.window_main.cache[pkg_adj.split("=")[0]]
for ver in pkg.versions:
if ver.version == pkg_adj.split("=")[1]:
pkg_inst_ver = ver
break
pkgname = pkg_adj.split("=")[0]
pkgversion = str(pkg_inst_ver.source_version)
pkgdescription = str(pkg_inst_ver.description)
pkg = self.window_main.cache[i]
except Exception as e:
logging.error(_("%s could not be detected in the source because the source was changed or for other reasons."), \
str(pkgname))
logging.error(str(e))
else: # 没有调整的情况
str(i))
continue
if not pkg:
continue
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkg.name)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkg.name)})
if pkg.name in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkg.name])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
try:
pkg = self.window_main.cache[pkgname]
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(i))
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
logging.error(str(e))
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(pkgname))
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
try:
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 发送插入数据库成功的信号local_upgrade_list
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 这里也需要, 发送插入数据库成功的信号
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
elif mode == InstallBackend.MODE_INSTALL_ALL: # 系统全部升级
# # insert signal deb first
for i in pkg_list:
changeLog = ""
try:
pkg = self.window_main.cache[i]
except Exception as e:
logging.error(_("%s could not be detected in the source because the source was changed or for other reasons."), \
str(i))
continue
if not pkg:
continue
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkg.name)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkg.name)})
if pkg.name in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkg.name])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
try:
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(i))
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkg.name, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
# insert group deb next
for i in pkg_group:
# FIXME: 获取组信息
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(i)
#更新信息update-infos
UpdateInfos.update({"appname":str(i)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(i)})
if i in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][i])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
json_file = json.dumps(InstallInfos.copy())
try:
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
except:
pass
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=i, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(pkgname) + ".yaml")
with open(file_path, "r") as stream:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkg.name, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
# insert group deb next
for i in pkg_group:
# FIXME: 获取组信息
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(i)
#更新信息update-infos
UpdateInfos.update({"appname":str(i)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(i)})
if i in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][i])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
json_file = json.dumps(InstallInfos.copy())
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
try:
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkg_group:
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
except:
pass
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=i, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(i) + ".yaml")
with open(file_path, "r") as stream:
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
try:
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkg_group:
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(str(pkgversion))
#移除step-two标记
self._removal_of_marker()
elif mode == InstallBackend.MODE_INSTALL_SYSTEM: # 全盘升级
self.insert_into_updateinfo(_("Upgrade System"), "", "This is a complete system upgrade, equivalent to the implementation of apt dist-upgrade", timestr, status, "1", errstr, str("全盘升级"), status_cn, " ")
self.window_main.dbusController.UpdateSqlitSingle("Upgrade System", timestr)
# 全盘更新完成 ..判断版本号
if status == "success":
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(str(pkgversion))
self._refresh_system_version(pseudo_version=True)
#移除step-two标记
self._removal_of_marker()
elif mode == InstallBackend.MODE_INSTALL_SYSTEM: # 全盘升级
self.insert_into_updateinfo(_("Upgrade System"), "", "This is a complete system upgrade, equivalent to the implementation of apt dist-upgrade", timestr, status, "1", errstr, str("全盘升级"), status_cn, " ")
self.window_main.dbusController.UpdateSqlitSingle("Upgrade System", timestr)
# 全盘更新完成 ..判断版本号
if status == "success":
# 更新版本号
self._refresh_system_version(pseudo_version=True)
#移除step-two标记
self._removal_of_marker()
else:
logging.warning("Cache is None.")
else:
logging.warning("Cache is None.")
except Exception as e:
logging.error("record update error: %s.",str(e))
# 获取group信息
def GetGroupmsg(self, appname):

View File

@ -716,13 +716,13 @@ def get_proc_from_dbus_name(dbus_name, bus=None):
dbus_interface="org.freedesktop.DBus")
proc = psutil.Process(int(pid))
with open("/proc/%s/status" % pid) as process:
values = [v for v in process.readlines() if v.startswith("Uid:")]
uid = int(values[0].split()[1])
# with open("/proc/%s/status" % pid) as process:
# values = [v for v in process.readlines() if v.startswith("Uid:")]
# uid = int(values[0].split()[1])
#检查是否root用户执行
if uid == 0:
return "root"
# #检查是否root用户执行
# if uid == 0:
# return "root"
return proc.name()

View File

@ -64,7 +64,6 @@ class UpdateManager():
self.simulate_mode = SimulateTerminal()
self.install_mode = UpdateInstallMode(self)
self.apt_p2p_config = AptP2pConfigManager()
self.safe_manager = UpdateSafeManager()
self._reload_options_config()
self._refresh_cache_only()
@ -748,7 +747,7 @@ class UpdateManager():
logging.warning("The cache has no package named '%s', this is a virtual package...", debname)
providers = deb_cache.get_providing_packages(debname)
# hear!
if len(providers) != 1:
if len(providers) < 1:
logging.error("Can not found depend %s.", debname)
continue
depname = providers[0].name
@ -762,8 +761,9 @@ class UpdateManager():
_group_satify = True
else:
pkg = deb_cache[debname]
if (pkg.installed and apt_pkg.check_dep(pkg.installed.version, oper, ver)) or (not pkg.installed and apt_pkg.check_dep(pkg.candidate.version, oper, ver)) and _group_satify == False:
_group_satify = True
if (apt_pkg.check_dep(pkg.candidate.source_version, oper, ver)) or (pkg.installed and apt_pkg.check_dep(pkg.installed.version, oper, ver)) or (not pkg.installed and apt_pkg.check_dep(pkg.candidate.version, oper, ver)) and _group_satify == False:
# if not apt_pkg.check_dep(cand, oper, ver): #no candidate
_group_satify = True
except Exception as e:
logging.error(str(e))
if _group_satify == False and or_group not in _noSatisfyList:
@ -919,54 +919,6 @@ class SimulateTerminal():
return terminal_msg
class UpdateSafeManager():
KYSEC_STATUS = "/sys/kernel/security/kysec/status"
KYSEC_EXECTL = "/sys/kernel/security/kysec/exectl"
def __init__(self):
self.bus = dbus.SystemBus()
self.safe_status = False
self.safe_exectl = 0
self.check_status()
def check_status(self):
self._check_safe_status()
self._check_safe_exectl()
def _check_safe_status(self):
if os.path.exists(self.KYSEC_STATUS):
with open(self.KYSEC_STATUS, 'r') as f:
data = f.read()
if data != "0":
self.safe_status = True
logging.info("Safe mode is turned on...")
def _check_safe_exectl(self):
if self.safe_status == True:
if os.path.exists(self.KYSEC_EXECTL):
with open(self.KYSEC_EXECTL, 'r') as f:
data = f.read()
self.safe_exectl = int(data)
logging.info("Safe exectl is %s...",data)
def reset_safe(self):
if self.safe_status == True:
self._set_fun_status(self.safe_exectl)
def shutdown_safe(self):
if self.safe_status == True:
self._set_fun_status(0)
#设置aptdeamon的环境变量
def _set_fun_status(self,value):
try:
logging.info("Set kysec_xattr_set_func_status %s...",str(value))
obj = self.bus.get_object('com.kylin.kysec', '/xattr')
interface = dbus.Interface(obj,dbus_interface='com.kylin.kysec.xattr')
retval = interface.kysec_xattr_set_func_status(0,value,timeout=2)
return retval
except Exception as e:
logging.error(str(e))
return False
class UpdateInstallMode():
OPENKYLIN_DISTTRIBUTOR = "Openkylin"
KYLIN_DISTTRIBUTOR = "Kylin"

View File

@ -403,15 +403,15 @@ class UpdateManagerDbusController(dbus.service.Object):
os.environ["LANGUAGE"] = user_lang
self.parent.aptd_lang_switch = True
reload(enums)
purge_list = [str(pkg) for pkg in _purge_list]
sender_name = get_proc_from_dbus_name(sender)
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' DistPurgePackages Sender:%s and purge list is:%s...',sender_name,_purge_list)
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' DistPurgePackages Sender:%s and purge list is:%s...',sender_name, purge_list)
(status, details) = PolicyKit_Authority(get_source_name_from_enum(sender_name)+_(" requires authentication to uninstall software packages."), sender)
if not status:
self.PurgePackagesFinished(False,details,'')
return self.RETURN_UNKNOWN_CODE,details
purge_list = [str(pkg) for pkg in _purge_list]
#目前只有360使用这个环境变量 当其他包也使用时 可以将这个权限放开
if "360epp" in purge_list:
#需要对aptdeamon加这两个环境变量 才可以提示弹窗

View File

@ -89,21 +89,66 @@ class UpgradeStrategiesDbusController(dbus.service.Object):
if status == "enable":
with open(self.P2P_DEDAULT_PATH, 'w+') as configfile:
configfile.write("#enable=true\n")
#第一次进行检查是否已经开启
args = ["systemctl","is-enabled","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
if p.returncode != 0:
logging.info("Apt-p2p service is not runing and will be enable...")
#第二次进行重启
args = ["systemctl","enable","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
if p.returncode == 0:
logging.info("Service Enable Execute successfully")
#第三次进行重启
args = ["systemctl","restart","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
if p.returncode == 0:
logging.info("Restart Execute successfully")
return self.RETURN_SUCCESS_CODE,self.RETURN_SUCCESS_DESC
else:
logging.error(str(p.stdout))
logging.error("Failed to execute reboot")
return self.RETURN_UNKNOWN_CODE,str(p.stdout)
else:
logging.error(str(p.stdout))
logging.error("Failed to execute enable")
return self.RETURN_UNKNOWN_CODE,str(p.stdout)
else:
logging.info("Apt-p2p service has been enabled and not need to reabled...")
return self.RETURN_SUCCESS_CODE,self.RETURN_SUCCESS_DESC
elif status == "disable":
with open(self.P2P_DEDAULT_PATH, 'w+') as configfile:
configfile.write("enable=false\n")
args = ["systemctl","is-enabled","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
if p.returncode == 0:
logging.info("Apt-p2p service is runing and will be disable...")
args = ["systemctl","disable","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
if p.returncode == 0:
logging.info("Service disable Execute successfully")
args = ["systemctl","stop","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
if p.returncode == 0:
logging.info("Stop Execute successfully")
return self.RETURN_SUCCESS_CODE,self.RETURN_SUCCESS_DESC
else:
logging.error(str(p.stdout))
logging.error("Failed to execute Stop")
return self.RETURN_UNKNOWN_CODE,str(p.stdout)
else:
logging.error(str(p.stdout))
logging.error("Failed to execute disable")
return self.RETURN_UNKNOWN_CODE,str(p.stdout)
else:
logging.info("Apt-p2p service has been disabled and not need to redisabled...")
return self.RETURN_SUCCESS_CODE,self.RETURN_SUCCESS_DESC
else:
logging.waring("error: input value _status=%s",status)
args = ["systemctl","restart","apt-p2p.service"]
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
logging.info(str(p.stdout))
if p.returncode == 0:
logging.info("Execute successfully")
return self.RETURN_SUCCESS_CODE,self.RETURN_SUCCESS_DESC
else:
logging.info("Failed to execute reboot")
return self.RETURN_UNKNOWN_CODE,str(p.stdout)
else:
logging.waring("apt-p2p function is not install...")

View File

@ -24,8 +24,8 @@ from importlib import reload
# 超时检测 秒单位
UPDATER_IDLE_CHECK_INTERVAL = 5
#安装的超时检查20分钟
INSTALL_IDLE_TIMEOUT = 20 * 60
#安装的超时检查20分钟 按照5秒检查一次
INSTALL_IDLE_TIMEOUT = 4 * 60
#更新超时检查 5分钟
UPDATE_IDLE_TIMEOUT = 5 * 60
@ -63,7 +63,7 @@ class InstallBackendAptdaemon(InstallBackend):
elif self.action == self.ACTION_INSTALL or self.action == self.ACTION_INSTALL_SHUTDOWN:
#安装的超时间检查 超时解除禁止关机
self.install_timestamp = time.time()
self.install_timestamp = INSTALL_IDLE_TIMEOUT
self.check_progress = 0
GLib.timeout_add_seconds(UPDATER_IDLE_CHECK_INTERVAL,
self._check_install_inactivity)
@ -81,20 +81,19 @@ class InstallBackendAptdaemon(InstallBackend):
"""Shutdown the daemon if it has been inactive for time specified
in INSTALL_IDLE_TIMEOUT.
"""
logging.info("Checking for inactivity in Installing...")
logging.info("Checking for inactivity in Installing Time:%d...",self.install_timestamp)
if self.window_main.now_working != self.ACTION_INSTALL and self.window_main.now_working != self.ACTION_INSTALL_SHUTDOWN:
logging.info("Installing to exit and timeout check quit...")
return False
#进度不同时 更新时间戳
# 进度不同时 更新时间戳
if self.aptd_base.progress != self.check_progress:
self.check_progress = self.aptd_base.progress
self.install_timestamp = time.time()
self.install_timestamp = INSTALL_IDLE_TIMEOUT
#只有安装的时候启用 下载时候不使用
timestamp = self.install_timestamp
if (time.time() - timestamp > INSTALL_IDLE_TIMEOUT
and self.on_install_stage == True):
if (self.install_timestamp <= 0 and self.on_install_stage == True):
logging.error("Quitting due to inactivity(%s)",self.aptd_base.details)
if self.action == self.ACTION_INSTALL_SHUTDOWN:
#关机安装模式 解除禁止关机锁
@ -111,8 +110,10 @@ class InstallBackendAptdaemon(InstallBackend):
# self.window_main.dbusController.Quit(None)
return False
return True
else:
self.install_timestamp = self.install_timestamp - 1
return True
def _check_update_inactivity(self):
logging.info("Checking for inactivity in Updating...")
@ -350,11 +351,10 @@ class InstallBackendAptdaemon(InstallBackend):
self.window_main.dbusController.UpdateDetectStatusChanged(progress,status)
elif action == self.ACTION_INSTALL:
#50%时候 属于下载状态切换到安装状态的过程 下面的代码只执行一次
#Fix 取消的时候进度会直接跳到100 出现判断错误进入安装状态 所以只有在进度51 - 90 之前的一次进度进入安装态
if progress > 51 and progress < 90 and self.on_install_stage == False:
if progress >= 50 and progress < 90 and self.on_install_stage == False:
logging.info("The process is now in the installtion phase")
self.on_install_stage = True
self.window_main.safe_manager.shutdown_safe()
self.safe_manager.shutdown_safe()
self._start_install_lock(_("Kylin System Updater"))
#只处理从下载切换到安装时出现的网络问题

View File

@ -12,6 +12,7 @@ import subprocess
import traceback
import shutil
import fcntl
import dbus
import threading
from apt import Cache
from gettext import gettext as _
@ -179,6 +180,9 @@ class InstallBackend():
self.update_essential = UpdateEssentialItem(self)
if self.action == self.ACTION_INSTALL:
self.safe_manager = UpdateSafeManager()
#更新的时候此对象还未生成
if self.window_main.update_list != None:
self.upgrade_data = window_main.update_list.upgrade_meta
@ -664,7 +668,7 @@ class InstallBackend():
#升级完成后走的分支
if action == self.ACTION_INSTALL:
false_num = 0
self.window_main.safe_manager.reset_safe()
self.safe_manager.reset_safe()
self._release_install_lock()
self._send_error_code(error_code)
@ -1182,4 +1186,58 @@ class InhibitShutdownLock():
logging.error("unlock failed." + str(e))
self.pidfile.close()
self.pidfile = None
return False
return False
class UpdateSafeManager():
KYSEC_STATUS = "/sys/kernel/security/kysec/status"
KYSEC_EXECTL = "/sys/kernel/security/kysec/exectl"
KYSEC_EXECUT_CONTROL = 0
KYSEC_NETWORK_CONTROL = 1
KYSEC_SHUTDOWN_CODE = 0
def __init__(self):
self.bus = dbus.SystemBus()
self.safe_status = False
self.safe_exectl_code = self.KYSEC_SHUTDOWN_CODE
self.check_status()
def check_status(self):
self._check_safe_status()
self._check_safe_exectl()
def _check_safe_status(self):
if os.path.exists(self.KYSEC_STATUS):
with open(self.KYSEC_STATUS, 'r') as f:
data = f.read()
if data != "0":
self.safe_status = True
def _check_safe_exectl(self):
if self.safe_status == True:
if os.path.exists(self.KYSEC_EXECTL):
with open(self.KYSEC_EXECTL, 'r') as f:
data = f.read()
self.safe_exectl_code = int(data)
logging.info("Now kylin Sec has opened and exectl status:%s...",data)
def reset_safe(self):
if self.safe_status == True:
self._set_kysec_status(self.KYSEC_EXECUT_CONTROL,self.safe_exectl_code)
self._set_kysec_status(self.KYSEC_NETWORK_CONTROL,2)
def shutdown_safe(self):
if self.safe_status == True:
self._set_kysec_status(self.KYSEC_EXECUT_CONTROL,self.KYSEC_SHUTDOWN_CODE)
self._set_kysec_status(self.KYSEC_NETWORK_CONTROL,self.KYSEC_SHUTDOWN_CODE)
def _set_kysec_status(self,fun,value):
try:
obj = self.bus.get_object('com.kylin.kysec', '/xattr')
interface = dbus.Interface(obj,dbus_interface='com.kylin.kysec.xattr')
retval = interface.kysec_xattr_set_func_status(fun,value,timeout=0.5)
logging.info("Set kysec_xattr_set_func_status %s...",str(value))
return True
except Exception as e:
logging.error("Set kylin Sec Failed and fun:%d value:%d Error msg:" + str(e),fun,value)
return False

11
debian/changelog vendored
View File

@ -1,3 +1,14 @@
kylin-system-updater (2.0.5.15) v101; urgency=medium
* BUG: #140507 : 【2203自适应升级2209】2107升级到2203再由2203自适应升级至2209-RC6失败
#145229 : 【2203自适应升级2209】升级过程中出现弹窗认证
* 需求号: 无
* 其他改动说明: 无
* 其他改动影响域:系统更新
-- luoxueyi <luoxueyi@kylinos.cn> Thu, 27 Oct 2022 17:31:10 +0800
kylin-system-updater (2.0.5.14) v101; urgency=medium
* BUG: #144937 : 【2203自适应升级2209】自动更新下载报错