precheckout installer (#21752)

* precheckout installer

* repaint

* cleanup
old-commit-hash: adb079efcd
commatwo_master
Adeeb Shihadeh 4 years ago committed by GitHub
parent 62c80f0429
commit d37a02911e
  1. 73
      selfdrive/ui/qt/setup/installer.cc
  2. 1
      selfdrive/ui/qt/setup/installer.h

@ -6,6 +6,7 @@
#include <map> #include <map>
#include <QDebug> #include <QDebug>
#include <QDir>
#include <QTimer> #include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -18,6 +19,10 @@
#define CONTINUE_PATH "/data/continue.sh" #define CONTINUE_PATH "/data/continue.sh"
#define CACHE_PATH "/usr/comma/openpilot"
#define INSTALL_PATH "/data/openpilot"
#define TMP_INSTALL_PATH "/data/tmppilot"
bool time_valid() { bool time_valid() {
time_t rawtime; time_t rawtime;
@ -27,6 +32,10 @@ bool time_valid() {
return (1900 + sys_time->tm_year) >= 2020; return (1900 + sys_time->tm_year) >= 2020;
} }
void run(const char* cmd) {
int err = std::system(cmd);
assert(err == 0);
}
Installer::Installer(QWidget *parent) : QWidget(parent) { Installer::Installer(QWidget *parent) : QWidget(parent) {
QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *layout = new QVBoxLayout(this);
@ -53,6 +62,9 @@ Installer::Installer(QWidget *parent) : QWidget(parent) {
layout->addStretch(); layout->addStretch();
QObject::connect(&proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Installer::cloneFinished);
QObject::connect(&proc, &QProcess::readyReadStandardError, this, &Installer::readProgress);
QTimer::singleShot(100, this, &Installer::doInstall); QTimer::singleShot(100, this, &Installer::doInstall);
setStyleSheet(R"( setStyleSheet(R"(
@ -74,6 +86,7 @@ Installer::Installer(QWidget *parent) : QWidget(parent) {
void Installer::updateProgress(int percent) { void Installer::updateProgress(int percent) {
bar->setValue(percent); bar->setValue(percent);
val->setText(QString("%1%").arg(percent)); val->setText(QString("%1%").arg(percent));
repaint();
} }
void Installer::doInstall() { void Installer::doInstall() {
@ -84,20 +97,34 @@ void Installer::doInstall() {
} }
// cleanup // cleanup
int err = std::system("rm -rf /data/tmppilot /data/openpilot"); run("rm -rf " TMP_INSTALL_PATH " " INSTALL_PATH);
assert(err == 0);
// TODO: support using the dashcam cache // do the install
// do install if (QDir(CACHE_PATH).exists()) {
freshClone(); cachedFetch();
} else {
freshClone();
}
} }
void Installer::freshClone() { void Installer::freshClone() {
qDebug() << "Doing fresh clone\n"; qDebug() << "Doing fresh clone";
QObject::connect(&proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Installer::cloneFinished); proc.start("git", {"clone", "--progress", GIT_URL, "-b", BRANCH,
QObject::connect(&proc, &QProcess::readyReadStandardError, this, &Installer::readProgress); "--depth=1", "--recurse-submodules", TMP_INSTALL_PATH});
QStringList args = {"clone", "--progress", GIT_URL, "-b", BRANCH, "--depth=1", "--recurse-submodules", "/data/tmppilot"}; }
proc.start("git", args);
void Installer::cachedFetch() {
qDebug() << "Fetching with cache";
run("cp -rp " CACHE_PATH " " TMP_INSTALL_PATH);
int err = chdir(TMP_INSTALL_PATH);
assert(err == 0);
run("git remote set-branches --add origin " BRANCH);
updateProgress(10);
proc.setWorkingDirectory(TMP_INSTALL_PATH);
proc.start("git", {"fetch", "--progress", "origin", BRANCH});
} }
void Installer::readProgress() { void Installer::readProgress() {
@ -123,17 +150,22 @@ void Installer::readProgress() {
} }
void Installer::cloneFinished(int exitCode, QProcess::ExitStatus exitStatus) { void Installer::cloneFinished(int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "finished " << exitCode; qDebug() << "git finished with " << exitCode;
assert(exitCode == 0); assert(exitCode == 0);
int err; updateProgress(100);
// move into place // ensure correct branch is checked out
err = std::system("mv /data/tmppilot /data/openpilot"); int err = chdir(TMP_INSTALL_PATH);
assert(err == 0); assert(err == 0);
run("git checkout " BRANCH);
run("git reset --hard origin/" BRANCH);
// move into place
run("mv " TMP_INSTALL_PATH " " INSTALL_PATH);
#ifdef INTERNAL #ifdef INTERNAL
std::system("mkdir -p /data/params/d/"); run("mkdir -p /data/params/d/");
std::map<std::string, std::string> params = { std::map<std::string, std::string> params = {
{"SshEnabled", "1"}, {"SshEnabled", "1"},
@ -146,16 +178,13 @@ void Installer::cloneFinished(int exitCode, QProcess::ExitStatus exitStatus) {
param << value; param << value;
param.close(); param.close();
} }
std::system("cd /data/tmppilot && git remote set-url origin --push " GIT_SSH_URL); run("cd " INSTALL_PATH " && git remote set-url origin --push " GIT_SSH_URL);
#endif #endif
// write continue.sh // write continue.sh
err = std::system("cp /data/openpilot/installer/continue_openpilot.sh /data/continue.sh.new"); run("cp /data/openpilot/installer/continue_openpilot.sh /data/continue.sh.new");
assert(err == 0); run("chmod +x /data/continue.sh.new");
err = std::system("chmod +x /data/continue.sh.new"); run("mv /data/continue.sh.new " CONTINUE_PATH);
assert(err == 0);
std::system("mv /data/continue.sh.new " CONTINUE_PATH);
assert(err == 0);
// wait for the installed software's UI to take over // wait for the installed software's UI to take over
QTimer::singleShot(60 * 1000, &QCoreApplication::quit); QTimer::singleShot(60 * 1000, &QCoreApplication::quit);

@ -24,4 +24,5 @@ private:
void doInstall(); void doInstall();
void freshClone(); void freshClone();
void cachedFetch();
}; };

Loading…
Cancel
Save