Kylin-os-installer源码解析

Kylin-os-installer源码解析

kylin-os-installer是openkylin OS的安装器,用来把操作系统安装到设备上。本文尝试从源代码介绍这个工具的实现思路。

开发调试

编译

git clone git@gitee.com:openkylin/kylin-os-installer.git

cd kylin-os-installer
mkdir build
cd build
qmake ..
make -j8

开发模式启动

主程序入口在 src/Installer_main/main.cpp, 窗口实例化之前有一些参数配置,为了省事,可自行直接创建窗口并显示:

	  // ...
    // if(argc > 1) {
    //     if(QString(QLatin1String(argv[1])).contains("oem")) {
    //         QString strtype = "oem2";
    //         if(QString(QLatin1String(argv[2])).contains("automatic")) {
    //             w_auto = new InstallerMainWidget_auto(true);
    //             w_auto->show();
    //         } else {
    //             loadSetConfFile(strtype);
    //             w = new InstallerMainWidget;
    //             w->setInstallMode(strtype);
    //             w->show();
    //         }
    //     }
    // } else {
    //     //2021-3-29 huawei swap file swapoff
    //     KServer::KCommand::initCmd()->getInstance()->RunScripCommand("swapoff", {"-a"});
    //     KServer::KCommand::initCmd()->getInstance()->RunScripCommand("sudo", {"-u", "kylin", "gsettings", "set" ,"org.ukui.flash-disk.autoload" ,"ifautoload", "false"});
    //     QString readfile = KServer::KReadFile("/proc/cmdline");
    //     if(readfile.contains("automatic") ||
    //             readfile.contains("ple-mode") ||
    //             readfile.contains("test-mode")) {
    //         loadSetConfFile("");
    //         w_auto = new InstallerMainWidget_auto(false);
    //         w_auto->show();

    //     } else if(KServer::KReadFile("/proc/cmdline").contains("oem-config/enable=true")) {
    //         QString strtype = "oem1";
    //         loadSetConfFile(strtype);
    //         w = new InstallerMainWidget;
    //         w->setInstallMode(strtype);
    //         w->show();
    //     } else {
    //         loadSetConfFile("");
    //         w = new InstallerMainWidget;
    //         w->show();
    //         qInfo() << "Show window";
    //     }

    // }
    w = new InstallerMainWidget;
    w->show();
    // ...

源码结构

项目源码主要有三部分组成:

  1. 主窗口,相关代码在src/Installer_main
  2. 子窗口, 相关代码在 src/plugins
  3. bash脚本, 负责安装阶段的操作,代码在 scripts

核心功能实现

核心功能即OS安装操作,通过一系列bash脚本实现, 源码位于 scripts 目录。调用入口是 `z.sh`

在C++中的调用入口参考:

void CustomInstallerProcess::exec()
{
    QString error = "";
    QString output =  "";
    int exitcode = 0;
    QString ScriptPath =  KServer::GetKylinInstallPath() + "/scripts" ;
    bool isOK;
    isOK = KServer::KCommand::getInstance()->RunScripCommand("/bin/bash", {"z.sh"}, ScriptPath,  output, error, exitcode);
    if(!isOK) {
        emit signalProcessStatus(exitcode);//tr("An exception occurred during script execution!")
    } else {
        emit signalProcessStatus(exitcode);
    }
    qDebug() << "error:" << error;
}

scripts分为三个阶段:

  • prepare
  • in_chroot
  • after
阶段职责
prepare分区设置
in_chroot用户配置相关的设置
after执行部分特殊操作

在in_chroot中,脚本95install-extra-packages 会在/cdrom/.kylin-post-packages文件,并执行安装动作, /cdrom对应的是iso根目录。这为我们安装自定义包提供了一种实现方式。

启动配置

kylin-os-installer.kylin-os-installer.service中配置了kylin-os-instller的启动顺序,总的来说是在lightdm之前启动,并且要求内核启动参数要有boot-capser,服务才会启动。

如果您觉得这篇文章有帮助,麻烦点个赞支持一下~感谢各位啦。

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时光机121906

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值