script-install-btrfsmaintenance 1.6 KB

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