forked from kdave/btrfsmaintenance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtrfsmaintenance-refresh-cron.sh
executable file
·58 lines (49 loc) · 1.37 KB
/
btrfsmaintenance-refresh-cron.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
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#
# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany.
#
# please send bugfixes or comments to http://www.suse.de/feedback.
# Adjust symlinks of btrfs maintenance services according to the configs.
# Run with 'uninstall' to remove them again
#
# paranoia settings
#
umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
SCRIPTS=/usr/share/btrfsmaintenance
if [ "$1" = 'uninstall' ]; then
for SCRIPT in btrfs-scrub.sh btrfs-defrag.sh btrfs-balance.sh btrfs-trim.sh; do
for PERIOD in daily weekly monthly; do
LINK="${SCRIPT%.*}"
FILE="/etc/cron.$PERIOD/$LINK"
rm -f "$FILE"
done
done
exit 0
fi
if [ -f /etc/sysconfig/btrfsmaintenance ]; then
. /etc/sysconfig/btrfsmaintenance
fi
if [ -f /etc/default/btrfsmaintenance ]; then
. /etc/default/btrfsmaintenance
fi
refresh_period() {
EXPECTED="$1"
SCRIPT="$2"
echo "Refresh script $SCRIPT for $EXPECTED"
for PERIOD in daily weekly monthly; do
# NOTE: debian does not allow filenames with dots in /etc/cron.*
LINK="${SCRIPT%.*}"
FILE="/etc/cron.$PERIOD/$LINK"
if [ "$PERIOD" = "$EXPECTED" ]; then
ln -sf "$SCRIPTS/$SCRIPT" "$FILE"
else
rm -f "$FILE"
fi
done
}
refresh_period "$BTRFS_SCRUB_PERIOD" btrfs-scrub.sh
refresh_period "$BTRFS_DEFRAG_PERIOD" btrfs-defrag.sh
refresh_period "$BTRFS_BALANCE_PERIOD" btrfs-balance.sh
refresh_period "$BTRFS_TRIM_PERIOD" btrfs-trim.sh