Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
198b6f3
Only finish in case of finish phase.
teclator Feb 3, 2025
9cad61c
Reboot when finished the auto installation
teclator Feb 3, 2025
057ec3e
Added reboot command to Agama CLI
teclator Feb 4, 2025
4ac28b3
Do not check the installer phase in the CLI
teclator Feb 5, 2025
acf17f7
Added unit test for finishing the installation
teclator Feb 5, 2025
5251347
Added changelog
teclator Feb 5, 2025
5576d46
Apply suggestions from code review
teclator Feb 5, 2025
4a19cc0
Added changes based on code review
teclator Feb 5, 2025
d2001dd
Unattended installation: allow to stop at the end
teclator Feb 13, 2025
948f058
Updated autoinstallation changelog
teclator Feb 13, 2025
8625673
Use a separate environment file
teclator Feb 13, 2025
0533571
Allow to specify the finish method
teclator Feb 17, 2025
62a2f39
Apply suggestions from code review
teclator Feb 18, 2025
1fbf200
Changes based on code review
teclator Feb 18, 2025
092a956
Write only known needed env vars.
teclator Feb 18, 2025
d4bd151
Removed leftover dbg call
teclator Feb 18, 2025
5e945f1
Rewording changelog entry
teclator Feb 18, 2025
5aa343e
Clarify stop
teclator Feb 18, 2025
775e02e
Fixed rename and doc
teclator Feb 18, 2025
46569d7
Fixed unit test
teclator Feb 18, 2025
36ef12e
Fixed openapi spec generation
teclator Feb 18, 2025
52eb8d8
Added some documentation to finish_installation
teclator Feb 19, 2025
f529719
Update Finish method doc
teclator Feb 19, 2025
e64e810
Merge branch 'master' into reboot
teclator Feb 19, 2025
8db9ff7
Modify environment file target
teclator Feb 19, 2025
ef65680
Adapted agama-auto to call agama finish with the method given
teclator Feb 19, 2025
9591f49
Fix agama-auto indentation
teclator Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions autoinstallation/bin/agama-auto
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ set -ex
# Temporarily skip the AutoYaST XML validation
export YAST_SKIP_XML_VALIDATION=1

if [ -z "$1" ]
then
url=$( grep 'agama.auto=' < /run/agama/cmdline.d/agama.conf | awk -F 'agama.auto=' '{sub(/ .*$/, "", $2); print $2}' )
if [ -z "$1" ]; then
url=$(grep 'agama.auto=' </run/agama/cmdline.d/agama.conf | awk -F 'agama.auto=' '{sub(/ .*$/, "", $2); print $2}')
else
url="$1"
fi

if [ -z "$url" ]
then
if [ -z "$url" ]; then
echo "no autoinstallation profile"
exit 0
fi

method=$(grep 'agama.finish=' </run/agama/cmdline.d/agama.conf | awk -F 'agama.finish=' '{sub(/ .*$/, "", $2); print $2}')

echo "Using the profile at $url"

case "$url" in
* )
/usr/bin/agama profile import "$url"
/usr/bin/agama install;;
*)
/usr/bin/agama profile import "$url"
/usr/bin/agama install
case "$method" in
"stop" | "halt" | "poweroff")
/usr/bin/agama finish $method
;;
*)
/usr/bin/agama finish
;;
esac
;;
esac
9 changes: 9 additions & 0 deletions autoinstallation/package/agama-auto.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Thu Feb 13 12:10:11 UTC 2025 - Knut Anderssen <kanderssen@suse.com>

- gh#agama-project/agama#1970
- Adapted agama-auto script to reboot by default once the
unattended installation is finished.
- Allow to modify the finish method through the 'agama.finish'
kernel cmdline argument.

-------------------------------------------------------------------
Fri Sep 20 11:27:29 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 2 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama.Manager1.bus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<arg name="tarball_filesystem_path" direction="out" type="s"/>
</method>
<method name="Finish">
<arg name="method" direction="in" type="s"/>
<arg name="result" direction="out" type="b"/>
</method>
<property type="aa{sv}" name="InstallationPhases" access="read"/>
<property type="u" name="CurrentInstallationPhase" access="read"/>
Expand Down
2 changes: 2 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama1.Manager.bus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<arg name="tarball_filesystem_path" direction="out" type="s"/>
</method>
<method name="Finish">
<arg name="method" direction="in" type="s"/>
<arg name="result" direction="out" type="b"/>
</method>
<property type="aa{sv}" name="InstallationPhases" access="read"/>
<property type="u" name="CurrentInstallationPhase" access="read"/>
Expand Down
21 changes: 21 additions & 0 deletions doc/dbus/org.opensuse.Agama1.Manager.doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
<arg name="tarball_filesystem_path" direction="out" type="s"/>
</method>
<method name="Finish">
<!--
Finish method.

Possible values are: "stop", "reboot", "poweroff", "halt"

* *stop*:
Finish the installation without rebooting or shutting down the machine in order
to inspect it.

* *reboot*:
Finish the installation rebooting into the installed system.

* *poweroff*:
Finish the installation calling shutdown -P

* *halt*:
Finish the installation calling shutdown -H

-->
<arg name="method" direction="in" type="s"/>
<arg name="result" direction="out" type="b"/>
</method>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@

. /lib/dracut-lib.sh

TARGET="${1:-/run/agama/cmdline.d/agama.conf}"
ENV_TARGET="${1:-/run/agama/environment.conf}"
get_agama_args() {
local _i _found
local _i _found _env

for _i in $CMDLINE; do
case $_i in
LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_*)
LIBSTORAGE_* | YAST_* | Y2* | ZYPP_*)
_found=1
_env=1
;;
agama*)
_found=1
;;
esac

if [ -n "$_found" ]; then
printf "Agama variable found ($_i)"
if ! strstr "$_i" "="; then
# Set the variable as a boolean if there is no assignation
_i="${_i}=1"
fi
echo $_i >>/etc/cmdline.d/99-agama-cmdline.conf
echo $_i >>"${TARGET}"
if [ -n "$_env" ]; then
_i=$(echo "$_i" | tr '[:lower:].-' '[:upper:]__'
echo $_i >>"${ENV_TARGET}"
fi
fi
unset _found
unset _found _env
done

return 0
Expand Down
12 changes: 12 additions & 0 deletions rust/agama-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::config::ConfigCommands;
use crate::logs::LogsCommands;
use crate::profile::ProfileCommands;
use crate::questions::QuestionsCommands;
use crate::FinishMethod;
use clap::Subcommand;

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -105,4 +106,15 @@ pub enum Commands {
/// URL pointing to file for download
url: String,
},
/// Finish the installation rebooting the system by default.
///
/// This command finishes the installation by performing a set of tasks and rebooting the system by
/// default if the installation is completed successfully.
///
/// Optionally an argument can be given for determining whether the system should be rebooted,
/// poweroff, halt or just stop at the of the installation. Values: [stop|reboot|poweroff|halt]
Finish {
#[clap(default_value = "reboot")]
method: Option<FinishMethod>,
},
}
2 changes: 2 additions & 0 deletions rust/agama-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum CliError {
Validation,
#[error("Could not start the installation")]
Installation,
#[error("The installation has not finished correctly")]
NotFinished,
#[error("Could not read the password")]
InteractivePassword(#[source] InquireError),
#[error("Could not read the password from the standard input")]
Expand Down
25 changes: 25 additions & 0 deletions rust/agama-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use agama_lib::manager::FinishMethod;
use clap::{Args, Parser};

mod auth;
Expand Down Expand Up @@ -129,6 +130,25 @@ async fn install(manager: &ManagerClient<'_>, max_attempts: u8) -> anyhow::Resul
Ok(())
}

/// Finish the instalation with the given method
///
/// Before finishing, it makes sure that the manager is idle.
///
/// * `manager`: the manager client.
async fn finish(manager: &ManagerClient<'_>, method: FinishMethod) -> anyhow::Result<()> {
if manager.is_busy().await {
println!("Agama's manager is busy. Waiting until it is ready...");
}

// Make sure that the manager is ready
manager.wait().await?;
if !manager.finish(method).await? {
eprintln!("Cannot finish the installation ({method})");
return Err(CliError::NotFinished)?;
}
Ok(())
}

async fn show_progress() -> Result<(), ServiceError> {
// wait 1 second to give other task chance to start, so progress can display something
tokio::time::sleep(Duration::from_secs(1)).await;
Expand Down Expand Up @@ -211,6 +231,11 @@ pub async fn run_command(cli: Cli) -> Result<(), ServiceError> {
let manager = build_manager().await?;
install(&manager, 3).await?
}
Commands::Finish { method } => {
let manager = build_manager().await?;
let method = method.unwrap_or_default();
finish(&manager, method).await?;
Comment thread
teclator marked this conversation as resolved.
}
Commands::Questions(subcommand) => run_questions_cmd(client, subcommand).await?,
Commands::Logs(subcommand) => run_logs_cmd(client, subcommand).await?,
Commands::Download { url } => Transfer::get(&url, std::io::stdout())?,
Expand Down
42 changes: 39 additions & 3 deletions rust/agama-lib/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ impl TryFrom<u32> for InstallationPhase {
}
}

/// Finish method
#[derive(
Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Clone,
Copy,
strum::Display,
strum::EnumString,
utoipa::ToSchema,
)]
#[strum(serialize_all = "camelCase")]
#[serde(rename_all = "camelCase")]
pub enum FinishMethod {
// Halt the system
Halt,
// Reboots the system
Reboot,
// Do nothing at the end of the installation
Stop,
Comment thread
teclator marked this conversation as resolved.
// Poweroff the system
Poweroff,
}

impl Default for FinishMethod {
fn default() -> Self {
Self::Reboot
}
}

impl<'a> ManagerClient<'a> {
pub async fn new(connection: Connection) -> zbus::Result<ManagerClient<'a>> {
Ok(Self {
Expand Down Expand Up @@ -116,9 +148,13 @@ impl<'a> ManagerClient<'a> {
Ok(self.manager_proxy.commit().await?)
}

/// Executes the after installation tasks.
pub async fn finish(&self) -> Result<(), ServiceError> {
Ok(self.manager_proxy.finish().await?)
/// Executes the after installation tasks finishing with the method given or rebooting the
/// system by default.
pub async fn finish(&self, method: FinishMethod) -> Result<bool, ServiceError> {
Ok(self
.manager_proxy
.finish(&method.to_string().as_str())
.await?)
}

/// Determines whether it is possible to start the installation.
Expand Down
4 changes: 1 addition & 3 deletions rust/agama-lib/src/product/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use std::collections::HashMap;
use std::str::FromStr;

use crate::dbus::{get_optional_property, get_property};
use crate::error::ServiceError;
use crate::software::proxies::SoftwareProductProxy;
use serde::Serialize;
use std::collections::HashMap;
use zbus::Connection;

use super::proxies::RegistrationProxy;
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/proxies/manager1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait Manager1 {
fn commit(&self) -> zbus::Result<()>;

/// Finish method
fn finish(&self) -> zbus::Result<()>;
fn finish(&self, method: &str) -> zbus::Result<bool>;

/// Probe method
fn probe(&self) -> zbus::Result<()>;
Expand Down
18 changes: 12 additions & 6 deletions rust/agama-server/src/manager/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use agama_lib::{
error::ServiceError,
logs,
manager::{InstallationPhase, InstallerStatus, ManagerClient},
manager::{FinishMethod, InstallationPhase, InstallerStatus, ManagerClient},
proxies::Manager1Proxy,
};
use axum::{
Expand Down Expand Up @@ -173,15 +173,21 @@ async fn install_action(State(state): State<ManagerState<'_>>) -> Result<(), Err
/// Executes the post installation tasks (e.g., rebooting the system).
#[utoipa::path(
post,
path = "/install",
path = "/finish",
context_path = "/api/manager",
responses(
(status = 200, description = "The installation tasks are executed.")
(status = 200, description = "The installation tasks are executed.", body = Option<FinishMethod>)
)
)]
async fn finish_action(State(state): State<ManagerState<'_>>) -> Result<(), Error> {
state.manager.finish().await?;
Ok(())
async fn finish_action(
State(state): State<ManagerState<'_>>,
method: Option<Json<FinishMethod>>,
) -> Result<Json<bool>, Error> {
let method = match method {
Some(Json(method)) => method,
_ => FinishMethod::default(),
};
Ok(Json(state.manager.finish(method).await?))
}

/// Returns the manager status.
Expand Down
1 change: 1 addition & 0 deletions rust/agama-server/src/web/docs/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl ApiDocBuilder for ManagerApiDocBuilder {
ComponentsBuilder::new()
.schema_from::<agama_lib::manager::InstallationPhase>()
.schema_from::<agama_lib::manager::InstallerStatus>()
.schema_from::<agama_lib::manager::FinishMethod>()
.schema_from::<agama_lib::logs::LogsLists>()
.build()
}
Expand Down
5 changes: 5 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Mon Feb 17 17:18:35 UTC 2025 - Knut Anderssen <kanderssen@suse.com>

- Added reboot command to the CLI (gh#agama-project/agama#1970)

-------------------------------------------------------------------
Fri Feb 14 17:00:33 UTC 2025 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion rust/share/agama-web-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ After=network-online.target agama.service agama-hostname.service
BindsTo=agama.service

[Service]
EnvironmentFile=-/etc/agama.d/cmdline.conf
EnvironmentFile=-/run/agama/environment.conf
Environment="AGAMA_LOG=debug,zbus=info"
Type=notify
ExecStart=/usr/bin/agama-web-server serve --address :::80 --address2 :::443
Expand Down
9 changes: 6 additions & 3 deletions service/lib/agama/dbus/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def initialize(backend, logger)
dbus_method(:Commit, "") { install_phase }
dbus_method(:CanInstall, "out result:b") { can_install? }
dbus_method(:CollectLogs, "out tarball_filesystem_path:s") { collect_logs }
dbus_method(:Finish, "") { finish_phase }
dbus_method(:Finish, "in method:s, out result:b") { |m| finish_phase(m) }
Comment thread
teclator marked this conversation as resolved.
dbus_reader :installation_phases, "aa{sv}"
dbus_reader :current_installation_phase, "u"
dbus_reader :iguana_backend, "b"
Expand Down Expand Up @@ -101,8 +101,11 @@ def collect_logs
end

# Last action for the installer
def finish_phase
backend.finish_installation
#
# @param method [String]
# @return [Boolean]
def finish_phase(method)
backend.finish_installation(method)
end

# Description of all possible installation phase values
Expand Down
Loading