mirror of
https://github.com/dathere/ckan-devstaller.git
synced 2025-11-09 13:39:49 +00:00
feat: add DataStore plugin
This commit is contained in:
parent
b79fccccfb
commit
3dcfd561fa
3 changed files with 133 additions and 2 deletions
82
Cargo.lock
generated
82
Cargo.lock
generated
|
|
@ -45,10 +45,31 @@ dependencies = [
|
|||
"anyhow",
|
||||
"inquire",
|
||||
"owo-colors",
|
||||
"rust-ini",
|
||||
"xshell",
|
||||
"xshell-venv",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-random"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359"
|
||||
dependencies = [
|
||||
"const-random-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-random-macro"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.25.0"
|
||||
|
|
@ -74,6 +95,21 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "dlv-list"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f"
|
||||
dependencies = [
|
||||
"const-random",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.20"
|
||||
|
|
@ -119,6 +155,23 @@ dependencies = [
|
|||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.5.2"
|
||||
|
|
@ -214,6 +267,16 @@ version = "1.21.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "ordered-multimap"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79"
|
||||
dependencies = [
|
||||
"dlv-list",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "4.2.2"
|
||||
|
|
@ -256,6 +319,16 @@ dependencies = [
|
|||
"bitflags 2.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-ini"
|
||||
version = "0.21.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7295b7ce3bf4806b419dc3420745998b447178b7005e2011947b38fc5aa6791"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"ordered-multimap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.0.8"
|
||||
|
|
@ -339,6 +412,15 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.12.0"
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ edition = "2024"
|
|||
anyhow = "1.0.99"
|
||||
inquire = "0.7.5"
|
||||
owo-colors = { version = "4.2.2", features = ["supports-colors"] }
|
||||
rust-ini = "0.21.2"
|
||||
xshell = "0.2.7"
|
||||
xshell-venv = "1.3.0"
|
||||
|
|
|
|||
52
src/main.rs
52
src/main.rs
|
|
@ -110,7 +110,6 @@ fn main() -> Result<()> {
|
|||
"\n{} Downloading, installing, and starting ckan-compose...",
|
||||
"5.".if_supports_color(Stdout, |text| text.on_magenta().white()),
|
||||
);
|
||||
println!("{}", "You may need to provide an arbitrary name then press ENTER to set defaults for the rest.".if_supports_color(Stdout, |text| text.on_bright_red().white()));
|
||||
sh.change_dir(format!("/home/{username}"));
|
||||
if !std::fs::exists(format!("/home/{username}/ckan-compose"))? {
|
||||
cmd!(sh, "git clone https://github.com/tino097/ckan-compose.git").run()?;
|
||||
|
|
@ -167,12 +166,61 @@ POSTGRES_PASSWORD=pass";
|
|||
"ckan -c /etc/ckan/default/ckan.ini sysadmin add {username}"
|
||||
)
|
||||
.run()?;
|
||||
cmd!(sh, "ckan -c /etc/ckan/default/ckan.ini run").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
"✅ 6. Installed CKAN 2.11.3 and started running instance."
|
||||
.if_supports_color(Stdout, |text| text.on_green().white())
|
||||
);
|
||||
|
||||
println!(
|
||||
"\n{} Enabling DataStore plugin, adding config URLs in /etc/ckan/default/ckan.ini and updating permissions...",
|
||||
"7.".if_supports_color(Stdout, |text| text.on_magenta().white()),
|
||||
);
|
||||
let mut conf = ini::Ini::load_from_file("/etc/ckan/default/ckan.ini")?;
|
||||
let app_main_section = conf.section_mut(Some("app:main")).unwrap();
|
||||
let mut ckan_plugins = app_main_section.get("ckan.plugins").unwrap().to_string();
|
||||
ckan_plugins.push_str(" datastore");
|
||||
app_main_section.insert("ckan.plugins", ckan_plugins);
|
||||
app_main_section.insert(
|
||||
"ckan.datastore.write_url",
|
||||
"postgresql://ckan_default:pass@localhost/datastore_default",
|
||||
);
|
||||
app_main_section.insert(
|
||||
"ckan.datastore.read_url",
|
||||
"postgresql://datastore_default:pass@localhost/datastore_default",
|
||||
);
|
||||
conf.write_to_file("/etc/ckan/default/ckan.ini")?;
|
||||
let postgres_container_id = cmd!(
|
||||
sh,
|
||||
"sudo docker ps -aqf name=^ckan-devstaller-project-postgres$"
|
||||
)
|
||||
.read()?;
|
||||
let set_permissions_output = cmd!(
|
||||
sh,
|
||||
"ckan -c /etc/ckan/default/ckan.ini datastore set-permissions"
|
||||
)
|
||||
.read()?;
|
||||
std::fs::write("permissions.sql", set_permissions_output)?;
|
||||
loop {
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
if std::fs::exists("permissions.sql")? {
|
||||
break
|
||||
}
|
||||
}
|
||||
sh.change_dir(format!("/home/{username}"));
|
||||
cmd!(
|
||||
sh,
|
||||
"sudo docker cp permissions.sql {postgres_container_id}:/permissions.sql"
|
||||
)
|
||||
.run()?;
|
||||
cmd!(sh, "sudo docker exec {postgres_container_id} psql -U ckan_default --set ON_ERROR_STOP=1 -f permissions.sql").run()?;
|
||||
println!(
|
||||
"{}",
|
||||
"✅ 7. Enabled DataStore plugin, set DataStore URLs in /etc/ckan/default/ckan.ini, and updated permissions."
|
||||
.if_supports_color(Stdout, |text| text.on_green().white())
|
||||
);
|
||||
|
||||
cmd!(sh, "ckan -c /etc/ckan/default/ckan.ini run").run()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue