Skip to content

Commit

Permalink
Feat/import actions (#105)
Browse files Browse the repository at this point in the history
* Add action for myNode migration

* fix wildcard placement

* Update upstream to v0.16.3

* add superuser privileges to 'scp' command

* Fix quotes to allow for passwords containing special bash chars

* update permissions of mynode dir and fix scp

* add sudo permissions to cat mynode .lndpw

* remove >&2 from the mynode script commands

* revert other 2 >&2 for sshpass commands

* add raspiblitz migration action

* add back cat command to import-umbrel-5 action

* CipherSeed wip

* complete Cypher Seed property

* Remove CipherSeed debugging println

* update release notes and change bitcoin core dependency to 'opt-out'

* remove unused imports and commented out code

* remove references to 'Embassy', update BTC UDS values, and minor changes

* fix properties startup bug

* add time to sleep to fix race condition

* Update upstream to 16.4, fix 'up' migration, and fix properties cipherSeed bug

* fix cipherSeed bug

* add loop to ensure cipherseed is created

* move file_path variable to 'else' block and remove debugging println

* replace broken Start9 HQ link with link to 1ml

* Fix Aezeed spelling

* fix dependencies to allow pruned nodes contingent on version and update autoconfig

---------

Co-authored-by: gStart9 <george@start9labs.com>
  • Loading branch information
Dominion5254 and gStart9 authored Jul 13, 2023
1 parent 5bb2f93 commit f90c2fd
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 282 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lightninglabs/lnd:v0.16.2-beta
FROM lightninglabs/lnd:v0.16.4-beta

ARG ARCH
ARG PLATFORM
Expand Down
17 changes: 17 additions & 0 deletions actions/import-mynode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

set -e

cat > input.json
MYNODE_HOST=$(jq -r '.["mynode-host"]' input.json)
MYNODE_PASS=$(jq -r '.["mynode-password"]' input.json)
rm input.json
>&2 echo "Stopping MyNode Services"
sshpass -p "$MYNODE_PASS" ssh -o StrictHostKeyChecking=no admin@$MYNODE_HOST "echo \"$MYNODE_PASS\" | >&2 sudo -S /usr/bin/mynode_stop_critical_services.sh"
>&2 echo "Copying LND data"
sshpass -p "$MYNODE_PASS" ssh -o StrictHostKeyChecking=no admin@$MYNODE_HOST "echo \"$MYNODE_PASS\" | >&2 sudo -S chmod -R 755 /mnt/hdd/mynode/lnd/data"
sshpass -p "$MYNODE_PASS" scp -o StrictHostKeyChecking=no -r -v admin@$MYNODE_HOST:"/mnt/hdd/mynode/lnd/data" /root/.lnd

LN_CLI_PASS=$(sshpass -p "$MYNODE_PASS" ssh -o StrictHostKeyChecking=no admin@$MYNODE_HOST "echo \"$MYNODE_PASS\" | sudo -S cat /mnt/hdd/mynode/settings/.lndpw")
echo -n "$LN_CLI_PASS" > /root/.lnd/pwd.dat
echo '{"version":"0","message":"Successfully Imported MyNode Data","value":null,"copyable":false,"qr":false}'
17 changes: 17 additions & 0 deletions actions/import-raspiblitz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

set -e

cat > input.json
RASPIBLITZ_HOST=$(jq -r '.["raspiblitz-host"]' input.json)
RASPIBLITZ_PASS=$(jq -r '.["raspiblitz-password"]' input.json)
RASPIBLITZ_LNCLI_PASS=$(jq -r '.["raspiblitz-lncli-password"]' input.json)
rm input.json
>&2 echo "Stopping RaspiBlitz LND"
sshpass -p "$RASPIBLITZ_PASS" ssh -o StrictHostKeyChecking=no admin@$RASPIBLITZ_HOST "lncli stop"
>&2 echo "Copying LND data"
sshpass -p "$RASPIBLITZ_PASS" ssh -o StrictHostKeyChecking=no admin@$RASPIBLITZ_HOST "echo \"$RASPIBLITZ_PASS\" | >&2 sudo -S chmod -R 755 /mnt/hdd/lnd/data"
sshpass -p "$RASPIBLITZ_PASS" scp -o StrictHostKeyChecking=no -r -v admin@$RASPIBLITZ_HOST:"/mnt/hdd/lnd/data" /root/.lnd

echo -n "$RASPIBLITZ_LNCLI_PASS" > /root/.lnd/pwd.dat
echo '{"version":"0","message":"Successfully Imported RaspiBlitz Data","value":null,"copyable":false,"qr":false}'
4 changes: 2 additions & 2 deletions actions/import-umbrel-5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ UMBREL_HOST=$(jq -r '.["umbrel-host"]' input.json)
UMBREL_PASS=$(jq -r '.["umbrel-password"]' input.json)
rm input.json
>&2 echo "Stopping Umbrel Services"
sshpass -p $UMBREL_PASS ssh -o StrictHostKeyChecking=no umbrel@$UMBREL_HOST "echo $UMBREL_PASS | >&2 sudo -S /home/umbrel/umbrel/scripts/stop"
sshpass -p "$UMBREL_PASS" ssh -o StrictHostKeyChecking=no umbrel@$UMBREL_HOST "echo \"$UMBREL_PASS\" | >&2 sudo -S /home/umbrel/umbrel/scripts/stop"
>&2 echo "Copying LND Data"
sshpass -p $UMBREL_PASS scp -o StrictHostKeyChecking=no -r -v umbrel@$UMBREL_HOST:/home/umbrel/umbrel/app-data/lightning/data/lnd/* /root/.lnd
sshpass -p "$UMBREL_PASS" scp -o StrictHostKeyChecking=no -r -v umbrel@$UMBREL_HOST:/home/umbrel/umbrel/app-data/lightning/data/lnd/* /root/.lnd
echo -n 'moneyprintergobrrr' > /root/.lnd/pwd.dat
echo '{"version":"0","message":"Successfully Imported Umbrel Data","value":null,"copyable":false,"qr":false}'
4 changes: 2 additions & 2 deletions actions/import-umbrel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ UMBREL_HOST=$(jq -r '.["umbrel-host"]' input.json)
UMBREL_PASS=$(jq -r '.["umbrel-password"]' input.json)
rm input.json
>&2 echo "Stopping Umbrel Services"
sshpass -p $UMBREL_PASS ssh -o StrictHostKeyChecking=no umbrel@$UMBREL_HOST "echo $UMBREL_PASS | >&2 sudo -S /home/umbrel/umbrel/scripts/stop"
sshpass -p "$UMBREL_PASS" ssh -o StrictHostKeyChecking=no umbrel@$UMBREL_HOST "echo \"$UMBREL_PASS\" | >&2 sudo -S /home/umbrel/umbrel/scripts/stop"
>&2 echo "Copying LND Data"
sshpass -p $UMBREL_PASS scp -o StrictHostKeyChecking=no -r -v umbrel@$UMBREL_HOST:/home/umbrel/umbrel/lnd/* /root/.lnd
sshpass -p "$UMBREL_PASS" scp -o StrictHostKeyChecking=no -r -v umbrel@$UMBREL_HOST:/home/umbrel/umbrel/lnd/* /root/.lnd
echo -n 'moneyprintergobrrr' > /root/.lnd/pwd.dat
echo '{"version":"0","message":"Successfully Imported Umbrel Data","value":null,"copyable":false,"qr":false}'
126 changes: 72 additions & 54 deletions configurator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::Path;
use std::process::Command;
use std::str::FromStr;
use std::{
io::{Read, Write},
io::{self, Read, Write},
time::Duration,
};

Expand Down Expand Up @@ -119,8 +119,6 @@ enum BitcoinCoreConfig {
None,
#[serde(rename_all = "kebab-case")]
Internal { user: String, password: String },
#[serde(rename_all = "kebab-case")]
InternalProxy { user: String, password: String },
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -207,7 +205,7 @@ pub struct Property<T> {
masked: bool,
}

#[derive(serde::Deserialize)]
#[derive(serde::Deserialize, serde::Serialize)]
pub struct CipherSeedMnemonic {
cipher_seed_mnemonic: Vec<String>,
}
Expand Down Expand Up @@ -261,6 +259,14 @@ pub fn local_port_available(port: u16) -> Result<bool, anyhow::Error> {
}
}
}

fn save_to_file(cipher_seed_mnemonic: &[String], file_path: &str) -> io::Result<()> {
let mut file = File::create(file_path)?;
for (i, word) in cipher_seed_mnemonic.iter().enumerate() {
writeln!(file, "{} {}", i + 1, word)?;
}
Ok(())
}

struct WatchtowerUri {
pubkey: String,
Expand Down Expand Up @@ -326,15 +332,6 @@ fn main() -> Result<(), anyhow::Error> {
28332,
28333,
),
BitcoinCoreConfig::InternalProxy { user, password } => (
user,
password,
"btc-rpc-proxy.embassy",
8332,
"bitcoind.embassy",
28332,
28333,
),
};

let rpc_info = &BitcoindRpcInfo {
Expand Down Expand Up @@ -555,7 +552,7 @@ fn main() -> Result<(), anyhow::Error> {
None => (),
Some(backups) => {
while local_port_available(8080)? {
std::thread::sleep(Duration::from_secs(10))
std::thread::sleep(Duration::from_secs(20))
}
let mac = std::fs::read(Path::new(
"/root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
Expand Down Expand Up @@ -626,50 +623,71 @@ fn main() -> Result<(), anyhow::Error> {
},
}
} else {
println!("creating password data");

let mut cipher_seed_created = false;
let mut password_bytes = [0; 16];
let mut dev_random = File::open("/dev/random")?;
dev_random.read_exact(&mut password_bytes)?;
let output = std::process::Command::new("curl")
.arg("--no-progress-meter")
.arg("-X")
.arg("GET")
.arg("--cacert")
.arg("/root/.lnd/tls.cert")
.arg("https://lnd.embassy:8080/v1/genseed")
.arg("-d")
.arg(format!("{}", serde_json::json!({})))
.output()?;
if !output.status.success() {
eprintln!("{}", std::str::from_utf8(&output.stderr)?);
return Err(anyhow::anyhow!("Error generating seed. Exiting."));
}
let CipherSeedMnemonic {
cipher_seed_mnemonic,
} = serde_json::from_slice(&output.stdout)?;
let status = std::process::Command::new("curl")
.arg("--no-progress-meter")
.arg("-X")
.arg("POST")
.arg("--cacert")
.arg("/root/.lnd/tls.cert")
.arg("https://lnd.embassy:8080/v1/initwallet")
.arg("-d")
.arg(format!(
"{}",
serde_json::json!({
"wallet_password": base64::encode(&password_bytes),
"cipher_seed_mnemonic": cipher_seed_mnemonic,
})
))
.status()?;
if status.success() {
let mut pass_file = File::create("/root/.lnd/pwd.dat")?;
pass_file.write_all(&password_bytes)?;
} else {
return Err(anyhow::anyhow!("Error creating wallet. Exiting."));
let file_path = "/root/.lnd/start9/cipherSeedMnemonic.txt";

while !cipher_seed_created {
println!("creating password data");
dev_random.read_exact(&mut password_bytes)?;
let output = std::process::Command::new("curl")
.arg("--no-progress-meter")
.arg("-X")
.arg("GET")
.arg("--cacert")
.arg("/root/.lnd/tls.cert")
.arg("https://lnd.embassy:8080/v1/genseed")
.arg("-d")
.arg(format!("{}", serde_json::json!({})))
.output()?;
if !output.status.success() {
eprintln!("{}", std::str::from_utf8(&output.stderr)?);
return Err(anyhow::anyhow!("Error generating seed. Exiting."));
}

if let Ok(CipherSeedMnemonic {
cipher_seed_mnemonic,
}) = serde_json::from_slice(&output.stdout) {
println!("CipherSeed successfully generated");

if let Err(err) = save_to_file(&cipher_seed_mnemonic, file_path) {
eprintln!("Failed to save the CipherSeedMnemonic: {}", err);
} else {
println!("CipherSeedMnemonic saved to '{}'", file_path);
}

let status = std::process::Command::new("curl")
.arg("--no-progress-meter")
.arg("-X")
.arg("POST")
.arg("--cacert")
.arg("/root/.lnd/tls.cert")
.arg("https://lnd.embassy:8080/v1/initwallet")
.arg("-d")
.arg(format!(
"{}",
serde_json::json!({
"wallet_password": base64::encode(&password_bytes),
"cipher_seed_mnemonic": cipher_seed_mnemonic,
})
))
.status()?;
if status.success() {
let mut pass_file = File::create("/root/.lnd/pwd.dat")?;
pass_file.write_all(&password_bytes)?;
} else {
return Err(anyhow::anyhow!("Error creating wallet. Exiting."));
}
cipher_seed_created = true
} else {
println!("Waiting for RPC to start...");
std::thread::sleep(Duration::from_secs(5));
}
}
}

println!("copying macaroon to public dir...");
while !Path::new("/root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon").exists() {
std::thread::sleep(std::time::Duration::from_secs(1));
Expand Down
2 changes: 1 addition & 1 deletion docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ lnd_child=$!

while ! [ -e /root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon ]; do
echo "Waiting for lnd to create macaroon..."
sleep 1
sleep 30
done

cat /root/.lnd/data/chain/bitcoin/mainnet/admin.macaroon | basenc --base16 -w0 > /root/.lnd/start9/admin.macaroon.hex
Expand Down
Loading

0 comments on commit f90c2fd

Please sign in to comment.