diff options
author | Leonard Kugis <leonard@kug.is> | 2025-10-06 15:35:57 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2025-10-06 15:35:57 +0200 |
commit | d0f9161188e70b1144db4739d97e20be872e06aa (patch) | |
tree | 8d9fd913724c1078018e819ded2625fafc7bff1d | |
parent | 460fe72c98204758b12931efb15f5a35b387d6f3 (diff) | |
download | squashr-d0f9161188e70b1144db4739d97e20be872e06aa.tar.gz |
Implemented as Makefile project
-rw-r--r-- | .gitignore | 23 | ||||
-rw-r--r-- | Cargo.toml | 23 | ||||
-rw-r--r-- | Makefile | 43 | ||||
-rw-r--r-- | packaging/squashr.conf | 24 | ||||
-rwxr-xr-x | src/main.rs (renamed from squashr.rs) | 50 |
5 files changed, 142 insertions, 21 deletions
@@ -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 @@ -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)?; |