Compare commits
11 Commits
cdd3ba0cbd
...
v0.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
38ed42f4b7
|
|||
|
1f95d5b1b1
|
|||
| c08693d39c | |||
|
a8a15bab36
|
|||
|
7719d2442d
|
|||
| 58c682d4d3 | |||
|
45d9f5f6c8
|
|||
|
659a76f5c9
|
|||
|
250077c592
|
|||
|
631843b3c5
|
|||
|
9c653e44a4
|
@@ -22,8 +22,15 @@ jobs:
|
||||
- name: Run pre-commit hooks
|
||||
run: pre-commit run --all-files --color always
|
||||
|
||||
- name: Install Poetry
|
||||
run: |
|
||||
pip install poetry
|
||||
poetry self add poetry-plugin-export
|
||||
|
||||
- name: Install pip-audit
|
||||
run: pip install pip-audit
|
||||
|
||||
- name: Run pip-audit
|
||||
run: pip-audit
|
||||
- name: Audit dependencies (Poetry lockfile)
|
||||
run: |
|
||||
poetry export -f requirements.txt --without-hashes \
|
||||
| pip-audit -r /dev/stdin
|
||||
|
||||
61
.gitea/workflows/trivy-scan.yml
Normal file
61
.gitea/workflows/trivy-scan.yml
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
name: Trivy Scan
|
||||
on:
|
||||
schedule:
|
||||
- cron: 17 8 * * *
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
security-scan:
|
||||
runs-on: running-man
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Trivy scan via Docker
|
||||
id: trivy
|
||||
continue-on-error: true
|
||||
run: |
|
||||
docker run --rm \
|
||||
--volumes-from "$HOSTNAME" \
|
||||
aquasec/trivy:latest \
|
||||
fs /workspace/guardutils/resrm \
|
||||
--scanners vuln \
|
||||
--pkg-types library \
|
||||
--include-dev-deps \
|
||||
--severity MEDIUM,HIGH,CRITICAL \
|
||||
--ignore-unfixed \
|
||||
--format json \
|
||||
--output /workspace/guardutils/resrm/trivy.json \
|
||||
--exit-code 1
|
||||
|
||||
- name: Notify Node-RED on vulnerabilities
|
||||
if: steps.trivy.outcome == 'failure'
|
||||
run: |
|
||||
jq -r '
|
||||
{
|
||||
repo: "guardutils/resrm",
|
||||
summary: (
|
||||
"Total: " +
|
||||
((.Results[].Vulnerabilities | length) | tostring)
|
||||
),
|
||||
vulnerabilities: [
|
||||
.Results[].Vulnerabilities[] | {
|
||||
library: .PkgName,
|
||||
cve: .VulnerabilityID,
|
||||
severity: .Severity,
|
||||
installed: .InstalledVersion,
|
||||
fixed: .FixedVersion,
|
||||
title: .Title,
|
||||
url: .PrimaryURL
|
||||
}
|
||||
]
|
||||
}
|
||||
' trivy.json \
|
||||
| curl -s -X POST https://nodered.sysmd.uk/trivy-alert \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary @-
|
||||
|
||||
- name: Fail workflow if vulnerabilities found
|
||||
if: steps.trivy.outcome == 'failure'
|
||||
run: exit 1
|
||||
17
README.md
17
README.md
@@ -1,9 +1,13 @@
|
||||
[](https://git.sysmd.uk/guardutils/resrm/src/branch/main/LICENCE)
|
||||

|
||||
[](https://git.sysmd.uk/guardutils/resrm/releases)
|
||||
[](https://git.sysmd.uk/guardutils/resrm/src/branch/main/.pre-commit-config.yaml)
|
||||
|
||||
# resrm
|
||||
|
||||
<div align="center">
|
||||
<img src="resrm.png" alt="resrm logo" width="256" />
|
||||
</div>
|
||||
|
||||
**resrm** is a safe, drop-in replacement for the Linux `rm` command with **undo/restore support**.
|
||||
It moves files to a per-user _trash_ instead of permanently deleting them, while still allowing full `sudo` support for root-owned files.
|
||||
|
||||
@@ -41,7 +45,7 @@ The GPG fingerprint is `0032C71FA6A11EF9567D4434C5C06BD4603C28B1`.
|
||||
#### 2) Add the APT source
|
||||
|
||||
```bash
|
||||
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/guardutils.gpg] https://repo.sysmd.uk debian main" | sudo tee /etc/apt/sources.list.d/guardutils.list
|
||||
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/guardutils.gpg] https://repo.sysmd.uk/guardutils/debian stable main" | sudo tee /etc/apt/sources.list.d/guardutils.list
|
||||
```
|
||||
|
||||
#### 3) Update and install
|
||||
@@ -65,13 +69,11 @@ sudo rpm --import https://repo.sysmd.uk/guardutils/guardutils.gpg
|
||||
sudo tee /etc/yum.repos.d/guardutils.repo > /dev/null << 'EOF'
|
||||
[guardutils]
|
||||
name=GuardUtils Repository
|
||||
baseurl = https://repo.sysmd.uk/rpm/$basearch
|
||||
|
||||
baseurl=https://repo.sysmd.uk/guardutils/rpm/$basearch
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey = https://repo.sysmd.uk/guardutils/guardutils.gpg
|
||||
|
||||
repo_gpgcheck=1
|
||||
gpgkey=https://repo.sysmd.uk/guardutils/guardutils.gpg
|
||||
EOF
|
||||
```
|
||||
|
||||
@@ -132,6 +134,9 @@ resrm -l
|
||||
# Restore a file by ID or basename
|
||||
resrm --restore <id|name>
|
||||
|
||||
# Show full details of trashed item
|
||||
resrm --inspect <id|name>
|
||||
|
||||
# Empty the trash permanently
|
||||
resrm --empty
|
||||
```
|
||||
|
||||
14
poetry.lock
generated
14
poetry.lock
generated
@@ -38,13 +38,13 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.20.0"
|
||||
version = "3.20.3"
|
||||
description = "A platform independent file lock."
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
files = [
|
||||
{file = "filelock-3.20.0-py3-none-any.whl", hash = "sha256:339b4732ffda5cd79b13f4e2711a31b0365ce445d95d243bb996273d072546a2"},
|
||||
{file = "filelock-3.20.0.tar.gz", hash = "sha256:711e943b4ec6be42e1d4e6690b48dc175c822967466bb31c0c293f34334c13f4"},
|
||||
{file = "filelock-3.20.3-py3-none-any.whl", hash = "sha256:4b0dda527ee31078689fc205ec4f1c1bf7d56cf88b6dc9426c4f230e46c2dce1"},
|
||||
{file = "filelock-3.20.3.tar.gz", hash = "sha256:18c57ee915c7ec61cff0ecf7f0f869936c7c30191bb0cf406f1341778d0834e1"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -201,18 +201,18 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "virtualenv"
|
||||
version = "20.35.4"
|
||||
version = "20.36.1"
|
||||
description = "Virtual Python Environment builder"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "virtualenv-20.35.4-py3-none-any.whl", hash = "sha256:c21c9cede36c9753eeade68ba7d523529f228a403463376cf821eaae2b650f1b"},
|
||||
{file = "virtualenv-20.35.4.tar.gz", hash = "sha256:643d3914d73d3eeb0c552cbb12d7e82adf0e504dbf86a3182f8771a153a1971c"},
|
||||
{file = "virtualenv-20.36.1-py3-none-any.whl", hash = "sha256:575a8d6b124ef88f6f51d56d656132389f961062a9177016a50e4f507bbcc19f"},
|
||||
{file = "virtualenv-20.36.1.tar.gz", hash = "sha256:8befb5c81842c641f8ee658481e42641c68b5eab3521d8e092d18320902466ba"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
distlib = ">=0.3.7,<1"
|
||||
filelock = ">=3.12.2,<4"
|
||||
filelock = {version = ">=3.20.1,<4", markers = "python_version >= \"3.10\""}
|
||||
platformdirs = ">=3.9.1,<5"
|
||||
typing-extensions = {version = ">=4.13.2", markers = "python_version < \"3.11\""}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "resrm"
|
||||
version = "0.3.3"
|
||||
version = "0.4.1"
|
||||
description = "drop-in replacement for rm with undo/restore built-in."
|
||||
authors = ["Marco D'Aleo <marco@marcodaleo.com>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
@@ -10,6 +10,7 @@ Basic usage:
|
||||
resrm --skip-trash file # permanent delete (bypass trash)
|
||||
resrm -l|--list # list trash entries (neat table)
|
||||
resrm --restore <id|name> # restore by short-id (8 chars) or exact basename
|
||||
resrm --inspect <id|name> # output full detail list of trashed item
|
||||
resrm --empty # empty trash entries (permanent)
|
||||
"""
|
||||
|
||||
@@ -268,20 +269,23 @@ def restore(identifier: str):
|
||||
|
||||
def empty_trash():
|
||||
"""Permanently remove all trashed files and clear metadata."""
|
||||
|
||||
# Remove everything inside the trash directory
|
||||
count = 0
|
||||
for entry in list(meta):
|
||||
f = TRASH_DIR / entry["id"]
|
||||
for item in TRASH_DIR.iterdir():
|
||||
try:
|
||||
if f.exists():
|
||||
if f.is_dir():
|
||||
shutil.rmtree(f, ignore_errors=True)
|
||||
if item.is_dir():
|
||||
shutil.rmtree(item, ignore_errors=True)
|
||||
else:
|
||||
f.unlink(missing_ok=True)
|
||||
meta.remove(entry)
|
||||
item.unlink(missing_ok=True)
|
||||
count += 1
|
||||
except Exception as e:
|
||||
print(f"Failed to remove {f}: {e}")
|
||||
print(f"Failed to remove {item}: {e}")
|
||||
|
||||
# Clear metadata
|
||||
meta.clear()
|
||||
save_meta(meta)
|
||||
|
||||
print(f"Trash emptied ({count} entries removed).")
|
||||
|
||||
|
||||
@@ -374,6 +378,79 @@ def move_to_trash(
|
||||
print(f"Removed '{path}' -> trash id {short_id(uid)}")
|
||||
|
||||
|
||||
def inspect_entry(identifier: str):
|
||||
"""Show full information about trash entries matching the identifier."""
|
||||
candidates = find_candidates(identifier)
|
||||
|
||||
if not candidates:
|
||||
print(f"No match found for '{identifier}'")
|
||||
return
|
||||
|
||||
for entry in candidates:
|
||||
|
||||
# Validate entry structure
|
||||
if not isinstance(entry, dict):
|
||||
print(f"Invalid metadata entry (not a dict): {entry!r}")
|
||||
print()
|
||||
continue
|
||||
|
||||
entry_id = entry.get("id")
|
||||
orig_path = entry.get("orig_path", "?")
|
||||
timestamp = entry.get("timestamp", "?")
|
||||
|
||||
if not entry_id:
|
||||
print(f"Invalid metadata entry (missing id): {entry}")
|
||||
continue
|
||||
|
||||
trash_path = TRASH_DIR / entry_id
|
||||
|
||||
print(f"ID: {short_id(entry_id)}")
|
||||
print(f"Original: {orig_path}")
|
||||
print(f"Deleted at: {human_time(timestamp)}")
|
||||
print(f"Stored at: {trash_path}")
|
||||
|
||||
try:
|
||||
st = trash_path.lstat() # preserves symlink info
|
||||
import stat, pwd, grp
|
||||
|
||||
# Type detection
|
||||
if stat.S_ISDIR(st.st_mode):
|
||||
ftype = "directory"
|
||||
elif stat.S_ISLNK(st.st_mode):
|
||||
try:
|
||||
target = os.readlink(trash_path)
|
||||
ftype = f"symlink → {target}"
|
||||
except Exception:
|
||||
ftype = "symlink"
|
||||
else:
|
||||
ftype = "file"
|
||||
|
||||
# Permissions
|
||||
perms = stat.filemode(st.st_mode)
|
||||
|
||||
# Ownership
|
||||
try:
|
||||
user = pwd.getpwuid(st.st_uid).pw_name
|
||||
except Exception:
|
||||
user = st.st_uid
|
||||
try:
|
||||
group = grp.getgrgid(st.st_gid).gr_name
|
||||
except Exception:
|
||||
group = st.st_gid
|
||||
owner = f"{user}:{group}"
|
||||
|
||||
# Size (bytes for file, recursive for directories)
|
||||
size = st.st_size
|
||||
|
||||
print(f"Type: {ftype}")
|
||||
print(f"Size: {size} bytes")
|
||||
print(f"Permissions: {perms}")
|
||||
print(f"Ownership: {owner}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Unknown stats for {e}")
|
||||
|
||||
|
||||
def main(argv: Optional[List[str]] = None):
|
||||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
@@ -386,6 +463,15 @@ def main(argv: Optional[List[str]] = None):
|
||||
parser.add_argument(
|
||||
"--skip-trash", action="store_true", help="permanent delete"
|
||||
)
|
||||
|
||||
inspect_arg = parser.add_argument(
|
||||
"--inspect",
|
||||
"-I",
|
||||
nargs="+",
|
||||
metavar="item",
|
||||
help="show full metadata and original path for this trash entry",
|
||||
)
|
||||
|
||||
restore_arg = parser.add_argument(
|
||||
"--restore",
|
||||
nargs="+",
|
||||
@@ -393,8 +479,8 @@ def main(argv: Optional[List[str]] = None):
|
||||
help="restore by id or basename",
|
||||
)
|
||||
|
||||
# restore completer
|
||||
def restore_completer(prefix, parsed_args, **kwargs):
|
||||
# completer
|
||||
def id_name_completer(prefix, parsed_args, **kwargs):
|
||||
return [
|
||||
short_id(m["id"])
|
||||
for m in meta
|
||||
@@ -405,7 +491,8 @@ def main(argv: Optional[List[str]] = None):
|
||||
if Path(m["orig_path"]).name.startswith(prefix)
|
||||
]
|
||||
|
||||
restore_arg.completer = restore_completer
|
||||
restore_arg.completer = id_name_completer
|
||||
inspect_arg.completer = id_name_completer
|
||||
parser.add_argument("-l", "--list", action="store_true", help="list trash")
|
||||
parser.add_argument(
|
||||
"--empty", action="store_true", help="empty the trash permanently"
|
||||
@@ -424,7 +511,9 @@ def main(argv: Optional[List[str]] = None):
|
||||
print(__doc__)
|
||||
return
|
||||
|
||||
if not args.paths and not (args.list or args.empty or args.restore):
|
||||
if not args.paths and not (
|
||||
args.list or args.empty or args.restore or args.inspect
|
||||
):
|
||||
print("resrm: missing operand")
|
||||
print("Try 'resrm --help' for more information.")
|
||||
return
|
||||
@@ -433,6 +522,11 @@ def main(argv: Optional[List[str]] = None):
|
||||
list_trash()
|
||||
return
|
||||
|
||||
if args.inspect:
|
||||
for item in args.inspect:
|
||||
inspect_entry(item)
|
||||
return
|
||||
|
||||
if args.empty:
|
||||
empty_trash()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user