blob: 06a73be2ffe7b308b316c6c32d051a696b3810f0 [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#ifndef DEV_INSTALL_DEV_INSTALL_H_
6#define DEV_INSTALL_DEV_INSTALL_H_
7
Mike Frysingerb9c9f6c2019-02-24 02:32:32 -05008#include <sys/stat.h>
9
Mike Frysinger60260f62019-02-24 02:28:23 -050010#include <istream>
Mike Frysinger1dad0972019-02-23 18:36:37 -050011#include <string>
12#include <vector>
13
Mike Frysingerb9c9f6c2019-02-24 02:32:32 -050014#include <base/files/file_path.h>
Mike Frysinger1dad0972019-02-23 18:36:37 -050015#include <base/macros.h>
16
17namespace dev_install {
18
19class DevInstall {
20 public:
21 DevInstall();
Ben Chan34d14d02019-09-19 11:56:19 -070022 DevInstall(const std::string& binhost,
23 const std::string& binhost_version,
24 bool reinstall,
25 bool uninstall,
26 bool yes,
Mike Frysingerfdfc1662020-04-28 04:22:36 -040027 bool only_bootstrap,
28 uint32_t jobs);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090029 DevInstall(const DevInstall&) = delete;
30 DevInstall& operator=(const DevInstall&) = delete;
Mike Frysinger1dad0972019-02-23 18:36:37 -050031
32 // Run the dev_install routine.
33 int Run();
34
Mike Frysingeree5af6e2019-02-23 23:47:03 -050035 // Whether the system is currently in dev mode.
36 virtual bool IsDevMode() const;
37
Mike Frysinger60260f62019-02-24 02:28:23 -050038 // Prompts the user.
39 virtual bool PromptUser(std::istream& input, const std::string& prompt);
40
Mike Frysingerb9c9f6c2019-02-24 02:32:32 -050041 // 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 Frysinger3eaab632019-11-03 20:19:09 -050045 // Create a directory if it doesn't yet exist, and chmod it to 0755.
46 bool CreateMissingDirectory(const base::FilePath& dir);
47
Mike Frysinger6fc79c02019-11-04 16:35:11 -050048 // Write the data to the file.
49 bool WriteFile(const base::FilePath& file, const std::string& data);
50
Mike Frysinger69c167f2019-02-24 05:14:57 -050051 // Clear the /usr/local state.
52 virtual bool ClearStateDir(const base::FilePath& dir);
53
Mike Frysinger3d44f782019-02-25 23:17:08 -050054 // Initialize the /usr/local state.
55 virtual bool InitializeStateDir(const base::FilePath& dir);
56
Mike Frysingerb4aadcd2019-02-25 23:50:05 -050057 // Load any runtime state we'll use later on.
58 bool LoadRuntimeSettings(const base::FilePath& lsb_release);
59
Mike Frysingerbd336d22019-02-26 00:15:41 -050060 // Initialize binhost_ setting from other settings.
61 void InitializeBinhost();
62
Mike Frysingerbf36e3c2019-11-02 02:47:50 -040063 // 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 Frysinger6fc79c02019-11-04 16:35:11 -050068 // Configure the portage tooling state.
69 virtual bool ConfigurePortage();
70
Mike Frysinger2eb3afd2019-11-04 17:44:54 -050071 // Install the extra set of packages.
72 virtual bool InstallExtraPackages();
73
Mike Frysinger60260f62019-02-24 02:28:23 -050074 // Unittest helpers.
Mike Frysinger69c167f2019-02-24 05:14:57 -050075 void SetReinstallForTest(bool reinstall) { reinstall_ = reinstall; }
76 void SetUninstallForTest(bool uninstall) { uninstall_ = uninstall; }
Mike Frysinger60260f62019-02-24 02:28:23 -050077 void SetYesForTest(bool yes) { yes_ = yes; }
Mike Frysingerb9c9f6c2019-02-24 02:32:32 -050078 void SetStateDirForTest(const base::FilePath& dir) { state_dir_ = dir; }
Mike Frysingerbf36e3c2019-11-02 02:47:50 -040079 void SetBootstrapForTest(bool bootstrap) { only_bootstrap_ = bootstrap; }
Mike Frysingerb4aadcd2019-02-25 23:50:05 -050080 std::string GetDevserverUrlForTest() { return devserver_url_; }
81 std::string GetBoardForTest() { return board_; }
82 std::string GetBinhostVersionForTest() { return binhost_version_; }
Mike Frysinger60260f62019-02-24 02:28:23 -050083
Mike Frysinger1dad0972019-02-23 18:36:37 -050084 private:
85 bool reinstall_;
86 bool uninstall_;
87 bool yes_;
88 bool only_bootstrap_;
Mike Frysingerb9c9f6c2019-02-24 02:32:32 -050089 base::FilePath state_dir_;
Mike Frysinger1dad0972019-02-23 18:36:37 -050090 std::string binhost_;
91 std::string binhost_version_;
Mike Frysingerfdfc1662020-04-28 04:22:36 -040092 int jobs_;
Mike Frysingerb4aadcd2019-02-25 23:50:05 -050093 // 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 Frysinger1dad0972019-02-23 18:36:37 -050097};
98
99} // namespace dev_install
100
101#endif // DEV_INSTALL_DEV_INSTALL_H_