Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust): run postscripts in a chroot #1792

Merged
merged 9 commits into from
Nov 29, 2024
25 changes: 25 additions & 0 deletions rust/agama-lib/share/examples/post-script.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
user: {
fullName: 'Jane Doe',
userName: 'jane.doe',
password: 'nots3cr3t',
},
root: {
password: 'nots3cr3t',
},
product: {
id: 'Tumbleweed',
},
scripts: {
post: [
{
name: 'enable-sshd',
chroot: true,
body: |||
#!/bin/bash
systemctl enable sshd
|||,
},
],
},
}
59 changes: 54 additions & 5 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
"description": "User-defined scripts to run before the installation starts",
"type": "array",
"items": {
"$ref": "#/$defs/script"
"$ref": "#/$defs/preScript"
}
},
"post": {
"title": "Post-installation scripts",
"description": "User-defined scripts to run after the installation finishes",
"type": "array",
"items": {
"$ref": "#/$defs/script"
"$ref": "#/$defs/postScript"
}
},
"init": {
"title": "Init scripts",
"description": "User-defined scripts to run booting the installed system",
"type": "array",
"items": {
"$ref": "#/$defs/script"
"$ref": "#/$defs/initScript"
}
}
}
Expand Down Expand Up @@ -1418,8 +1418,57 @@
"title": "Stripe size",
"$ref": "#/$defs/sizeValue"
},
"script": {
"title": "User-defined installation script",
"preScript": {
"title": "User-defined installation script that runs before the installation starts",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"description": "Script name, to be used as file name",
"type": "string"
},
"body": {
"title": "Script content",
"description": "Script content, starting with the shebang",
"type": "string"
},
"url": {
"title": "Script URL",
"description": "URL to fetch the script from"
}
},
"required": ["name"],
"oneOf": [{ "required": ["body"] }, { "required": ["url"] }]
},
"postScript": {
"title": "User-defined installation script that runs after the installation finishes",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"description": "Script name, to be used as file name",
"type": "string"
},
"body": {
"title": "Script content",
"description": "Script content, starting with the shebang",
"type": "string"
},
"url": {
"title": "Script URL",
"description": "URL to fetch the script from"
},
"chroot": {
"title": "Whether it should run in the installed system using a chroot environment",
"description": "whether to chroot to the target system (default: yes) or not",
"type": "boolean"
}
},
"required": ["name"],
"oneOf": [{ "required": ["body"] }, { "required": ["url"] }]
},
"initScript": {
"title": "User-defined installation script that runs during the first boot of the target system, once the installation is finished",
"type": "object",
"additionalProperties": false,
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/scripts/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ScriptsClient {
/// Adds a script to the given group.
///
/// * `script`: script's definition.
pub async fn add_script(&self, script: &Script) -> Result<(), ServiceError> {
pub async fn add_script(&self, script: Script) -> Result<(), ServiceError> {
self.client.post_void("/scripts", &script).await
}

Expand Down
2 changes: 2 additions & 0 deletions rust/agama-lib/src/scripts/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ pub enum ScriptError {
Unreachable(#[from] TransferError),
#[error("I/O error: '{0}'")]
InputOutputError(#[from] io::Error),
#[error("Wrong script type")]
WrongScriptType,
}
Loading