forked from azlux/log2ram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·65 lines (55 loc) · 2.23 KB
/
install.sh
File metadata and controls
executable file
·65 lines (55 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
systemctl -q is-active log2ram && {
echo "ERROR: log2ram service is still running. Please run \"sudo systemctl stop log2ram\" to stop it."
exit 1
}
[ "$(id -u)" -eq 0 ] || {
echo "You need to be ROOT (sudo can be used)"
exit 1
}
# log2ram
mkdir -p /usr/local/bin/
install -m 644 log2ram.service /etc/systemd/system/log2ram.service
install -m 644 log2ram-daily.service /etc/systemd/system/log2ram-daily.service
install -m 644 log2ram-daily.timer /etc/systemd/system/log2ram-daily.timer
install -m 755 log2ram /usr/local/bin/log2ram
if [ ! -f /etc/log2ram.conf ]; then
install -m 644 log2ram.conf /etc/log2ram.conf
fi
install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh
systemctl enable log2ram.service log2ram-daily.timer
# logrotate
if [ -d /etc/logrotate.d ]; then
install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram
else
echo "##### Directory /etc/logrotate.d does not exist. #####"
echo "##### Skipping log2ram.logrotate installation. #####"
fi
# Remove a previous log2ram version
rm -rf /var/log.hdd
# Make sure we start clean
rm -rf /var/hdd.log
# Include config to check if size is enought (See below)
source /etc/log2ram.conf
# Validates that the SIZE variable is defined in the log2ram configuration file.
# Exits with an error message if the SIZE variable is not set, preventing further installation.
if [ -z "$SIZE" ]; then
echo "ERROR: SIZE variable is not defined in /etc/log2ram.conf"
exit 1
fi
# Checks if the size of /var/log exceeds the specified SIZE threshold
# Returns an error if the size check fails or if the directory cannot be measured
# Exits the script with an error message if du command encounters issues
if ! du_output=$(du -sh -t "$SIZE" /var/log 2>/dev/null); then
echo "ERROR: Failed to check size of /var/log"
exit 1
fi
# Check if var SIZE is sufficient and show a warning when too small
if [ -n "$du_output" ] ; then
echo 'WARNING: Variable SIZE in /etc/log2ram.conf is too small to store the /var/log!'
echo -n 'Actual size of /var/log is:'
du -sh /var/log
echo -e '\nPlease increase SIZE in /etc/log2ram.conf to avoid issues'
fi
echo "##### Reboot to activate log2ram #####"
echo "##### edit /etc/log2ram.conf to configure options ####"