summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorauric <104602845+ihateamongus@users.noreply.github.com>2025-09-11 09:38:49 -0500
committerauric <104602845+ihateamongus@users.noreply.github.com>2025-09-11 09:38:49 -0500
commit4da4c90adba63332f305725f6dcff9d0e0665b96 (patch)
tree928938f4d2d0c8e7447c6c69cdb0463c60d21dd2
parent8f03aa9417b06d91182e7adc2e0b8c53e7cf6069 (diff)
Add Gentoo system snapshot script and viewer
-rw-r--r--tools/Makefile7
-rwxr-xr-xtools/gentoo_snapshot.sh81
-rw-r--r--tools/snapshot_viewer.c27
3 files changed, 113 insertions, 2 deletions
diff --git a/tools/Makefile b/tools/Makefile
index e42f8bf..f81d083 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -4,7 +4,7 @@ CFLAGS = -std=c99 -Wall -Wextra -pedantic -Os
LDFLAGS =
PREFIX ?= /usr/local
-all: exofetch colorstagger
+all: exofetch colorstagger snapshot_viewer
exofetch: exofetch.c
>$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
@@ -12,8 +12,11 @@ exofetch: exofetch.c
colorstagger: colorstagger.c
>$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -lX11
+snapshot_viewer: snapshot_viewer.c
+>$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+
clean:
->rm -f exofetch colorstagger
+>rm -f exofetch colorstagger snapshot_viewer
install: exofetch
>mkdir -p $(DESTDIR)$(PREFIX)/bin
diff --git a/tools/gentoo_snapshot.sh b/tools/gentoo_snapshot.sh
new file mode 100755
index 0000000..40c4748
--- /dev/null
+++ b/tools/gentoo_snapshot.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+# gentoo_snapshot.sh - collect a system snapshot on Gentoo/OpenRC systems
+# Usage: gentoo_snapshot.sh [output_file]
+# Default output file is gentoo_snapshot.txt in the current directory.
+
+set -e
+
+OUTPUT=${1:-gentoo_snapshot.txt}
+TMPDIR=$(mktemp -d)
+
+cleanup() {
+ rm -rf "$TMPDIR"
+}
+trap cleanup EXIT
+
+printf "===== Gentoo System Snapshot: %s =====\n" "$(date)" > "$OUTPUT"
+
+printf "\n## Kernel\n" >> "$OUTPUT"
+uname -a >> "$OUTPUT" 2>/dev/null || printf "uname not available\n" >> "$OUTPUT"
+
+printf "\n## CPU\n" >> "$OUTPUT"
+(lscpu 2>/dev/null || printf "lscpu not available\n") >> "$OUTPUT"
+
+printf "\n## Memory\n" >> "$OUTPUT"
+(free -h 2>/dev/null || printf "free not available\n") >> "$OUTPUT"
+
+printf "\n## Block Devices\n" >> "$OUTPUT"
+(lsblk 2>/dev/null || printf "lsblk not available\n") >> "$OUTPUT"
+
+printf "\n## Storage Usage\n" >> "$OUTPUT"
+(df -h 2>/dev/null || printf "df not available\n") >> "$OUTPUT"
+
+# Installed packages
+printf "\n## Installed Packages\n" >> "$OUTPUT"
+if command -v qlist >/dev/null 2>&1; then
+ qlist -I >> "$OUTPUT"
+elif command -v equery >/dev/null 2>&1; then
+ equery list '*' >> "$OUTPUT"
+else
+ printf "Package manager tools (qlist/equery) not found\n" >> "$OUTPUT"
+fi
+
+# OpenRC services
+printf "\n## OpenRC Services\n" >> "$OUTPUT"
+if command -v rc-update >/dev/null 2>&1; then
+ printf "\n### Enabled\n" >> "$OUTPUT"
+ rc-update show | awk '{print $1}' | sort -u >> "$OUTPUT"
+
+ printf "\n### Disabled\n" >> "$OUTPUT"
+ ENAB="$TMPDIR/enabled"
+ ALL="$TMPDIR/all"
+ rc-update show | awk '{print $1}' | sort -u > "$ENAB"
+ ls /etc/init.d 2>/dev/null | sort > "$ALL" || true
+ if [ -s "$ALL" ]; then
+ comm -23 "$ALL" "$ENAB" >> "$OUTPUT" || true
+ else
+ printf "/etc/init.d not accessible\n" >> "$OUTPUT"
+ fi
+else
+ printf "rc-update not found\n" >> "$OUTPUT"
+fi
+
+# Largest files
+printf "\n## Largest Files\n" >> "$OUTPUT"
+(find / -xdev -type f -printf '%s\t%p\n' 2>/dev/null | sort -nr | head -n 20 2>/dev/null || printf "find not available\n") >> "$OUTPUT"
+
+# Cleanup suggestions
+printf "\n## Cleanup Suggestions\n" >> "$OUTPUT"
+if [ -d /var/cache/distfiles ]; then
+ du -sh /var/cache/distfiles 2>/dev/null | awk '{print "Distfiles cache: "$1}' >> "$OUTPUT"
+fi
+if [ -d /var/tmp/portage ]; then
+ du -sh /var/tmp/portage 2>/dev/null | awk '{print "Portage build dir: "$1}' >> "$OUTPUT"
+fi
+printf "Consider running 'eclean packages' and 'eclean distfiles'\n" >> "$OUTPUT"
+
+# Additional information
+printf "\n## Environment\n" >> "$OUTPUT"
+(printenv 2>/dev/null || printf "printenv not available\n") >> "$OUTPUT"
+
+printf "\nSnapshot saved to %s\n" "$OUTPUT" >> "$OUTPUT"
diff --git a/tools/snapshot_viewer.c b/tools/snapshot_viewer.c
new file mode 100644
index 0000000..30ece56
--- /dev/null
+++ b/tools/snapshot_viewer.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char *argv[]) {
+ const char *file = (argc > 1) ? argv[1] : "gentoo_snapshot.txt";
+ FILE *fp = fopen(file, "r");
+ if (!fp) {
+ perror("fopen");
+ return 1;
+ }
+
+ char line[1024];
+ while (fgets(line, sizeof line, fp)) {
+ if (strncmp(line, "=====", 5) == 0) {
+ printf("\033[1;32m%s\033[0m", line);
+ } else if (strncmp(line, "##", 2) == 0) {
+ printf("\033[1;34m%s\033[0m", line);
+ } else if (strncmp(line, "###", 3) == 0) {
+ printf("\033[1;36m%s\033[0m", line);
+ } else {
+ fputs(line, stdout);
+ }
+ }
+
+ fclose(fp);
+ return 0;
+}