Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ env_logger = "0.10.0"
log = "0.4.8"
futures = "0.3.26"
clap = { version = "4.1.6", features = ["derive", "env"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }

[dependencies.matrix-sdk]
git = "https://github.com/matrix-org/matrix-rust-sdk"
ref = "e162c99"
features = ["anyhow"]
features = ["anyhow", "sso-login"]
14 changes: 10 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CLI to migrate one matrix account to a new one. Similar to [the EMS migrator][em
1. is a nice little CLI tool, based on `matrix-rust-sdk`
2. allows for restarts (refreshes at the beginning)
3. it runs the operations async and is thus a lot faster
4. SSO authentication is supported

_Note_:
It currently only migrates the rooms listing and power_levels, no user settings or profile data.
Expand All @@ -26,10 +27,15 @@ matrix-migrate

### Usage note

It requires both the user and password for the user `from` and `to` either as
command line parameters, or preferably as environment variables (`FROM_USER=`,
`FROM_PASSWORD`). It uses matrix discovery but if that doesn't work for you
you can provide custom homeservers, too.
Password authentication requires both the user and password for the user `from`
and `to` either as command line parameters, or preferably as environment
variables (`FROM_USER=`, `FROM_PASSWORD`).

If no `from` and/or `to` password provided it will try login with servers's
SSO.

It uses matrix discovery but if that doesn't work for you, you can provide
custom homeservers, too.

It will start with a full-sync of the room state, so depending on the size of
your matrix account(s), this may take a moment.
Expand Down
37 changes: 30 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Args {

/// Password of the account to migrate from
#[arg(long = "from-pw", env = "FROM_PASSWORD")]
from_user_password: String,
from_user_password: Option<String>,

/// Custom homeserver, if not defined discovery is used
#[arg(long, env = "FROM_HOMESERVER")]
Expand All @@ -34,7 +34,7 @@ struct Args {

/// Password of the account to migrate from
#[arg(long = "to-pw", env = "TO_PASSWORD")]
to_user_password: String,
to_user_password: Option<String>,

/// Custom homeserver, if not defined discovery is used
#[arg(long, env = "TO_HOMESERVER")]
Expand Down Expand Up @@ -62,10 +62,22 @@ async fn main() -> anyhow::Result<()> {

info!("Logging in {:}", args.from_user);

from_c
.login_username(args.from_user, &args.from_user_password)
.send()
.await?;
if args.from_user_password.is_none() {
info!("No password provided, trying SSO authtentication.");
from_c
.login_sso(|sso_url| async move {
info!("Open this URL in a web browser {:}", sso_url);
Ok(())
})
.initial_device_display_name("matrix-migrate")
.send()
.await?;
} else {
from_c
.login_username(args.from_user, &args.from_user_password.unwrap())
.send()
.await?;
};

let to_cb = Client::builder().user_agent("matrix-migrate/1");
let to_c = if let Some(h) = args.to_homeserver {
Expand All @@ -79,9 +91,20 @@ async fn main() -> anyhow::Result<()> {

info!("Logging in {:}", args.to_user);

to_c.login_username(args.to_user, &args.to_user_password)
if args.to_user_password.is_none() {
info!("No password provided, trying SSO authtentication.");
to_c.login_sso(|sso_url| async move {
info!("Open this URL in a web browser {:}", sso_url);
Ok(())
})
.initial_device_display_name("matrix-migrate")
.send()
.await?;
} else {
to_c.login_username(args.to_user, &args.to_user_password.unwrap())
.send()
.await?;
}

info!("All logged in. Syncing...");

Expand Down