mirror of
https://github.com/dathere/ckan-devstaller.git
synced 2025-11-09 13:39:49 +00:00
feat: add CLI config options and refactor steps
This commit is contained in:
parent
3727d60786
commit
25bb877fb6
2 changed files with 180 additions and 109 deletions
117
src/steps.rs
117
src/steps.rs
|
|
@ -1,4 +1,6 @@
|
|||
use crate::styles::{highlighted_text, important_text};
|
||||
use crate::styles::{highlighted_text, important_text, step_text, success_text};
|
||||
use anyhow::Result;
|
||||
use xshell::{Shell, cmd};
|
||||
|
||||
pub fn step_intro() {
|
||||
println!("Welcome to the ckan-devstaller!");
|
||||
|
|
@ -17,3 +19,116 @@ pub fn step_intro() {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
pub fn step_package_updates(step_prefix: String, sh: &Shell) -> Result<()> {
|
||||
println!(
|
||||
"\n{} Running {} and {}...",
|
||||
step_text(step_prefix.as_str()),
|
||||
highlighted_text("sudo apt update -y"),
|
||||
highlighted_text("sudo apt upgrade -y")
|
||||
);
|
||||
println!(
|
||||
"{}",
|
||||
important_text("You may need to provide your sudo password.")
|
||||
);
|
||||
cmd!(sh, "sudo apt update -y").run()?;
|
||||
// Ignoring xrdp error with .ignore_status() for now
|
||||
cmd!(sh, "sudo apt upgrade -y").ignore_status().run()?;
|
||||
println!(
|
||||
"{}",
|
||||
success_text(
|
||||
format!("{step_prefix} Successfully ran update and upgrade commands.").as_str()
|
||||
)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn step_install_curl(step_prefix: String, sh: &Shell) -> Result<()> {
|
||||
println!(
|
||||
"\n{} Installing {}...",
|
||||
step_text("2."),
|
||||
highlighted_text("curl")
|
||||
);
|
||||
cmd!(sh, "sudo apt install curl -y").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
success_text(format!("{step_prefix} Successfully installed curl.").as_str())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn step_install_openssh(step_prefix: String, sh: &Shell) -> Result<()> {
|
||||
println!(
|
||||
"\n{} Installing openssh-server...",
|
||||
step_text(step_prefix.as_str())
|
||||
);
|
||||
cmd!(sh, "sudo apt install openssh-server -y").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
success_text(format!("{step_prefix} Successfully installed openssh-server.").as_str())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn step_install_docker(step_prefix: String, sh: &Shell, username: String) -> Result<()> {
|
||||
let dpkg_l_output = cmd!(sh, "dpkg -l").read()?;
|
||||
let has_docker = cmd!(sh, "grep docker")
|
||||
.stdin(dpkg_l_output.clone())
|
||||
.ignore_status()
|
||||
.output()?
|
||||
.status
|
||||
.success();
|
||||
if !has_docker {
|
||||
println!("{} Installing Docker...", step_text(step_prefix.as_str()),);
|
||||
cmd!(
|
||||
sh,
|
||||
"curl -fsSL https://get.docker.com -o /home/{username}/get-docker.sh"
|
||||
)
|
||||
.run()?;
|
||||
cmd!(sh, "sudo sh /home/{username}/get-docker.sh").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
success_text(format!("{step_prefix} Successfully installed Docker.").as_str())
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn step_install_ahoy(step_prefix: String, sh: &Shell, username: String) -> Result<()> {
|
||||
println!("\n{} Installing Ahoy...", step_text(step_prefix.as_str()),);
|
||||
sh.change_dir(format!("/home/{username}"));
|
||||
cmd!(sh, "sudo curl -LO https://github.com/ahoy-cli/ahoy/releases/download/v2.5.0/ahoy-bin-linux-amd64").run()?;
|
||||
cmd!(sh, "mv ./ahoy-bin-linux-amd64 ./ahoy").run()?;
|
||||
cmd!(sh, "sudo chmod +x ./ahoy").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
success_text(format!("{step_prefix} Successfully installed Ahoy.").as_str())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn step_install_and_run_ckan_compose(
|
||||
step_prefix: String,
|
||||
sh: &Shell,
|
||||
username: String,
|
||||
) -> Result<()> {
|
||||
println!(
|
||||
"\n{} Downloading, installing, and starting ckan-compose...",
|
||||
step_text(step_prefix.as_str()),
|
||||
);
|
||||
if !std::fs::exists(format!("/home/{username}/ckan-compose"))? {
|
||||
cmd!(sh, "git clone https://github.com/tino097/ckan-compose.git").run()?;
|
||||
}
|
||||
sh.change_dir(format!("/home/{username}/ckan-compose"));
|
||||
cmd!(sh, "git switch ckan-devstaller").run()?;
|
||||
let env_data = "PROJECT_NAME=ckan-devstaller-project
|
||||
DATASTORE_READONLY_PASSWORD=pass
|
||||
POSTGRES_PASSWORD=pass";
|
||||
std::fs::write(format!("/home/{username}/ckan-compose/.env"), env_data)?;
|
||||
cmd!(sh, "sudo ../ahoy up").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
success_text(format!("{step_prefix} Successfully ran ckan-compose.").as_str())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue