blob: eb18e5369ea00d2c7b59d784f32792239c34e5af [file] [log] [blame]
Mike Frysinger1dad0972019-02-23 18:36:37 -05001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This file is kept small as it cannot be unittested (due to the main func).
6// So it should only initialie the CLI interface before calling into the
7// dedicated DevInstall class.
8
9#include "dev-install/dev_install.h"
10
11#include <unistd.h>
12
13#include <string>
14
15#include <base/logging.h>
16#include <brillo/flag_helper.h>
17#include <brillo/syslog_logging.h>
18
19using dev_install::DevInstall;
20
21int main(int argc, char* argv[]) {
22 DEFINE_string(binhost, "", "URL of the binhost that emerge will use");
23 DEFINE_string(binhost_version, "",
24 "Version number to use instead of the one in /etc/lsb-release");
25 DEFINE_bool(reinstall, false,
26 "Remove all installed packages and re-bootstrap emerge");
27 DEFINE_bool(uninstall, false, "Remove all installed packages");
28 DEFINE_bool(yes, false,
29 "Do not prompt for input -- assume yes to all responses");
30 DEFINE_bool(only_bootstrap, false,
31 "Only attempt to install the bootstrap packages");
Mike Frysingerfdfc1662020-04-28 04:22:36 -040032 DEFINE_uint32(jobs, 0, "How many install jobs to run in parallel");
Mike Frysinger1dad0972019-02-23 18:36:37 -050033
34 brillo::FlagHelper::Init(argc, argv,
35 "Chromium OS Development Image Installer");
36
37 // This tool is only run by devs, so writing to syslog doesn't make sense.
38 brillo::InitLog(brillo::kLogToStderr);
39
Mike Frysinger58c4fc92019-09-11 21:55:25 -040040 const base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
41 if (cl->GetArgs().size() > 0) {
42 LOG(ERROR) << "Unknown extra command line arguments; exiting";
43 return EXIT_FAILURE;
44 }
45
Mike Frysinger69c167f2019-02-24 05:14:57 -050046 if (FLAGS_uninstall && FLAGS_reinstall) {
47 LOG(ERROR) << "--reinstall & --uninstall may not be used together";
48 return EXIT_FAILURE;
49 }
50
Mike Frysinger1dad0972019-02-23 18:36:37 -050051 if (getuid() != 0) {
52 LOG(ERROR) << argv[0] << " must be run as root";
53 return EXIT_FAILURE;
54 }
55
56 DevInstall dev_install(FLAGS_binhost, FLAGS_binhost_version, FLAGS_reinstall,
Mike Frysingerfdfc1662020-04-28 04:22:36 -040057 FLAGS_uninstall, FLAGS_yes, FLAGS_only_bootstrap,
58 FLAGS_jobs);
Mike Frysinger1dad0972019-02-23 18:36:37 -050059 return dev_install.Run();
60}