Skip to content

Commit 0d3cf5a

Browse files
committed
Assorted consistency tweaks
1 parent 4165c30 commit 0d3cf5a

File tree

12 files changed

+196
-168
lines changed

12 files changed

+196
-168
lines changed

.shellcheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enable=require-variable-braces

build-packages.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
#!/usr/bin/env bash
22

33
# Exit the script if any of the commands fail
4-
set -e
5-
set -u
6-
set -o pipefail
4+
set -euo pipefail
75

86
# Set working directory to the location of this script
97
cd "$(dirname "${BASH_SOURCE[0]}")"
108

119
STARTDIR="$(pwd)"
12-
DESTDIR="$STARTDIR/pkg"
13-
OUTDIR="$STARTDIR/deb"
10+
DESTDIR="${STARTDIR}/pkg"
11+
OUTDIR="${STARTDIR}/deb"
1412
# get version
1513
repo="azlux/log2ram"
16-
api=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq ".[0]")
17-
new=$(echo $api | grep -Po '"tag_name": "\K.*?(?=")')
14+
api=$(curl -sSfL --compressed "https://api.github.com/repos/${repo}/releases" | jq ".[0]")
15+
new=$(echo "${api}" | grep -Po '"tag_name": "\K.*?(?=")')
16+
17+
if [[ -z "${new}" ]]; then
18+
echo "Error: Failed to fetch release version from GitHub."
19+
exit 1
20+
fi
1821

1922
# Remove potential leftovers from a previous build
20-
rm -rf "$DESTDIR" "$OUTDIR"
23+
rm -rf "${DESTDIR}" "${OUTDIR}"
2124

2225
## log2ram
2326
# Create directory
24-
install -Dm 644 "$STARTDIR/log2ram.service" "$DESTDIR/etc/systemd/system/log2ram.service"
25-
install -Dm 644 "$STARTDIR/log2ram-daily.service" "$DESTDIR/etc/systemd/system/log2ram-daily.service"
26-
install -Dm 644 "$STARTDIR/log2ram-daily.timer" "$DESTDIR/etc/systemd/system/log2ram-daily.timer"
27-
install -Dm 755 "$STARTDIR/log2ram" "$DESTDIR/usr/local/bin/log2ram"
28-
install -Dm 644 "$STARTDIR/log2ram.conf" "$DESTDIR/etc/log2ram.conf"
29-
install -Dm 644 "$STARTDIR/uninstall.sh" "$DESTDIR/usr/local/bin/uninstall-log2ram.sh"
27+
install -Dm 644 "${STARTDIR}/log2ram.service" "${DESTDIR}/etc/systemd/system/log2ram.service"
28+
install -Dm 644 "${STARTDIR}/log2ram-daily.service" "${DESTDIR}/etc/systemd/system/log2ram-daily.service"
29+
install -Dm 644 "${STARTDIR}/log2ram-daily.timer" "${DESTDIR}/etc/systemd/system/log2ram-daily.timer"
30+
install -Dm 755 "${STARTDIR}/log2ram" "${DESTDIR}/usr/local/bin/log2ram"
31+
install -Dm 644 "${STARTDIR}/log2ram.conf" "${DESTDIR}/etc/log2ram.conf"
32+
install -Dm 644 "${STARTDIR}/uninstall.sh" "${DESTDIR}/usr/local/bin/uninstall-log2ram.sh"
3033

3134
# logrotate
32-
install -Dm 644 "$STARTDIR/log2ram.logrotate" "$DESTDIR/etc/logrotate.d/log2ram"
35+
install -Dm 644 "${STARTDIR}/log2ram.logrotate" "${DESTDIR}/etc/logrotate.d/log2ram"
3336

3437
# Build .deb
35-
mkdir "$DESTDIR/DEBIAN" "$OUTDIR"
36-
cp "$STARTDIR/debian/"* "$DESTDIR/DEBIAN/"
38+
mkdir "${DESTDIR}/DEBIAN" "${OUTDIR}"
39+
cp "${STARTDIR}/debian/"* "${DESTDIR}/DEBIAN/"
3740

3841
# Set version
39-
sed -i "s/VERSION-TO-REPLACE/$new/" "$DESTDIR/DEBIAN/control"
42+
sed -i "s/VERSION-TO-REPLACE/${new}/" "${DESTDIR}/DEBIAN/control"
4043

41-
dpkg-deb --build "$DESTDIR" "$OUTDIR"
44+
dpkg-deb --build "${DESTDIR}" "${OUTDIR}"

debian/postinst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env bash
2+
23
set -euo pipefail
34

45
systemctl daemon-reload
56
systemctl enable log2ram.service log2ram-daily.timer
67

7-
88
rm -f /etc/cron.daily/log2ram
99
rm -f /etc/cron.hourly/log2ram
1010

11-
if [ "$1" == "configure" ]; then
12-
echo "##### Reboot to activate log2ram #####"
13-
echo "##### edit /etc/log2ram.conf to configure options ####"
11+
if [[ "$1" == "configure" ]]; then
12+
echo "##### Reboot to activate log2ram #####"
13+
echo "##### edit /etc/log2ram.conf to configure options ####"
1414
fi
1515

1616
exit 0

debian/preinst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
2-
systemctl -q is-active log2ram.service && systemctl stop log2ram.service
3-
systemctl -q is-active log2ram-daily.timer && systemctl stop log2ram-daily.timer
2+
3+
systemctl -q is-active log2ram.service && systemctl stop log2ram.service
4+
systemctl -q is-active log2ram-daily.timer && systemctl stop log2ram-daily.timer
5+
46
rm -rf /var/hdd.log
57

68
exit 0

debian/prerm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env bash
2+
23
case "$1" in
3-
upgrade)
4-
[ -d /run/systemd/system/ ] && systemctl stop log2ram.service log2ram-daily.timer
5-
exit 0
6-
;;
7-
*)
8-
[ -d /run/systemd/system/ ] && systemctl stop log2ram.service log2ram-daily.timer
9-
[ -d /run/systemd/system/ ] && systemctl disable log2ram.service log2ram-daily.timer
10-
exit 0
11-
;;
4+
upgrade)
5+
[[ -d /run/systemd/system/ ]] && systemctl stop log2ram.service log2ram-daily.timer
6+
exit 0
7+
;;
8+
*)
9+
[[ -d /run/systemd/system/ ]] && systemctl stop log2ram.service log2ram-daily.timer
10+
[[ -d /run/systemd/system/ ]] && systemctl disable log2ram.service log2ram-daily.timer
11+
exit 0
12+
;;
1213
esac

install.sh

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
#!/usr/bin/env bash
22

3-
systemctl -q is-active log2ram && {
4-
echo "ERROR: log2ram service is still running. Please run \"sudo systemctl stop log2ram\" to stop it."
5-
exit 1
6-
}
7-
[ "$(id -u)" -eq 0 ] || {
3+
if [[ "$(id -u)" -ne 0 ]]; then
84
echo "You need to be ROOT (sudo can be used)"
95
exit 1
10-
}
6+
fi
7+
8+
if systemctl -q is-active log2ram; then
9+
echo "ERROR: log2ram service is still running. Please run \"sudo systemctl stop log2ram\" to stop it."
10+
exit 1
11+
fi
1112

1213
# log2ram
1314
mkdir -p /usr/local/bin/
1415
install -m 644 log2ram.service /etc/systemd/system/log2ram.service
1516
install -m 644 log2ram-daily.service /etc/systemd/system/log2ram-daily.service
1617
install -m 644 log2ram-daily.timer /etc/systemd/system/log2ram-daily.timer
18+
install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh
1719
install -m 755 log2ram /usr/local/bin/log2ram
18-
if [ ! -f /etc/log2ram.conf ]; then
20+
21+
# Install config if not already present
22+
if [[ ! -f /etc/log2ram.conf ]]; then
1923
install -m 644 log2ram.conf /etc/log2ram.conf
2024
fi
21-
install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh
25+
2226
systemctl enable log2ram.service log2ram-daily.timer
2327

2428
# logrotate
25-
if [ -d /etc/logrotate.d ]; then
29+
if [[ -d /etc/logrotate.d ]]; then
2630
install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram
2731
else
2832
echo "##### Directory /etc/logrotate.d does not exist. #####"
@@ -36,29 +40,30 @@ rm -rf /var/log.hdd
3640
rm -rf /var/hdd.log
3741

3842
# Include config to check if size is enought (See below)
39-
source /etc/log2ram.conf
43+
# shellcheck disable=SC1091
44+
. /etc/log2ram.conf
4045

4146
# Validates that the SIZE variable is defined in the log2ram configuration file.
4247
# Exits with an error message if the SIZE variable is not set, preventing further installation.
43-
if [ -z "$SIZE" ]; then
44-
echo "ERROR: SIZE variable is not defined in /etc/log2ram.conf"
45-
exit 1
48+
if [[ -z "${SIZE}" ]]; then
49+
echo "ERROR: SIZE variable is not defined in /etc/log2ram.conf"
50+
exit 1
4651
fi
4752

4853
# Checks if the size of /var/log exceeds the specified SIZE threshold
4954
# Returns an error if the size check fails or if the directory cannot be measured
5055
# Exits the script with an error message if du command encounters issues
51-
if ! du_output=$(du -sh -t "$SIZE" /var/log 2>/dev/null); then
52-
echo "ERROR: Failed to check size of /var/log"
53-
exit 1
56+
if ! du_output=$(du -sh -t "${SIZE}" /var/log 2>/dev/null); then
57+
echo "ERROR: Failed to check size of /var/log"
58+
exit 1
5459
fi
5560

5661
# Check if var SIZE is sufficient and show a warning when too small
57-
if [ -n "$du_output" ] ; then
58-
echo 'WARNING: Variable SIZE in /etc/log2ram.conf is too small to store the /var/log!'
59-
echo -n 'Actual size of /var/log is:'
60-
du -sh /var/log
61-
echo -e '\nPlease increase SIZE in /etc/log2ram.conf to avoid issues'
62+
if [[ -n "${du_output}" ]]; then
63+
echo 'WARNING: Variable SIZE in /etc/log2ram.conf is too small to store the /var/log!'
64+
echo -n 'Actual size of /var/log is:'
65+
du -sh /var/log
66+
echo -e '\nPlease increase SIZE in /etc/log2ram.conf to avoid issues'
6267
fi
6368

6469
echo "##### Reboot to activate log2ram #####"

0 commit comments

Comments
 (0)