Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,34 @@ After a verified download, `download-content.sh` keeps the publisher's matching

The script skips `.part` files. It exits with `0` if every archive passes, `1` if a check fails, or `2` if the check cannot start, for example when there are no complete ZIM files.

### Heartbeat (optional)

When the box connects to the internet, it sends a “I’m alive” signal to a service of your choice. If the signals stop arriving for a certain period, that service sends an alert, allowing you to remotely detect that the box has gone down.

```bash
sudo ./scripts/install-heartbeat.sh
```

When the script is run again, the existing settings become the default answers to the prompts. Press Enter to keep the current value. Settings are stored in `/etc/has-heartbeat.conf`. You can manually edit `url`, `format`, `method`, `headers`, `query`, `body`, `warnings`, `metrics`, and `box_id` (changes take effect with the next heartbeat). To change `interval`, you must run the script again.
To disable the feature, run the script again and enter `off` when prompted for the URL.
To test: `sudo ./scripts/heartbeat.sh`
Logs: `journalctl -u has-heartbeat.service`

For a custom API, configure `method`, `headers`, and a `query` or `body` template in `/etc/has-heartbeat.conf`.
The following variables are replaced with escaped values:
`{status}` (up/down), `{msg}`, `{box}`, `{uptime}`, `{disk}` (%), `{cpu}` (°C)

```bash
url="https://monitor.example.com/api/box"
method="POST"
headers=("Authorization: Bearer token")
body='{"status":"{status}","message":"{msg}"}'
```

`query` builds the part after the `?` of the URL (e.g. `query="durum={status}&mesaj={msg}"`), `body` becomes the request body, and `method` defaults to GET for `params`, POST for `json` and POST when `body` is set. Values in `query` are percent-encoded and values in `body` are JSON-escaped automatically. When `query` or `body` is set, `format` is ignored.

Note for dead-man's-switch services (healthchecks.io and similar): every ping counts as success, so `status=down` is only informational there. The alert is triggered by the signals stopping. For an instant disk-warning alert, use a service that reads the status (e.g. a Uptime Kuma push monitor) or a custom API that has a failure endpoint.

### Repo layout

```
Expand All @@ -133,8 +161,10 @@ scripts/install-homepage.sh installs the custom homepage
scripts/status.sh health check: disk, services, hotspot, content, power
scripts/verify-content.sh offline ZIM checksum check
scripts/disk-health.sh disk and power health check (saglik/: its systemd timer)
scripts/install-heartbeat.sh (optional) installs the heartbeat
config/iiab-overrides.yml Internet-in-a-Box settings
config/content.conf list of content to download
config/heartbeat.conf heartbeat settings
www/home/index.html homepage
www/home/acil.html emergency page (Turkish, sourced from AFAD and EPA)
```
Expand Down Expand Up @@ -176,6 +206,7 @@ It checks free space on the SD card and SSD, the web, Kiwix, hotspot and DHCP se
`br0` should now be UP with 10.10.10.10 and `wlan0` should show `state forwarding`.
- **SSH without a cable:** join the Pi's hotspot and use `ssh user@10.10.10.10`.
- **Restoring the original homepage:** `sudo cp /library/www/html/home/index.html.iiab-original /library/www/html/home/index.html`
- **No heartbeat signal arrives.** While the box is offline that is normal. When it has internet, test with `sudo ./scripts/heartbeat.sh` and check `journalctl -u has-heartbeat.service -n 20`. If `/etc/has-heartbeat.conf` has an empty `url`, the heartbeat is disabled; re-run `sudo ./scripts/install-heartbeat.sh`.

### License

Expand Down Expand Up @@ -276,6 +307,29 @@ Hemen kontrol: `sudo ./scripts/disk-health.sh`. Bazı USB adaptörlerinin arkas

Betik `.part` dosyalarını atlar. Tüm arşivler geçerse `0`, bir kontrol başarısız olursa `1`, kontrol başlayamazsa `2` döner. Örneğin klasörde tamamlanmış ZIM yoksa sonuç `2` olur.

### Heartbeat (isteğe bağlı)

Kutu internete çıktığında seçtiğin bir servise "çalışıyorum" sinyali yollar. Sinyaller belirli süre gelmezse o servis uyarır ve kutunun düştüğünü uzaktan öğrenirsin.

```bash
sudo ./scripts/install-heartbeat.sh
```

Betik tekrar çalıştırıldığında mevcut ayarlar soruların varsayılanı olur; değeri korumak için Enter'a bas. Ayarlar `/etc/has-heartbeat.conf` dosyasında durur. `url`, `format`, `method`, `headers`, `query`, `body`, `warnings`, `metrics` ve `box_id` elle düzenlenebilir (bir sonraki sinyalde geçerli olur), `interval`'ı değiştirmek için betiği tekrar çalıştırmak gerekir. Özelliği kapatmak için betiği tekrar çalıştır ve URL sorusuna `off` yaz.
Test: `sudo ./scripts/heartbeat.sh`.
Loglar: `journalctl -u has-heartbeat.service`.

Özel bir API için `/etc/has-heartbeat.conf` dosyasında `method`, `headers` ve bir `query` ya da `body` şablonu belirle. `{status}` (up/down), `{msg}`, `{box}`, `{uptime}`, `{disk}` (%) ve `{cpu}` (°C) değişkenleri escaped değerlerle değiştirilir:

```bash
url="https://monitor.example.com/api/box"
method="POST"
headers=("Authorization: Bearer token")
body='{"durum":"{status}","mesaj":"{msg}"}'
```

Not: healthchecks.io gibi "dead man's switch" servislerinde her ping başarı sayılır; orada `status=down` yalnızca bilgilendirmedir, uyarı sinyallerin kesilmesiyle tetiklenir. Disk uyarısının anında alarm üretmesini istiyorsan status'u okuyan bir servis kullan (ör. Uptime Kuma push monitörü) ya da failure endpoint'i olan bir API'ye `query`/`body` ile bağlan. `query` URL'nin `?` sonrasını kurar, `body` isteğin gövdesi olur; `query` değerleri percent-encoded, `body` değerleri JSON-escaped gönderilir. `method` `params` için GET, `json` ve `body` dolu için POST olur.

### Repo yapısı

```
Expand All @@ -286,8 +340,10 @@ scripts/install-homepage.sh özel ana sayfayı kurar
scripts/status.sh sağlık kontrolü: disk, servisler, hotspot, içerik, güç
scripts/verify-content.sh çevrimdışı ZIM sağlama kontrolü
scripts/disk-health.sh disk ve güç sağlığı denetimi (saglik/: systemd zamanlayıcısı)
scripts/install-heartbeat.sh (isteğe bağlı) heartbeat kurar
config/iiab-overrides.yml Internet-in-a-Box ayarları
config/content.conf indirilecek içerik listesi
config/heartbeat.conf heartbeat ayarları
www/home/index.html ana sayfa
www/home/acil.html acil durum sayfası (AFAD ve EPA kaynaklı)
```
Expand Down Expand Up @@ -329,6 +385,7 @@ SD kart ve SSD'deki boş alanı, web, Kiwix, hotspot ve DHCP servislerini, hotsp
Artık `br0` 10.10.10.10 adresiyle UP, `wlan0` da `state forwarding` görünmeli.
- **Kablosuz SSH:** Pi'nin hotspot'una bağlan ve `ssh kullanici@10.10.10.10` kullan.
- **Orijinal ana sayfaya dönmek için:** `sudo cp /library/www/html/home/index.html.iiab-original /library/www/html/home/index.html`
- **Heartbeat sinyali gitmiyor.** Kutu internetsizken bu normaldir. İnterneti olduğunda `sudo ./scripts/heartbeat.sh` ile test et ve `journalctl -u has-heartbeat.service -n 20` kaydına bak. `/etc/has-heartbeat.conf` içinde `url` boşsa nabız kapalıdır; `sudo ./scripts/install-heartbeat.sh`'ı tekrar çalıştır.

### Lisans

Expand Down
63 changes: 63 additions & 0 deletions config/heartbeat.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# HAS_PrepperDisk uzaktan nabız ayarları / remote heartbeat settings
# scripts/install-heartbeat.sh bu dosyayı /etc/has-heartbeat.conf'a yazar.
# It writes the settings to /etc/has-heartbeat.conf; on an installed box that file is live.
#
# url: sinyalin gideceği adres. Boş = nabız kapalı / empty = disabled.
# Değişkenler / variables:
# {status}: up | down {msg}: uyarı metni / warning text
# {box}: box_id {uptime}: örn. 3d12h / e.g. 3d12h
# {disk}: doluluk yüzdesi / disk usage percent
# {cpu}: sıcaklık, °C / temperature in °C (yoksa boş kalır / empty if unavailable)
# Examples:
# healthchecks.io : https://hc-ping.com/<uuid> format="params"
# Uptime Kuma : https://<kuma>/api/push/<token> (push monitor) format="params"
# Discord webhook : https://discord.com/api/webhooks/<id>/<token> format="json"
# Telegram : https://api.telegram.org/bot<token>/sendMessage?chat_id=<id> format="json"

url=""

# --- hazır biçimler / preset formats (yeni başlayanlar için / for beginners) ---
# params: sinyal ve uyarılar URL parametresi olarak gider (?status=up&msg=...)
# json: sinyal POST gövdesinde JSON olarak gider ({"content": ..., "text": ...})
# NOT: query ya da body doluysa format yok sayılır. / if query or body is set, format is ignored.
format="params"

# --- tam özelleştirme / full customization ---
# HTTP yöntemi; boşsa otomatik: preset biçimde params->GET, json->POST;
# query/body modunda body doluysa POST, yoksa GET.
# HTTP method; empty = auto: params->GET, json->POST in preset mode;
# in query/body mode POST when body is set, otherwise GET.
method=""

# HTTP başlıkları / headers:
# headers=("Authorization: Bearer token" "X-Box-ID: has1")
headers=()

# GET/POST sorgu şablonu / query template (URL'nin ? sonrası / after the ?):
# query="durum={status}&mesaj={msg}"
# Değerler otomatik percent-encode edilir / values are percent-encoded.
query=""

# Gövde şablonu / body template, örn. / e.g.:
# body='{"durum":"{status}","mesaj":"{msg}"}'
# Değerler otomatik JSON-escape edilir / values are JSON-escaped.
body=""

# --- veri seçimi / what to send ---
# disk.json'daki uyarılar sinyalle gitsin mi / send the disk.json warnings (1/0)?
# Uyarı varsa sinyal her durumda "down" gider; bu ayar yalnızca uyarı metninin
# sinyale eklenip eklenmeyeceğini belirler.
# If warnings exist the signal is "down" regardless; this only controls whether
# the warning text is included in the signal.
warnings=1

# temel metrikler de gitsin mi / also send basic metrics (1/0)?
# {uptime} {disk} {cpu} değişkenlerini doldurur / fills these variables
metrics=0

# isteğe bağlı kutu etiketi / optional box label, örn. "has1"
box_id=""

# systemd zamanlayıcı aralığı / systemd timer interval: 30min, 6h, 12h, 1d ...
# Değiştirmek için install-heartbeat.sh'ı tekrar çalıştır / re-run to change.
interval="6h"
13 changes: 10 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# HAS_PrepperDisk kurulum betiği / installer
# 1. Internet-in-a-Box ayarlarını hazırlar / prepares Internet-in-a-Box settings
# 2. Internet-in-a-Box'ı kurar / installs Internet-in-a-Box
# 3. HAS_PrepperDisk ana sayfasını kurar / installs the HAS_PrepperDisk homepage
# 3. Ana sayfayı, disk sağlığını ve (isteğe bağlı) heartbeat'i kurar /
# installs the homepage, disk health and (optional) heartbeat
#
# Kurulum sırasında Pi yeniden başlarsa bu betiği tekrar çalıştır.
# If the Pi reboots during install, just run this script again.
Expand Down Expand Up @@ -75,10 +76,15 @@ else
[ -f /etc/iiab/install-flags/iiab-complete ] || die "Kurulum bitmedi / install not finished. Tekrar çalıştır / run again: sudo ./install.sh"
fi

# -------------------------------------------------------------- 3. ana sayfa
say "3/3 Ana sayfa / homepage"
# -------------------------------------------------------------- 3. bileşenler
say "3/3 HAS_PrepperDisk bileşenleri / components"
"$REPO/scripts/install-homepage.sh"
"$REPO/scripts/install-disk-health.sh"
read -rp "Heartbeat kurulsun mu? / install heartbeat? [e/y/N] " HB || HB=""
case "$HB" in
e|E|y|Y) "$REPO/scripts/install-heartbeat.sh";;
*) echo "Atlandı, sonradan kurmak için / skipped, to install later: sudo ./scripts/install-heartbeat.sh";;
esac

say "Kurulum sonrası sağlık kontrolü / post-install health check"
echo "İçerikler henüz indirilmediyse ZIM uyarıları normaldir / ZIM warnings are expected before downloading content."
Expand All @@ -91,6 +97,7 @@ say "Bitti / done"
cat <<EOF
Ana sayfa / homepage: http://$IP/home (hotspot üzerinden / via hotspot: http://box.lan/home)
Yönetim / admin console: http://$IP/admin (kullanıcı / user: iiab-admin)
Heartbeat: sudo ./scripts/install-heartbeat.sh (kur veya değiştir / install or change)

Sıradaki adım / next step: içerikleri indir / download content
sudo ./scripts/download-content.sh
Expand Down
23 changes: 23 additions & 0 deletions saglik/has-heartbeat.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Unit]
Description=HAS_PrepperDisk: Heartbeat service

[Service]
Type=oneshot
Environment=HAS_HEARTBEAT_SAMPLE_CONF=
ExecStart=/usr/local/lib/has-heartbeat/heartbeat.sh

NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
SystemCallArchitectures=native
CapabilityBoundingSet=
9 changes: 9 additions & 0 deletions saglik/has-heartbeat.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=HAS_PrepperDisk: Heartbeat zamanlayıcı (@INTERVAL@'de bir) / heartbeat timer (every @INTERVAL@)

[Timer]
OnBootSec=5min
OnUnitActiveSec=@INTERVAL@

[Install]
WantedBy=timers.target
16 changes: 15 additions & 1 deletion scripts/disk-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,22 @@ if command -v vcgencmd >/dev/null; then
fi
fi

# escape
items=""
for w in "${warn[@]}"; do items+="${items:+,}\"$w\""; done
if command -v python3 >/dev/null 2>&1; then
items=$(python3 -c 'import json, sys
print(",".join(json.dumps(w) for w in sys.argv[1:]))' "${warn[@]}" 2>/dev/null) || items=""
fi
if [ -z "$items" ] && [ ${#warn[@]} -gt 0 ]; then
for w in "${warn[@]}"; do
w=${w//\\/\\\\}
w=${w//\"/\\\"}
w=${w//$'\n'/\\n}
w=${w//$'\r'/\\r}
w=${w//$'\t'/\\t}
items+="${items:+,}\"$w\""
done
fi
cat > "$OUT.tmp" <<EOF
{"checked":"$(date -Is)","warnings":[$items]}
EOF
Expand Down
Loading