blob: e7387433c251fbf02214c5d85552a0862fb884eb (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#!/bin/bash
VERSION="1.0.0 (SysBoost)"
LOG_FILE="$HOME/.sysboost.log"
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}
is_docker() {
[[ -f /.dockerenv ]]
}
show_help() {
cat << EOF
Linux System Optimizer -
Usage:
sysboost --clean Clean junk files
sysboost --optimize-ram Optimize RAM
sysboost --optimize-cpu Optimize CPU
sysboost --schedule enable Enable scheduled optimization
sysboost --schedule disable Disable scheduled optimization
sysboost --uninstall Remove sysboost and clean up
sysboost --version Show version
sysboost --help Show this help message
EOF
}
clean_junk() {
log "Cleaning junk files..."
if command -v pacman &>/dev/null; then
sudo pacman -Sc --noconfirm
elif command -v apt &>/dev/null; then
sudo apt autoremove -y && sudo apt clean
elif command -v dnf &>/dev/null; then
sudo dnf autoremove -y && sudo dnf clean all
elif command -v zypper &>/dev/null; then
sudo zypper clean --all
else
log "No supported package manager found."
fi
if command -v journalctl &>/dev/null; then
sudo journalctl --vacuum-time=7d
else
log "Skipping journal cleanup (journalctl not found)"
fi
log "Junk cleanup completed."
}
optimize_ram() {
log "Optimizing RAM..."
if is_docker; then
log "Skipping RAM optimization (Docker detected)"
return
fi
echo 3 | sudo tee /proc/sys/vm/drop_caches
if swapon --summary | grep -q "swap"; then
sudo swapoff -a && sudo swapon -a
else
log "No swap found, skipping."
fi
log "RAM optimization completed."
}
optimize_cpu() {
log "Optimizing CPU..."
if is_docker; then
log "Skipping CPU optimization (Docker detected)"
return
fi
if command -v systemctl &>/dev/null; then
for service in bluetooth.service cups.service avahi-daemon.service ModemManager.service; do
if systemctl is-active --quiet "$service"; then
sudo systemctl stop "$service"
log "Stopped $service"
fi
done
else
log "Skipping CPU optimization (systemctl not found)"
fi
log "CPU optimization completed."
}
enable_schedule() {
log "Enabling scheduled optimization..."
if is_docker; then
log "Skipping scheduled optimization (Docker detected)"
return
fi
(crontab -l 2>/dev/null; echo "0 3 * * * /usr/bin/linuxboot --clean") | crontab -
log "Scheduled optimization enabled (Runs daily at 3 AM)."
}
disable_schedule() {
log "Disabling scheduled optimization..."
if is_docker; then
log "Skipping scheduled optimization (Docker detected)"
return
fi
crontab -l 2>/dev/null | grep -v '/usr/bin/linuxboot' | crontab -
log "Scheduled optimization disabled."
}
uninstall() {
log "Uninstalling Linuxboot..."
sudo rm -f /usr/bin/linuxboot
sudo rm -f "$LOG_FILE"
crontab -l 2>/dev/null | grep -v '/usr/bin/linuxboot' | crontab -
log "Linuxboot has been uninstalled."
}
case "$1" in
--clean) clean_junk ;;
--optimize-ram) optimize_ram ;;
--optimize-cpu) optimize_cpu ;;
--schedule)
case "$2" in
enable) enable_schedule ;;
disable) disable_schedule ;;
*) echo "Invalid schedule option. Use 'enable' or 'disable'." ;;
esac
;;
--uninstall) uninstall ;;
--version) echo "Linux System Optimizer v$VERSION" ;;
--help) show_help ;;
*)
echo "Invalid option. Use --help for usage."
exit 1
;;
esac
|