|
| 1 | +# vim: set ft=make : |
| 2 | + |
| 3 | +# Reenable rmlint trim feature |
| 4 | +enable-rmlint ACTION="": |
| 5 | + #!/usr/bin/bash |
| 6 | + source /usr/lib/ujust/ujust.sh |
| 7 | + OPTION={{ ACTION }} |
| 8 | + if [[ ! -f "/etc/systemd/system/btrfs-dedup@.service.d/override.conf" ]]; then |
| 9 | + RMLINT_STATE="${red}${b}not enabled{n}" |
| 10 | + else |
| 11 | + RMLINT_STATE="${green}${b}already enabled${n}" |
| 12 | + fi |
| 13 | + if [ "$OPTION" == "help" ]; then |
| 14 | + echo "Usage: ujust enable-rmlint <option>" |
| 15 | + echo " <option>: Specify the quick option to skip the prompt" |
| 16 | + echo " Use 'enable' to reenable rmlint functionality" |
| 17 | + echo " Use 'disable' to revert to UBlue stock configuration (only duperemove is executed)" |
| 18 | + exit 0 |
| 19 | + elif [ "$OPTION" == "" ]; then |
| 20 | + echo "${bold}rmlint configuration${normal}" |
| 21 | + echo "rmlint conf is $RMLINT_STATE" |
| 22 | + OPTION=$(Choose "Enable rmlint" "Disable rmlint") |
| 23 | + fi |
| 24 | + if [[ "${OPTION,,}" =~ ^enable ]]; then |
| 25 | + if [[ "${RMLINT_STATE,,}" =~ "^already" ]]; then |
| 26 | + echo "${red} rmlint has already been enabled!" |
| 27 | + exit 0 |
| 28 | + fi |
| 29 | + ublue-update --wait |
| 30 | + rpm-ostree install --apply-live -y rmlint |
| 31 | + mkdir /etc/systemd/system/btrfs-dedup@.service.d/ |
| 32 | + bash -c 'cat << EOL > /etc/systemd/system/btrfs-dedup@.service.d/override.conf |
| 33 | + [Unit] |
| 34 | + Description=Btrfs deduplication on %f |
| 35 | + ConditionPathIsMountPoint=%f |
| 36 | + RequiresMountsFor=%f |
| 37 | + |
| 38 | + [Service] |
| 39 | + Type=oneshot |
| 40 | + MemoryHigh=1G |
| 41 | + ExecCondition=sh -c '[ "$(stat -f -c "%%T" "$1")" = btrfs ]' _ %f/ |
| 42 | + ExecStartPre=-find %f/ -mindepth 1 -maxdepth 1 -mtime +14 -name .duperemove.hash -exec rm -f '{}' \; |
| 43 | + ExecStartPre=-cp -a %f/.duperemove.hash duperemove.hash |
| 44 | + ExecStartPre=-compsize %f/ |
| 45 | + ExecStart=rmlint --hidden --types="duplicates" --config=sh:handler=clone %f/ |
| 46 | + ExecStart=sh -c 'exec ./rmlint.sh -d -p -r -k' |
| 47 | + ExecStart=-compsize %f/ |
| 48 | + ExecStart=-sh -c '[ "$(sqlite3 -readonly duperemove.hash "SELECT keyval FROM config where keyname=''version_major''")" -ge 4 ] || rm -f duperemove.hash' |
| 49 | + ExecStart=duperemove -r -d -h -q --hashfile=duperemove.hash --skip-zeroes --exclude="%f/.duperemove.hash" --exclude="%f/@swapfile/swapfile" %f/ |
| 50 | + ExecStartPost=-compsize %f/ |
| 51 | + ExecStopPost=-cp -a duperemove.hash %f/.duperemove.hash |
| 52 | + TimeoutStartSec=4h |
| 53 | + RuntimeDirectory=%p/%i |
| 54 | + WorkingDirectory=%t/%p/%i |
| 55 | + Nice=19 |
| 56 | + CPUSchedulingPolicy=batch |
| 57 | + IOSchedulingClass=best-effort |
| 58 | + IOSchedulingPriority=7 |
| 59 | + OOMScoreAdjust=1000 |
| 60 | + CPUWeight=30 |
| 61 | + CPUQuota=300% |
| 62 | + IOWeight=30 |
| 63 | + EOL' |
| 64 | + echo "rmlint has been reenabled!" |
| 65 | + elif [[ "${OPTION,,}" =~ ^(disable|uninstall) ]]; then |
| 66 | + if [[ "${RMLINT_STATE,,}" =~ "^not" ]]; then |
| 67 | + echo "${red} rmlint has already been disabled!" |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + ublue-update --wait |
| 71 | + rpm-ostree remove -y rmlint |
| 72 | + rm /etc/systemd/system/btrfs-dedup@.service.d/override.conf |
| 73 | + rmdir /etc/systemd/system/btrfs-dedup@.service.d/ |
| 74 | + echo "rmlint has been disabled." |
| 75 | + fi |
0 commit comments