prepare.rs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. use easy_repl::{command, CommandStatus, Repl};
  2. use crate::{cfg};
  3. use crate::op::{makesure, once};
  4. pub fn prepare_view() {
  5. let repl_bresult = Repl::builder()
  6. .description("rumia-cli system view: /prepare")
  7. .prompt("[ rumia-cli: /prepare ] ")
  8. .add("checklist", command! {
  9. "print a checklist for prepare sequence",
  10. () => || {
  11. println!("Prepare Sequence:\n\
  12. sysfs-mount\n\
  13. proc-mount\n\
  14. bootfs-mount\n\
  15. cfg-phase2-load\n\
  16. initrd-env-load\n\
  17. run-mount-from-cfg\
  18. ");
  19. Ok(CommandStatus::Done)
  20. }
  21. })
  22. .add("bootfs-mount", command! {
  23. "mount /boot",
  24. () => || {
  25. makesure::mkdir_p("/boot");
  26. once::mount_bootfs();
  27. Ok(CommandStatus::Done)
  28. }
  29. })
  30. .add("cfg-phase2-load", command! {
  31. "load rumia config phase 2",
  32. () => || {
  33. cfg::load_phase2();
  34. Ok(CommandStatus::Done)
  35. }
  36. })
  37. .add("initrd-env-load", command! {
  38. "load rumia config phase 2",
  39. () => || {
  40. makesure::export_initrd_env_from_cfg();
  41. Ok(CommandStatus::Done)
  42. }
  43. })
  44. .add("env-load", command! {
  45. "load rumia config phase 2",
  46. () => || {
  47. makesure::export_env_from_cfg();
  48. Ok(CommandStatus::Done)
  49. }
  50. })
  51. .add("run-mount-cli", command! {
  52. "mount '/run' with given option",
  53. (option: String) => |option:String| {
  54. makesure::mkdir_p("/run");
  55. once::mount_runfs(option.as_str());
  56. makesure::mkdir_p_with_mode("/run/initramfs", 0o755);
  57. Ok(CommandStatus::Done)
  58. }
  59. })
  60. .add("run-mount-from-cfg", command! {
  61. "mount '/run' with config",
  62. () => || {
  63. makesure::mkdir_p("/run");
  64. once::mount_runfs_from_cfg();
  65. makesure::mkdir_p_with_mode("/run/initramfs", 0o755);
  66. Ok(CommandStatus::Done)
  67. }
  68. })
  69. .build();
  70. let mut repl = match repl_bresult {
  71. Ok(t) => t,
  72. Err(err) => {
  73. println!("[ERROR] fatal error when initializing this view: {:?}", err);
  74. return;
  75. }
  76. };
  77. let repl_run_result = repl.run();
  78. match repl_run_result {
  79. Ok(_) => {}
  80. Err(err) => {
  81. println!("[ERROR] this view crash by error: {:?}", err);
  82. println!("back to parent view...");
  83. }
  84. };
  85. }