script-install-btrfsmaintenance 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. # Generic btrfsmaintenance install script
  3. # Copyright 2021-2025 Bryan C. Roessler
  4. # Licensed under the Apache License, Version 2.0
  5. p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1
  6. is_root
  7. # Optionally provide the config directory manually
  8. if [[ $# -lt 1 ]]; then
  9. if [[ -d /etc/sysconfig ]]; then
  10. CONFDIR=/etc/sysconfig
  11. elif [[ -d /etc/default ]]; then
  12. CONFDIR=/etc/default
  13. else
  14. echo "Cannot detect sysconfig directory, please specify manually"
  15. exit 1
  16. fi
  17. else
  18. CONFDIR="$1"
  19. fi
  20. # This is hardcoded by the btrfs maintenance scripts, change at your peril
  21. INSTALLDIR="/usr/share/btrfsmaintenance"
  22. # Backup existing installation
  23. if [[ -d "$INSTALLDIR" ]]; then
  24. TEMPDIR="/tmp/btrfs-maintenance.bk"
  25. echo "Moving existing $INSTALLDIR to $TEMPDIR"
  26. [[ -d "$TEMPDIR" ]] && rm -rf "$TEMPDIR"
  27. mv "$INSTALLDIR" "$TEMPDIR"
  28. fi
  29. git clone "https://github.com/kdave/btrfsmaintenance.git" "$INSTALLDIR"
  30. # Quirks
  31. if [[ -e "/etc/os-release" ]]; then
  32. source "/etc/os-release"
  33. if [[ "$ID" == "centos" && "$VERSION_ID" == "7" ]]; then
  34. sed -i 's/flock --verbose/flock' "$INSTALLDIR"/btrfsmaintenance-functions
  35. fi
  36. fi
  37. chmod 755 "$INSTALLDIR"/*.sh
  38. # Copy config file
  39. [[ ! -f "$CONFDIR"/btrfsmaintenance ]] && install -oroot -groot -m644 "$INSTALLDIR"/sysconfig.btrfsmaintenance "$CONFDIR"/btrfsmaintenance
  40. # Copy systemd files and reload
  41. for f in "$INSTALLDIR"/btrfs-*.{service,timer}; do
  42. cp "$f" /usr/lib/systemd/system/
  43. done
  44. systemctl daemon-reload
  45. # Optionally, start and enable the services
  46. # systemctl enable --now btrfs-scrub