Skip to content

Commit

Permalink
feat: Install script
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulrahman1s committed Sep 2, 2022
1 parent ba9b1a0 commit 9059cca
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 8 deletions.
1 change: 1 addition & 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 @@ -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"
spinners = "4.1.0"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
Expand All @@ -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
Expand Down
49 changes: 49 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,28 @@ where
sp.stop_with_message(stop_message.into());
}
}

pub fn settings_file() -> Result<PathBuf> {
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)
}

0 comments on commit 9059cca

Please sign in to comment.