Skip to content

Commit 1190869

Browse files
modified: .gitignore
modified: Makefile modified: README.md modified: main.go
1 parent 11b1780 commit 1190869

4 files changed

Lines changed: 223 additions & 142 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ coverage.*
2020
profile.cov
2121

2222
# Dependency directories (remove the comment below to include it)
23-
# vendor/
23+
vendor/
2424

2525
# Go workspace file
2626
go.work

Makefile

Lines changed: 105 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,110 @@
1-
# Makefile for cross-building storage binary
2-
# Valleyman style, server/Redmi/native targets with help
3-
4-
# ---------------------------
5-
# Colors for help output
6-
# ---------------------------
7-
RED := \033[0;31m
8-
GREEN := \033[0;32m
9-
YELLOW := \033[0;33m
10-
BLUE := \033[0;34m
11-
NC := \033[0m
12-
13-
# ---------------------------
14-
# Default target
15-
# ---------------------------
16-
TARGET ?= native
1+
# Makefile for Storage Monitor project
2+
# Supports building for ZyXEL NAS, Redmi (Android / Termux), and native Linux.
3+
# Includes colored help output, ./bin output folder, and automatic install logic.
4+
5+
# Colors
6+
YELLOW := \033[1;33m
7+
CYAN := \033[0;36m
8+
GREEN := \033[0;32m
9+
RED := \033[0;31m
10+
RESET := \033[0m
11+
12+
# Binary name and output folder
13+
BINARY := storage
1714
BIN_DIR := ./bin
18-
BIN := $(BIN_DIR)/storage
19-
SRC := ./main.go
20-
21-
# ---------------------------
22-
# Toolchain for NSA320 (server)
23-
# ---------------------------
24-
SERVER_CC := /ffp/bin/arm-ffp-linux-uclibcgnueabi-gcc
25-
SERVER_CXX := /ffp/bin/arm-ffp-linux-uclibcgnueabi-g++
26-
SERVER_CFLAGS := --sysroot=/ffp
27-
SERVER_LDFLAGS := --sysroot=/ffp
28-
29-
# ---------------------------
30-
# Toolchain for Redmi (ARM64 Android)
31-
# ---------------------------
32-
REDMI_CC := aarch64-linux-android21-clang
33-
REDMI_CXX := aarch64-linux-android21-clang++
34-
REDMI_CFLAGS := ""
35-
REDMI_LDFLAGS := ""
36-
37-
# ---------------------------
15+
16+
# Go build flags
17+
BUILD_FLAGS := -trimpath -v -x
18+
19+
# Default target
20+
.DEFAULT_GOAL := help
21+
22+
# Architecture definitions
23+
ZyXEL_GOARCH := arm
24+
ZyXEL_GOARM := 5
25+
ZyXEL_GOOS := linux
26+
27+
Redmi_GOARCH := arm64
28+
Redmi_GOARM := 8
29+
Redmi_GOOS := android
30+
31+
Termux_GOARCH := arm64
32+
Termux_GOARM := 8
33+
Termux_GOOS := linux
34+
35+
Native_GOARCH := $(shell go env GOARCH)
36+
Native_GOOS := $(shell go env GOOS)
37+
38+
# Ensure bin directory exists
39+
$(BIN_DIR):
40+
@mkdir -p $(BIN_DIR)
41+
3842
# Help target
39-
# ---------------------------
40-
.PHONY: help
4143
help:
42-
@echo "$(GREEN)Usage: make [TARGET]$(NC)"
43-
@echo "Targets:"
44-
@echo " $(YELLOW)server$(NC) - Build for NSA320 (ARMv5, Linux 2.6.31.8, uClibc)"
45-
@echo " $(YELLOW)redmi$(NC) - Build for Redmi (ARM64 Android)"
46-
@echo " $(YELLOW)native$(NC) - Build for current OS/architecture"
47-
@echo " $(YELLOW)clean$(NC) - Remove bin directory"
48-
49-
# ---------------------------
50-
# Build targets
51-
# ---------------------------
52-
.PHONY: all
53-
all: $(TARGET)
54-
55-
.PHONY: server
56-
server: $(BIN)
57-
@echo "$(BLUE)Built for server (NSA320 ARMv5) -> $(BIN)$(NC)"
58-
59-
.PHONY: redmi
60-
redmi: $(BIN)
61-
@echo "$(BLUE)Built for Redmi (ARM64 Android) -> $(BIN)$(NC)"
62-
63-
.PHONY: native
64-
native: $(BIN)
65-
@echo "$(BLUE)Built for native OS/arch -> $(BIN)$(NC)"
66-
67-
$(BIN): $(SRC)
68-
@mkdir -p $(BIN_DIR)
69-
ifeq ($(TARGET),server)
70-
@echo "$(YELLOW)Cross-building for NSA320 (ARMv5, uClibc)...$(NC)"
71-
@CGO_ENABLED=1 \
72-
GOOS=linux GOARCH=arm GOARM=5 \
73-
CC=$(SERVER_CC) CXX=$(SERVER_CXX) \
74-
CGO_CFLAGS="$(SERVER_CFLAGS)" CGO_LDFLAGS="$(SERVER_LDFLAGS)" \
75-
go build -v -o $(BIN) $(SRC)
76-
endif
77-
ifeq ($(TARGET),redmi)
78-
@echo "$(YELLOW)Cross-building for Redmi (ARM64 Android)...$(NC)"
79-
@CGO_ENABLED=1 \
80-
GOOS=android GOARCH=arm64 \
81-
CC=$(REDMI_CC) CXX=$(REDMI_CXX) \
82-
CGO_CFLAGS="$(REDMI_CFLAGS)" CGO_LDFLAGS="$(REDMI_LDFLAGS)" \
83-
go build -v -o $(BIN) $(SRC)
84-
endif
85-
ifeq ($(TARGET),native)
86-
@echo "$(YELLOW)Building for current OS/arch...$(NC)"
87-
@CGO_ENABLED=0 go build -v -o $(BIN) $(SRC)
88-
endif
89-
90-
# ---------------------------
44+
@echo ""
45+
@echo "$(CYAN)Storage Monitor Build System$(RESET)"
46+
@echo ""
47+
@echo "$(YELLOW)Usage:$(RESET)"
48+
@echo " make [target]"
49+
@echo ""
50+
@echo "$(YELLOW)Targets:$(RESET)"
51+
@echo " $(GREEN)help$(RESET) - Show this help message"
52+
@echo " $(GREEN)zyxel$(RESET) - Build binary for ZyXEL NAS (ARMv5, uClibc)"
53+
@echo " $(GREEN)redmi$(RESET) - Build binary for Redmi (Android/Termux ARM64)"
54+
@echo " $(GREEN)termux$(RESET) - Build binary for Termux (Linux ARM64)"
55+
@echo " $(GREEN)native$(RESET) - Build binary for native host system ($(Native_GOOS)/$(Native_GOARCH))"
56+
@echo " $(GREEN)install$(RESET) - Auto-detect system and install appropriate binary"
57+
@echo " $(GREEN)clean$(RESET) - Remove build artifacts"
58+
@echo ""
59+
60+
# ZyXEL target
61+
zyxel: $(BIN_DIR)
62+
@echo "$(CYAN)[*] Building for ZyXEL NAS (ARMv5 soft-float)$(RESET)"
63+
GOOS=$(ZyXEL_GOOS) GOARCH=$(ZyXEL_GOARCH) GOARM=$(ZyXEL_GOARM) go build $(BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY)-zyxel main.go
64+
@echo "$(GREEN)✔ Build complete: $(BIN_DIR)/$(BINARY)-zyxel$(RESET)"
65+
66+
# Redmi target
67+
redmi: $(BIN_DIR)
68+
@echo "$(CYAN)[*] Building for Redmi (Android / ARM64)$(RESET)"
69+
GOOS=$(Redmi_GOOS) GOARCH=$(Redmi_GOARCH) GOARM=$(Redmi_GOARM) go build $(BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY)-redmi main.go
70+
@echo "$(GREEN)✔ Build complete: $(BIN_DIR)/$(BINARY)-redmi$(RESET)"
71+
72+
# Termux target
73+
termux: $(BIN_DIR)
74+
@echo "$(CYAN)[*] Building for Termux (Linux / ARM64)$(RESET)"
75+
GOOS=$(Termux_GOOS) GOARCH=$(Termux_GOARCH) GOARM=$(Termux_GOARM) go build $(BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY)-termux main.go
76+
@echo "$(GREEN)✔ Build complete: $(BIN_DIR)/$(BINARY)-termux$(RESET)"
77+
78+
# Native build
79+
native: $(BIN_DIR)
80+
@echo "$(CYAN)[*] Building for native system ($(Native_GOOS)/$(Native_GOARCH))$(RESET)"
81+
GOOS=$(Native_GOOS) GOARCH=$(Native_GOARCH) go build $(BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY)-native main.go
82+
@echo "$(GREEN)✔ Build complete: $(BIN_DIR)/$(BINARY)-native$(RESET)"
83+
84+
# Install target (auto-detect platform)
85+
install:
86+
@echo "$(CYAN)[*] Detecting target system...$(RESET)"
87+
@if [ -d "/ffp" ]; then \
88+
echo "$(CYAN)[+] Detected ZyXEL NAS (FFP environment)$(RESET)"; \
89+
$(MAKE) zyxel >/dev/null; \
90+
cp $(BIN_DIR)/$(BINARY)-zyxel /ffp/bin/$(BINARY); \
91+
chmod +x /ffp/bin/$(BINARY); \
92+
echo "$(GREEN)✔ Installed to /ffp/bin/$(BINARY)$(RESET)"; \
93+
elif [ -d "/data/data/com.termux/files/usr" ]; then \
94+
echo "$(CYAN)[+] Detected Termux/Android environment$(RESET)"; \
95+
$(MAKE) termux >/dev/null; \
96+
cp $(BIN_DIR)/$(BINARY)-termux /data/data/com.termux/files/usr/bin/$(BINARY); \
97+
chmod +x /data/data/com.termux/files/usr/bin/$(BINARY); \
98+
echo "$(GREEN)✔ Installed to /data/data/com.termux/files/usr/bin/$(BINARY)$(RESET)"; \
99+
else \
100+
echo "$(CYAN)[+] Detected native Linux system$(RESET)"; \
101+
$(MAKE) native >/dev/null; \
102+
sudo cp $(BIN_DIR)/$(BINARY)-native /usr/local/bin/$(BINARY); \
103+
echo "$(GREEN)✔ Installed to /usr/local/bin/$(BINARY)$(RESET)"; \
104+
fi
105+
91106
# Clean target
92-
# ---------------------------
93-
.PHONY: clean
94107
clean:
95-
@echo "$(RED)Removing $(BIN_DIR)...$(NC)"
96-
@rm -rf $(BIN_DIR)
108+
@echo "$(CYAN)[*] Cleaning build artifacts...$(RESET)"
109+
rm -rf $(BIN_DIR)
110+
@echo "$(GREEN)✔ Clean complete.$(RESET)"

README.md

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,100 @@
1-
# Storage Usage Monitor
1+
# Storage Monitor (Go)
22

3-
A lightweight Go utility that displays storage usage information with a visual progress bar and color-coded output for easy monitoring.
3+
A lightweight **Go** program that displays storage usage across multiple devices — including **Android**, **tablets**, and **ZyXEL NAS** systems — with automatic detection of **USB drives** connected to ZyXEL NAS (`/e-data`).
44

5-
## Features
5+
This project preserves the original code structure while extending it with dynamic USB detection on ZyXEL devices running **FFP (fonz_fun_plug)**.
66

7-
- 📊 Visual storage usage representation with progress bars
8-
- 🎨 Color-coded output for better readability
9-
- 📱 Supports multiple storage devices (internal, external, RAID arrays)
10-
- 🔢 Displays total, used, and free space in appropriate units
11-
- 🖥️ Clean, formatted output for terminal viewing
7+
---
128

13-
## Supported Storage Types
9+
## 📦 Features
1410

15-
- Android internal storage
16-
- SD cards
17-
- RAID arrays (md devices)
18-
- Any mountable storage device
11+
- Displays formatted storage information for:
12+
- **Redmi** internal and SD card paths
13+
- **Android tablet** storage
14+
- **ZyXEL NAS** RAID volumes (`/dev/md0`, `/dev/md1`)
15+
- **Automatically detected USB drives** in `/e-data`
16+
- Uses `df` to gather disk stats (works on Linux and embedded NAS systems)
17+
- Shows color-coded bar charts with usage percentage
18+
- Designed to run on **low-resource environments** (ARMv5 ZyXEL NAS)
19+
- ANSI color support for clean, readable terminal output
1920

20-
## Installation
21+
---
2122

22-
1. Ensure you have Go installed on your system
23-
2. Clone or download this repository
24-
3. Build the executable:
25-
```bash
26-
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -trimpath -v -x -o ./bin/storage ./main.go
27-
```
23+
## 🧠 How It Works
2824

29-
Usage
25+
1. A static list of known storage paths is defined (Android + ZyXEL HDDs).
26+
2. The function `detectZyXELUSB()` lists the `/e-data` directory to find all connected USB devices automatically.
27+
3. Each found mount is appended to the main storage list.
28+
4. For each storage path, `df` is executed to retrieve capacity and usage data.
29+
5. The information is displayed as a colored usage bar and numerical summary.
3030

31-
Run the compiled binary:
31+
---
3232

33+
## ⚙️ Requirements
34+
35+
- **Go 1.19+**
36+
- Works on:
37+
- Linux (x86 / ARM / ARMv5 / ARMv7)
38+
- Android (via Termux)
39+
- ZyXEL NAS with FFP (fonz_fun_plug)
40+
41+
Ensure that:
42+
- `/e-data` exists (for ZyXEL USB devices)
43+
- `df` and `ls` commands are available in your system PATH
44+
45+
---
46+
47+
## 🚀 Usage
48+
49+
### Run directly:
3350
```bash
51+
go run main.go
52+
53+
Build binary:
54+
55+
go build -o storage main.go
56+
57+
Run the binary:
58+
3459
./storage
35-
```
3660

37-
Output Example
3861

39-
```
40-
=== Úložiště ===
41-
Interní úložiště
42-
############################## 85% used
43-
Total: 64 G | Used: 54 G | Free: 10240 M
62+
---
63+
64+
📁 Directory Detection Logic (ZyXEL USB)
65+
66+
The ZyXEL USB devices are mounted under /e-data/ with directories named after the device UUID or label.
67+
For example:
68+
69+
/e-data/af5af4bc-aed3-4497-9663-9e2c60bbd5cb
70+
/e-data/68E0-DADB
71+
72+
The program dynamically lists these entries and adds them to the monitored storages list, labeling them as USB: <directory>.
73+
74+
75+
---
76+
77+
🧩 Future Enhancements
78+
79+
Auto-detect USB labels via blkid
80+
81+
Shorten UUID display (e.g., USB: af5af)
82+
83+
Include network mounts (/mnt/nfs, /mnt/smb)
84+
85+
JSON output mode for integration with dashboards
86+
87+
88+
89+
---
4490

45-
SD karta
46-
################## 60% used
47-
Total: 128 G | Used: 77 G | Free: 51200 M
48-
```
91+
🧑‍💻 Author
4992

50-
Customization
93+
Jonáš Nedvědický (PhateValleyman)
94+
Maintained as part of embedded utilities for ARM-based systems.
5195

52-
To monitor different storage paths, edit the storages slice in the main() function:
5396

54-
```go
55-
storages := []Storage{
56-
{"/path/to/your/storage", "Custom Label"},
57-
{"/another/path", "Another Label"},
58-
}
59-
```
97+
---
6098

61-
Requirements
6299

63-
· Go 1.11 or higher
64-
· Linux/Unix-like system with df command available
65-
· Terminal that supports ANSI color codes
66100

0 commit comments

Comments
 (0)