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 | #ifndef DEV_INSTALL_DEV_INSTALL_H_ |
| 6 | #define DEV_INSTALL_DEV_INSTALL_H_ |
| 7 | |
Mike Frysinger | b9c9f6c | 2019-02-24 02:32:32 -0500 | [diff] [blame] | 8 | #include <sys/stat.h> |
| 9 | |
Mike Frysinger | 60260f6 | 2019-02-24 02:28:23 -0500 | [diff] [blame] | 10 | #include <istream> |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
Mike Frysinger | b9c9f6c | 2019-02-24 02:32:32 -0500 | [diff] [blame] | 14 | #include <base/files/file_path.h> |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 15 | #include <base/macros.h> |
| 16 | |
| 17 | namespace dev_install { |
| 18 | |
| 19 | class DevInstall { |
| 20 | public: |
| 21 | DevInstall(); |
Ben Chan | 34d14d0 | 2019-09-19 11:56:19 -0700 | [diff] [blame] | 22 | DevInstall(const std::string& binhost, |
| 23 | const std::string& binhost_version, |
| 24 | bool reinstall, |
| 25 | bool uninstall, |
| 26 | bool yes, |
Mike Frysinger | fdfc166 | 2020-04-28 04:22:36 -0400 | [diff] [blame] | 27 | bool only_bootstrap, |
| 28 | uint32_t jobs); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 29 | DevInstall(const DevInstall&) = delete; |
| 30 | DevInstall& operator=(const DevInstall&) = delete; |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 31 | |
| 32 | // Run the dev_install routine. |
| 33 | int Run(); |
| 34 | |
Mike Frysinger | ee5af6e | 2019-02-23 23:47:03 -0500 | [diff] [blame] | 35 | // Whether the system is currently in dev mode. |
| 36 | virtual bool IsDevMode() const; |
| 37 | |
Mike Frysinger | 60260f6 | 2019-02-24 02:28:23 -0500 | [diff] [blame] | 38 | // Prompts the user. |
| 39 | virtual bool PromptUser(std::istream& input, const std::string& prompt); |
| 40 | |
Mike Frysinger | b9c9f6c | 2019-02-24 02:32:32 -0500 | [diff] [blame] | 41 | // Delete a path recursively on the same mount point. |
| 42 | virtual bool DeletePath(const struct stat& base_stat, |
| 43 | const base::FilePath& dir); |
| 44 | |
Mike Frysinger | 3eaab63 | 2019-11-03 20:19:09 -0500 | [diff] [blame] | 45 | // Create a directory if it doesn't yet exist, and chmod it to 0755. |
| 46 | bool CreateMissingDirectory(const base::FilePath& dir); |
| 47 | |
Mike Frysinger | 6fc79c0 | 2019-11-04 16:35:11 -0500 | [diff] [blame] | 48 | // Write the data to the file. |
| 49 | bool WriteFile(const base::FilePath& file, const std::string& data); |
| 50 | |
Mike Frysinger | 69c167f | 2019-02-24 05:14:57 -0500 | [diff] [blame] | 51 | // Clear the /usr/local state. |
| 52 | virtual bool ClearStateDir(const base::FilePath& dir); |
| 53 | |
Mike Frysinger | 3d44f78 | 2019-02-25 23:17:08 -0500 | [diff] [blame] | 54 | // Initialize the /usr/local state. |
| 55 | virtual bool InitializeStateDir(const base::FilePath& dir); |
| 56 | |
Mike Frysinger | b4aadcd | 2019-02-25 23:50:05 -0500 | [diff] [blame] | 57 | // Load any runtime state we'll use later on. |
| 58 | bool LoadRuntimeSettings(const base::FilePath& lsb_release); |
| 59 | |
Mike Frysinger | bd336d2 | 2019-02-26 00:15:41 -0500 | [diff] [blame] | 60 | // Initialize binhost_ setting from other settings. |
| 61 | void InitializeBinhost(); |
| 62 | |
Mike Frysinger | bf36e3c | 2019-11-02 02:47:50 -0400 | [diff] [blame] | 63 | // Download & manually install the bootstrap packages. |
| 64 | virtual bool DownloadAndInstallBootstrapPackage(const std::string& package); |
| 65 | virtual bool DownloadAndInstallBootstrapPackages( |
| 66 | const base::FilePath& listing); |
| 67 | |
Mike Frysinger | 6fc79c0 | 2019-11-04 16:35:11 -0500 | [diff] [blame] | 68 | // Configure the portage tooling state. |
| 69 | virtual bool ConfigurePortage(); |
| 70 | |
Mike Frysinger | 2eb3afd | 2019-11-04 17:44:54 -0500 | [diff] [blame] | 71 | // Install the extra set of packages. |
| 72 | virtual bool InstallExtraPackages(); |
| 73 | |
Mike Frysinger | 60260f6 | 2019-02-24 02:28:23 -0500 | [diff] [blame] | 74 | // Unittest helpers. |
Mike Frysinger | 69c167f | 2019-02-24 05:14:57 -0500 | [diff] [blame] | 75 | void SetReinstallForTest(bool reinstall) { reinstall_ = reinstall; } |
| 76 | void SetUninstallForTest(bool uninstall) { uninstall_ = uninstall; } |
Mike Frysinger | 60260f6 | 2019-02-24 02:28:23 -0500 | [diff] [blame] | 77 | void SetYesForTest(bool yes) { yes_ = yes; } |
Mike Frysinger | b9c9f6c | 2019-02-24 02:32:32 -0500 | [diff] [blame] | 78 | void SetStateDirForTest(const base::FilePath& dir) { state_dir_ = dir; } |
Mike Frysinger | bf36e3c | 2019-11-02 02:47:50 -0400 | [diff] [blame] | 79 | void SetBootstrapForTest(bool bootstrap) { only_bootstrap_ = bootstrap; } |
Mike Frysinger | b4aadcd | 2019-02-25 23:50:05 -0500 | [diff] [blame] | 80 | std::string GetDevserverUrlForTest() { return devserver_url_; } |
| 81 | std::string GetBoardForTest() { return board_; } |
| 82 | std::string GetBinhostVersionForTest() { return binhost_version_; } |
Mike Frysinger | 60260f6 | 2019-02-24 02:28:23 -0500 | [diff] [blame] | 83 | |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 84 | private: |
| 85 | bool reinstall_; |
| 86 | bool uninstall_; |
| 87 | bool yes_; |
| 88 | bool only_bootstrap_; |
Mike Frysinger | b9c9f6c | 2019-02-24 02:32:32 -0500 | [diff] [blame] | 89 | base::FilePath state_dir_; |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 90 | std::string binhost_; |
| 91 | std::string binhost_version_; |
Mike Frysinger | fdfc166 | 2020-04-28 04:22:36 -0400 | [diff] [blame] | 92 | int jobs_; |
Mike Frysinger | b4aadcd | 2019-02-25 23:50:05 -0500 | [diff] [blame] | 93 | // The URL to the devserver for local developer builds. |
| 94 | std::string devserver_url_; |
| 95 | // The active board for calculating default binhost. |
| 96 | std::string board_; |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace dev_install |
| 100 | |
| 101 | #endif // DEV_INSTALL_DEV_INSTALL_H_ |