Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 1 | // 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 | |
| 19 | using dev_install::DevInstall; |
| 20 | |
| 21 | int 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 Frysinger | fdfc166 | 2020-04-28 04:22:36 -0400 | [diff] [blame] | 32 | DEFINE_uint32(jobs, 0, "How many install jobs to run in parallel"); |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 33 | |
| 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 Frysinger | 58c4fc9 | 2019-09-11 21:55:25 -0400 | [diff] [blame] | 40 | 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 Frysinger | 69c167f | 2019-02-24 05:14:57 -0500 | [diff] [blame] | 46 | if (FLAGS_uninstall && FLAGS_reinstall) { |
| 47 | LOG(ERROR) << "--reinstall & --uninstall may not be used together"; |
| 48 | return EXIT_FAILURE; |
| 49 | } |
| 50 | |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 51 | 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 Frysinger | fdfc166 | 2020-04-28 04:22:36 -0400 | [diff] [blame] | 57 | FLAGS_uninstall, FLAGS_yes, FLAGS_only_bootstrap, |
| 58 | FLAGS_jobs); |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 59 | return dev_install.Run(); |
| 60 | } |