added makefile, funcs for install files to root
This commit is contained in:
17
Makefile
Normal file
17
Makefile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
.PHONY: clean
|
||||||
|
all:run
|
||||||
|
|
||||||
|
run: debugBuild
|
||||||
|
sudo ./target/debug/steckbrett
|
||||||
|
|
||||||
|
debugBuild:
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
rrun: build
|
||||||
|
sudo ./target/release/steckbrett
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
@@ -3,7 +3,7 @@ pub mod entry;
|
|||||||
mod settings;
|
mod settings;
|
||||||
|
|
||||||
pub mod status;
|
pub mod status;
|
||||||
use std::{thread::sleep, time::Duration};
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{
|
||||||
entry::Entry,
|
entry::Entry,
|
||||||
@@ -11,6 +11,7 @@ use crate::app::{
|
|||||||
status::{AppStatus, CurrentScreen, EditingField, EntryValError},
|
status::{AppStatus, CurrentScreen, EditingField, EntryValError},
|
||||||
};
|
};
|
||||||
use ratatui::widgets::TableState;
|
use ratatui::widgets::TableState;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub fromIP: String,
|
pub fromIP: String,
|
||||||
@@ -115,8 +116,53 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
outputString.push_str("\nwait");
|
outputString.push_str("\nwait");
|
||||||
println!("Writing config to system");
|
println!("Writing config to system");
|
||||||
sleep(Duration::from_millis(100));
|
let _ = std::fs::write("/usr/bin/forward.sh", outputString);
|
||||||
let _ = std::fs::write("./forward.sh", outputString);
|
Command::new("chmod")
|
||||||
|
.args(["+x", "/usr/bin/forward.sh"])
|
||||||
|
.output()
|
||||||
|
.expect("unable to configure startup script");
|
||||||
|
Command::new("systemctl")
|
||||||
|
.arg("daemon-reload")
|
||||||
|
.output()
|
||||||
|
.expect("unable to restart service");
|
||||||
|
}
|
||||||
|
|
||||||
|
// MUST REMOVE WHEN USED ELSE WHERE
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn installFiles(&self) {
|
||||||
|
self.saveConfigToScript();
|
||||||
|
let mut systemdString: String = String::new();
|
||||||
|
systemdString.push_str(
|
||||||
|
"
|
||||||
|
# DO NOT EDIT THIS FILE MANUALLY
|
||||||
|
# ANY MODIFICATIONS WILL BE OVERWRITTEN WHEN STECKBRETT IS RESET
|
||||||
|
# MODIFY AT YOUR OWN RISK
|
||||||
|
[Unit]
|
||||||
|
Description=Forward port to internal system
|
||||||
|
After=network.target
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
ExecStart=/usr/bin/portForward.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target",
|
||||||
|
);
|
||||||
|
let _ = std::fs::write("/etc/systemd/system/portForward.service", systemdString);
|
||||||
|
Command::new("systemctl")
|
||||||
|
.arg("daemon-reload")
|
||||||
|
.output()
|
||||||
|
.expect("Unable to reload systemd");
|
||||||
|
}
|
||||||
|
|
||||||
|
// MUST REMOVE WHEN USED ELSE WHERE
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn checkSTBFiles(&self) -> bool {
|
||||||
|
let serviceFile = Path::new("/etc/systemd/system/portForward.service");
|
||||||
|
let forwardScript = Path::new("/usr/bin/forward.sh");
|
||||||
|
serviceFile.exists() || forwardScript.exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn saveConfigToSettingsFile(&mut self) {
|
pub fn saveConfigToSettingsFile(&mut self) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::app::entry::Entry;
|
use crate::app::entry::Entry;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Display;
|
use std::{fmt::Display, path::Path};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
@@ -15,13 +15,15 @@ impl Display for Settings {
|
|||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn new(config: &String) -> Self {
|
pub fn new(config: &String) -> Self {
|
||||||
let data = std::fs::read_to_string(config);
|
let confPath = Path::new(config);
|
||||||
|
let data = std::fs::read_to_string(confPath);
|
||||||
match data {
|
match data {
|
||||||
Ok(data) => serde_json::from_str::<Settings>(&data).expect("Settings file corrupted"),
|
Ok(data) => serde_json::from_str::<Settings>(&data).expect("Settings file corrupted"),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let newSet = Settings { entries: vec![] };
|
let newSet = Settings { entries: vec![] };
|
||||||
let payload = serde_json::to_string_pretty(&newSet).unwrap();
|
let payload = serde_json::to_string_pretty(&newSet).unwrap();
|
||||||
let _ = std::fs::write(config, payload);
|
let _ = std::fs::create_dir(confPath.parent().unwrap());
|
||||||
|
let _ = std::fs::write(confPath, payload);
|
||||||
newSet
|
newSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user