-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.sh
executable file
·47 lines (40 loc) · 1.67 KB
/
service.sh
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
#!/system/bin/sh
# Copyright (C) 2020 Atrate <atrate@protonmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
LOGFILE='/cache/fstrimmer_lastrun.log'
# Sleep for 2 minutes due to a lot of I/O happening shortly after boot
# -------------------------------------------------------------------
sleep 120
# Clear fstrimmer_lastrun.log. After all, it's the LAST run log.
# --------------------------------------------------------------
echo -n > "$LOGFILE"
# Perform checks for root and busybox. Set all commands' prefix to busybox in case commands are not symlinked properly
# --------------------------------------------------------------------------------------------------------------------
if [[ $(id -u) -ne 0 ]]; then
echo "This script needs to be run as root!" | tee "$LOGFILE"
exit 1
fi
if [ -x /system/bin/busybox ]; then
BUSYBOX='/system/bin/busybox'
elif [ -x /system/xbin/busybox ]; then
BUSYBOX='/system/xbin/busybox'
else
echo "This script requires BusyBox to be installed in either /system/bin or /system/xbin!" | tee "$LOGFILE"
exit 1
fi
# Now for the real thing
# ----------------------
for PARTITION in "/cache" "/data" "/system" "/"
do
echo "Trimming $PARTITION" | tee -a "$LOGFILE"
"$BUSYBOX" fstrim -v "$PARTITION" 2>&1 | tee -a "$LOGFILE"
done
exit 0