btrfs-convert 689 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. btrfs_convert() {
  3. declare d dir tmp_dir
  4. for d in "$@"; do
  5. dir="$d"
  6. tmp_dir="$dir.tmp"
  7. if [[ -d $dir && ! -d $tmp_dir ]]; then
  8. if btrfs subvolume create "$tmp_dir" &>/dev/null &&
  9. mv "$dir"/* "$tmp_dir"/ &&
  10. rm -rf "$dir" &&
  11. mv "$tmp_dir" "$dir"; then
  12. echo "Successfully converted $dir to a btrfs subvolume"
  13. else
  14. echo "Failed to convert $dir to a btrfs subvolume"
  15. fi
  16. else
  17. echo "Skipping conversion, $dir is missing or $tmp_dir exists!"
  18. fi
  19. done
  20. unset d dir tmp_dir
  21. }
  22. if [[ $# -ge 1 ]]; then
  23. btrfs_convert "$@"
  24. else
  25. echo "btrfs_convert requires at least one argument (directory)"
  26. fi