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
1314mkdir -p /usr/local/bin/
1415install -m 644 log2ram.service /etc/systemd/system/log2ram.service
1516install -m 644 log2ram-daily.service /etc/systemd/system/log2ram-daily.service
1617install -m 644 log2ram-daily.timer /etc/systemd/system/log2ram-daily.timer
18+ install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh
1719install -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
2024fi
21- install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh
25+
2226systemctl 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
2731else
2832 echo " ##### Directory /etc/logrotate.d does not exist. #####"
@@ -36,29 +40,30 @@ rm -rf /var/log.hdd
3640rm -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
4651fi
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
5459fi
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'
6267fi
6368
6469echo " ##### Reboot to activate log2ram #####"
0 commit comments