aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2025-10-06 15:35:57 +0200
committerLeonard Kugis <leonard@kug.is>2025-10-06 15:35:57 +0200
commitd0f9161188e70b1144db4739d97e20be872e06aa (patch)
tree8d9fd913724c1078018e819ded2625fafc7bff1d
parent460fe72c98204758b12931efb15f5a35b387d6f3 (diff)
downloadsquashr-d0f9161188e70b1144db4739d97e20be872e06aa.tar.gz
Implemented as Makefile project
-rw-r--r--.gitignore23
-rw-r--r--Cargo.toml23
-rw-r--r--Makefile43
-rw-r--r--packaging/squashr.conf24
-rwxr-xr-xsrc/main.rs (renamed from squashr.rs)50
5 files changed, 142 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 4efb7e9..4f8e0b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,8 @@
backup
test
-# Created by https://www.toptal.com/developers/gitignore/api/linux,windows,macos,vim
-# Edit at https://www.toptal.com/developers/gitignore?templates=linux,windows,macos,vim
+
+# Created by https://www.toptal.com/developers/gitignore/api/rust,linux,windows,macos,vim
+# Edit at https://www.toptal.com/developers/gitignore?templates=rust,linux,windows,macos,vim
### Linux ###
*~
@@ -51,6 +52,22 @@ Temporary Items
# iCloud generated files
*.icloud
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+debug/
+target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# MSVC Windows builds of rustc generate these, which store debugging information
+*.pdb
+
### Vim ###
# Swap
[._]*.s[a-v][a-z]
@@ -97,5 +114,5 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
-# End of https://www.toptal.com/developers/gitignore/api/linux,windows,macos,vim
+# End of https://www.toptal.com/developers/gitignore/api/rust,linux,windows,macos,vim
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..eaf6c8b
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,23 @@
+[package]
+name = "squashr"
+version = "1.0.0"
+edition = "2021"
+license = "GNU AGPLv3"
+description = "Manage backups based on SquashFS, OverlayFS and LUKS"
+repository = "https://git.kug.is/squashr.git"
+
+[dependencies]
+anyhow = "1"
+clap = { version = "4", features = ["derive"] }
+serde = { version = "1", features = ["derive"] }
+itertools = "0.12"
+regex = "1"
+walkdir = "2"
+chrono = { version = "0.4", default-features = false, features = ["clock"] }
+rusqlite = { version = "0.31", features = ["bundled"] }
+libc = "0.2"
+
+[profile.release]
+lto = true
+codegen-units = 1
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ffbdd73
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,43 @@
+# Konfigurierbare Variablen (Standard wie bei Autotools)
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+ETCDIR ?= /etc
+DESTDIR ?=
+
+BIN := target/release/squashr
+NAME := squashr
+
+.PHONY: all build release debug install uninstall clean
+
+all: release
+
+build: release
+
+release:
+ cargo build --release
+
+debug:
+ cargo build
+
+install: $(BIN)
+ # Binärdatei
+ install -d $(DESTDIR)$(BINDIR)
+ install -m 0755 $(BIN) $(DESTDIR)$(BINDIR)/$(NAME)
+ # Beispiel-Config nur anlegen, wenn noch nicht vorhanden
+ install -d $(DESTDIR)$(ETCDIR)
+ @if [ ! -f "$(DESTDIR)$(ETCDIR)/squashr.conf" ]; then \
+ install -m 0644 packaging/squashr.conf "$(DESTDIR)$(ETCDIR)/squashr.conf"; \
+ echo "Installed default $(ETCDIR)/squashr.conf"; \
+ else \
+ echo "Keeping existing $(ETCDIR)/squashr.conf"; \
+ fi
+ @echo "Installed $(NAME) to $(DESTDIR)$(BINDIR)/$(NAME)"
+
+uninstall:
+ @rm -f "$(DESTDIR)$(BINDIR)/$(NAME)"
+ @echo "Removed $(DESTDIR)$(BINDIR)/$(NAME)"
+ @echo "(Keeping $(ETCDIR)/squashr.conf, remove manually if neccessary.)"
+
+clean:
+ cargo clean
+
diff --git a/packaging/squashr.conf b/packaging/squashr.conf
new file mode 100644
index 0000000..a4870b5
--- /dev/null
+++ b/packaging/squashr.conf
@@ -0,0 +1,24 @@
+# Backup root directory
+SQUASHR_ROOT=/var/lib/squashr
+
+# Includes (comma separated, directories and files)
+SQUASHR_INCLUDE=/etc, /home
+# Excludes (comma separated, directories and files)
+SQUASHR_EXCLUDE=/home/*/.cache, /home/*/Downloads
+
+# Truncation
+SQUASHR_TRUNCATE=/var/log
+
+# Rotation
+SQUASHR_N_SNAPSHOTS_MIN=5
+SQUASHR_N_SNAPSHOTS_MAX=30
+
+# Compression
+SQUASHR_COMPRESSION_ENABLE=true
+SQUASHR_COMPRESSION_ALGO=zstd
+SQUASHR_COMPRESSION_ARGS=-Xcompression-level 19
+
+# Encryption
+SQUASHR_CRYPTSETUP_ENABLE=false
+SQUASHR_CRYPTSETUP_CREATE_ARGS=--type luks2
+SQUASHR_CRYPTSETUP_OPEN_ARGS=--type luks
diff --git a/squashr.rs b/src/main.rs
index 2c77051..8df82ec 100755
--- a/squashr.rs
+++ b/src/main.rs
@@ -1,21 +1,19 @@
-#!/usr/bin/env -S rust-script
-//! ```cargo
-//! [package]
-//! name = "squashr"
-//! version = "0.5.1"
-//! edition = "2021"
-//!
-//! [dependencies]
-//! anyhow = "1"
-//! clap = { version = "4", features = ["derive"] }
-//! serde = { version = "1", features = ["derive"] }
-//! itertools = "0.12"
-//! regex = "1"
-//! walkdir = "2"
-//! chrono = { version = "0.4", default-features = false, features = ["clock"] }
-//! rusqlite = { version = "0.31", features = ["bundled"] }
-//! libc = "0.2"
-//! ```
+/* SquashR - Manage backups based on SquashFS, OverlayFS and LUKS
+ * Copyright (C) 2025 Leonard Kugis <leonard@kug.is>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
use anyhow::{anyhow, bail, Context, Result};
use clap::{Parser, Subcommand, ValueHint};
@@ -206,6 +204,18 @@ fn apply_cli_overrides(mut cfg: Config, cli:&Cli)->Result<Config>{
Ok(cfg)
}
+fn default_config_paths() -> Vec<PathBuf> {
+ let mut v = Vec::new();
+ if let Ok(xdg) = env::var("XDG_CONFIG_HOME") {
+ v.push(PathBuf::from(xdg).join("squashr/squashr.conf"));
+ }
+ if let Ok(home) = env::var("HOME") {
+ v.push(PathBuf::from(home).join(".config/squashr/squashr.conf"));
+ }
+ v.push(PathBuf::from("/etc/squashr.conf"));
+ v
+}
+
#[derive(Clone)]
struct Ctx {
state_dir: PathBuf,
@@ -285,6 +295,10 @@ impl Ctx {
fn main() -> Result<()> {
let cli = Cli::parse();
+ let cfg_path = match &cli.config {
+ Some(p) => Some(p.clone()),
+ None => default_config_paths().into_iter().find(|p| p.exists()),
+ };
let cfg = load_config(cli.config.as_deref())?;
let cfg = apply_env_overrides(cfg)?;
let cfg = apply_cli_overrides(cfg, &cli)?;