|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright (c) 2023 The Toltec Contributors |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +pkgnames=(move-logs-to-opt) |
| 6 | +pkgdesc="Move log files to /opt to save space on the root partition" |
| 7 | +url=https://github.com/toltec-dev/toltec |
| 8 | +pkgver=0.0.1-1 |
| 9 | +timestamp=2024-01-07T23:55Z |
| 10 | +section="utils" |
| 11 | +maintainer= "Eeems <[email protected]>" |
| 12 | +license=MIT |
| 13 | + |
| 14 | +source=(var-log.mount) |
| 15 | +sha256sums=(SKIP) |
| 16 | + |
| 17 | +package() { |
| 18 | + mkdir -p "$pkgdir"/opt/var/log |
| 19 | + install -D -m 644 -t "$pkgdir"/lib/systemd/system/ "$srcdir"/var-log.mount |
| 20 | +} |
| 21 | + |
| 22 | +configure() { |
| 23 | + systemctl daemon-reload |
| 24 | + if is-active systemd-journald.service; then |
| 25 | + journalctl --sync --flush |
| 26 | + systemctl stop systemd-journald.service |
| 27 | + fi |
| 28 | + if ! mountpoint -q /var/log; then |
| 29 | + echo "Moving log files to new location" |
| 30 | + local target_path=/home/root/.entware/var/log |
| 31 | + mkdir -p "$target_path" |
| 32 | + cp -af "/var/log/." "$target_path" |
| 33 | + rm -rf "/var/log/"* |
| 34 | + fi |
| 35 | + if ! is-enabled "var-log.mount"; then |
| 36 | + systemctl enable "var-log.mount" |
| 37 | + fi |
| 38 | + systemctl restart "var-log.mount" |
| 39 | + systemctl start systemd-journald.service |
| 40 | +} |
| 41 | + |
| 42 | +preremove() { |
| 43 | + if is-active systemd-journald.service; then |
| 44 | + journalctl --sync --flush |
| 45 | + systemctl stop systemd-journald.service |
| 46 | + fi |
| 47 | + disable-unit "var-log.mount" |
| 48 | +} |
| 49 | + |
| 50 | +postremove() { |
| 51 | + systemctl daemon-reload |
| 52 | + systemctl start systemd-journald.service |
| 53 | + if mountpoint -q /var/log; then |
| 54 | + umount -l /var/log |
| 55 | + fi |
| 56 | +} |
0 commit comments