diff --git a/Cargo.lock b/Cargo.lock index 07000f8..582203b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -668,6 +668,7 @@ version = "0.1.0" dependencies = [ "anyhow", "config", + "dirs", "lazy_static", "notify", "rust-s3", diff --git a/Cargo.toml b/Cargo.toml index a2e453c..91c1c46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,12 +3,12 @@ name = "rsink" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0.62" config = "0.13.2" +dirs = "4.0.0" lazy_static = "1.4.0" notify = "5.0.0" rust-s3 = { version = "0.32.3", default-features = false, features = ["sync", "tags", "sync-rustls-tls"] } -spinners = "4.1.0" \ No newline at end of file +spinners = "4.1.0" diff --git a/README.md b/README.md index 9b9fcb0..f96414b 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ Simple utility to backup/sync data between devices to the cloud - [ ] Mega ### Install -1. [Download](https://github.com/abdulrahman1s/RSink/releases/latest) the executable file from releases. -2. Extract the zipped file -3. Create a file named [`config.toml`](config.example.toml) and fill the missing values -4. Type `./rsink` to run the program +#### Shell (Linux/Mac/Termux) +```sh +$ curl -fsSL https://raw.githubusercontent.com/abdulrahman1s/RSink/master/install.sh | sh +``` ### Run on Android ... @@ -38,7 +38,7 @@ Simple utility to backup/sync data between devices to the cloud ### TODO -- [ ] Install script +- [X] Install script - [ ] Multiple providers the same time - [ ] Test the windows version - [ ] Support other cloud providers diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..60b886e --- /dev/null +++ b/install.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +if ! command -v tar >/dev/null; then + echo "Error: tar is required to install rsink" 1>&2 + exit 1 +fi + +if [ "$OS" = "Windows_NT" ]; then + target="x86_64-pc-windows-msvc" +else + case $(uname -sm) in + "Darwin x86_64") target="x86_64-apple-darwin" ;; + "Darwin arm64") target="aarch64-apple-darwin" ;; + "Android i686" | "Android x86" | "Android i786" | "Android i486" | "Android i386") target="i686-linux-android" ;; + "Android armv7l" | "Android armv8l" | "Android arm") target="armv7-linux-androideabi" ;; + "Linux aarch64" | "Linux arm64") target="aarch64-unknown-linux-gnu" ;; + *) target="x86_64-unknown-linux-gnu" ;; + esac +fi + +echo "Target: $target" + +arcive_url="https://github.com/abdulrahman1s/RSink/releases/latest/download/rsink-${target}.tar.gz" +install_path="$HOME/.local/bin" +exe="$install_path/rsink" + +curl --fail --location --progress-bar --output "$exe.tar.gz" "$arcive_url" +tar -xzvf "$exe.tar.gz" -C "$install_path" +rm "$exe.tar.gz" + +if command -v tar >/dev/null; then + sudo sh -c "echo '[Unit] +Description=Rsink syncls + +[Service] +Type=simple +ExecStart=$exe + +[Install] +WantedBy=multi-user.target' >> /etc/systemd/system/rsink.service" + + sudo systemctl enable rsink + sudo systemctl start rsink + systemctl status rsink +fi + +echo "Rsink was installed successfully to $exe" +echo "Please edit/create $HOME/.config/rsink/config.toml to configure the settings" +echo "An example of the configuration file at https://github.com/abdulrahman1s/RSink/blob/master/config.example.toml" diff --git a/src/main.rs b/src/main.rs index 70ea8d6..e17e7e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use util::*; lazy_static! { pub static ref SETTINGS: Config = Config::builder() - .add_source(config::File::with_name("config")) + .add_source(config::File::from(settings_file().unwrap())) .build() .expect("Cannot init settings"); pub static ref SYNC_DIR: PathBuf = SETTINGS diff --git a/src/util.rs b/src/util.rs index ff3fbc7..9cc4180 100644 --- a/src/util.rs +++ b/src/util.rs @@ -69,3 +69,28 @@ where sp.stop_with_message(stop_message.into()); } } + +pub fn settings_file() -> Result { + let mut path = dirs::config_dir().unwrap(); + + path.push("rsink"); + + fs::create_dir_all(&path)?; + + path.push("config.toml"); + + let file = fs::File::options() + .write(true) + .read(true) + .create(true) + .open(&path)?; + + if file.metadata()?.len() == 0 { + return Err(anyhow::anyhow!( + "Please configure the settings file at {}", + path.to_string_lossy() + )); + } + + Ok(path) +}