feat: implemented the whole process
This commit is contained in:
parent
4bd99c44ec
commit
e5cbd9f9e5
9 changed files with 64 additions and 25 deletions
|
@ -13,3 +13,4 @@ serde = { version = "1.0.171", features = ["derive"] }
|
||||||
regex = "1.9.1"
|
regex = "1.9.1"
|
||||||
reqwest = { version = "0.11.18", features = ["blocking"] }
|
reqwest = { version = "0.11.18", features = ["blocking"] }
|
||||||
uuid = { version = "1.4.0", features = ["serde", "v4"] }
|
uuid = { version = "1.4.0", features = ["serde", "v4"] }
|
||||||
|
tar = "0.4.39"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Strap,
|
Strap,
|
||||||
Unpack,
|
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +7,6 @@ impl From<String> for Command {
|
||||||
fn from(value: String) -> Self {
|
fn from(value: String) -> Self {
|
||||||
match value.to_lowercase().as_str() {
|
match value.to_lowercase().as_str() {
|
||||||
"strap" => Command::Strap,
|
"strap" => Command::Strap,
|
||||||
"unpack" => Command::Unpack,
|
|
||||||
_ => Command::None,
|
_ => Command::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::env::temp_dir;
|
use std::env::temp_dir;
|
||||||
use std::fs::{create_dir_all, File, remove_dir_all};
|
use std::fs::{create_dir_all, remove_dir_all};
|
||||||
use std::io::Write;
|
use std::io::Cursor;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -9,6 +9,7 @@ use uuid::Uuid;
|
||||||
use pkgfile::PKGFile;
|
use pkgfile::PKGFile;
|
||||||
|
|
||||||
use crate::args::{Args, Command};
|
use crate::args::{Args, Command};
|
||||||
|
use crate::prelude::run_bootstrap;
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
mod prelude;
|
mod prelude;
|
||||||
|
@ -67,27 +68,25 @@ fn main() {
|
||||||
create_dir_all(&tmp_dir)
|
create_dir_all(&tmp_dir)
|
||||||
.expect("Could not create tmp dir.");
|
.expect("Could not create tmp dir.");
|
||||||
|
|
||||||
|
println!("** extracting pkgtar...");
|
||||||
{
|
{
|
||||||
println!("** writing tar to tmp file...");
|
let mut archive = tar::Archive::new(Cursor::new(pkg.data));
|
||||||
let mut file = File::create(format!("{}/pkgtar", tmp_dir.to_str().unwrap_or("/tmp")))
|
archive.unpack(format!("{}/contents", &tmp_dir.to_str().unwrap()))
|
||||||
.expect("Could not create tmp pkgtar file");
|
.expect("Could not extract archive");
|
||||||
|
|
||||||
file.write(&pkg.data)
|
|
||||||
.expect("Could not write pkgtar to tmp file");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
env::set_current_dir(format!("{}/contents", &tmp_dir.to_str().unwrap()))
|
||||||
|
.expect("could not enter tmp dir");
|
||||||
|
|
||||||
// TODO: untar
|
println!("** running bootstrap commands...");
|
||||||
// TODO: cd into pkg
|
let res_bootstrap = run_bootstrap(mani);
|
||||||
// TODO: run bootstrap commands
|
|
||||||
|
|
||||||
println!("** removing temporary directory...");
|
println!("** removing temporary directory...");
|
||||||
remove_dir_all(&tmp_dir)
|
remove_dir_all(&tmp_dir)
|
||||||
.expect(&*format!("Could not remove tmp dir: {}", &tmp_dir.to_str().unwrap()));
|
.expect(&*format!("Could not remove tmp dir: {}", &tmp_dir.to_str().unwrap()));
|
||||||
|
exit(if res_bootstrap { println!("!! bootstrap success"); 0 } else { 1 })
|
||||||
}
|
}
|
||||||
Command::Unpack => {}
|
|
||||||
_ => {
|
_ => {
|
||||||
println!("Unsupported command, allowed commands: strap/unpack.");
|
println!("Unsupported command, allowed commands: strap.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ pub struct PKGR {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Bootstrap {
|
pub struct Bootstrap {
|
||||||
check_installed_commands: Vec<String>,
|
pub check_installed_commands: Vec<String>,
|
||||||
commands: Vec<String>
|
pub commands: Vec<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -33,3 +33,34 @@ pub fn mani_from_str(s: &str) -> Manifest<Option<PKGR>> {
|
||||||
pkgr: bmani.pkgr
|
pkgr: bmani.pkgr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn run_bootstrap(mani: Manifest<Option<PKGR>>) -> bool {
|
||||||
|
if let Some(pkgr) = mani.pkgr {
|
||||||
|
if let Some(bootstrap) = pkgr.bootstrap {
|
||||||
|
fn run_command<S: Into<String>>(s: S) -> i32 {
|
||||||
|
std::process::Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(s.into())
|
||||||
|
.spawn().expect("Could not spawn process.")
|
||||||
|
.wait().expect("Could not wait for process.")
|
||||||
|
.code().expect("Could not fetch exit code.")
|
||||||
|
}
|
||||||
|
|
||||||
|
for command in &bootstrap.check_installed_commands {
|
||||||
|
if run_command(command) != 0 {
|
||||||
|
println!("!! Command failed: {}", command);
|
||||||
|
println!("!! Already installed.");
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for command in &bootstrap.commands {
|
||||||
|
if run_command(command) != 0 {
|
||||||
|
println!("!! Command failed: {}", command);
|
||||||
|
println!("!! Bootstrap failed!!!");
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
14
package.toml
14
package.toml
|
@ -78,8 +78,8 @@ root = "/root" #*
|
||||||
# After the install script the build directory will be deleted and an CTREE (changed tree) will be generated.
|
# After the install script the build directory will be deleted and an CTREE (changed tree) will be generated.
|
||||||
# Then the CTREE will be used to copy the files over.
|
# Then the CTREE will be used to copy the files over.
|
||||||
[build]
|
[build]
|
||||||
build_script = "/scripts/build" # relative to pkg
|
build_script = "scripts/build" # relative to pkg
|
||||||
install_script = "/scripts/install" # relative to pkg
|
install_script = "scripts/install" # relative to pkg
|
||||||
|
|
||||||
[build.dependencies]
|
[build.dependencies]
|
||||||
base = "latest,stable" # selected by default
|
base = "latest,stable" # selected by default
|
||||||
|
@ -95,11 +95,13 @@ base = "latest,stable" # selected by default
|
||||||
# and only 1 release channel for pkgr
|
# and only 1 release channel for pkgr
|
||||||
[pkgr.bootstrap]
|
[pkgr.bootstrap]
|
||||||
## any non-zero = installed
|
## any non-zero = installed
|
||||||
check_installed_commands = [ "/scripts/check_installed" ]
|
check_installed_commands = [
|
||||||
|
"sh scripts/check_installed"
|
||||||
|
]
|
||||||
|
|
||||||
# any non-zero = fail
|
# any non-zero = fail
|
||||||
commands = [
|
commands = [
|
||||||
"/scripts/bootstrap/download_latest @version /tmp/pkgr.pkg",
|
"sh scripts/bootstrap/download_latest @version /tmp/pkgr.pkg",
|
||||||
"/scripts/bootstrap/dirty_install /tmp/pkgr.pkg",
|
"sh scripts/bootstrap/dirty_install /tmp/pkgr.pkg",
|
||||||
"/scripts/bootstrap/check_install"
|
"sh scripts/check_installed"
|
||||||
]
|
]
|
||||||
|
|
3
pkg/scripts/bootstrap/dirty_install
Normal file
3
pkg/scripts/bootstrap/dirty_install
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
printf ""
|
|
@ -1,7 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
fetch_latest_version() {
|
fetch_latest_version() {
|
||||||
|
printf ""
|
||||||
}
|
}
|
||||||
|
|
||||||
download_file() {
|
download_file() {
|
||||||
|
printf ""
|
||||||
}
|
}
|
3
pkg/scripts/check_installed
Normal file
3
pkg/scripts/check_installed
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
printf ""
|
|
@ -13,7 +13,7 @@ impl TryFrom<Vec<u8>> for PKGFile {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| u32::from(*v))
|
.map(|v| u32::from(*v))
|
||||||
.collect();
|
.collect();
|
||||||
let manifest_size: u32 = ((header[1] << 8) | header[2]);
|
let manifest_size: u32 = (header[1] << 8) | header[2];
|
||||||
if manifest_size > value.len() as u32 {
|
if manifest_size > value.len() as u32 {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue