Created
February 12, 2021 07:47
-
-
Save zatricky/b195b474ed5f3c3c4c57e878eef4f0f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ "$(id -u)" -eq 0 ]] || (echo "Got root?" ; exit 5) | |
command -v btrfs > /dev/null || (echo "Command not found: btrfs" ; exit 4) | |
for folder in $* ; do | |
mount | awk '{print $3}' | grep "$(pwd)/${folder}" && echo "${folder} has a submount?" && exit 1 | |
btrfs sub list . | grep "${PWD##*/}/${folder}" && echo "${folder} has a subvolume?" && exit 2 | |
[ -e ${folder}.temp ] && echo "${folder}.temp already exists?" && exit 3 || true | |
mv ${folder} ${folder}.temp | |
btrfs sub create ${folder} | |
USER=$(stat -c '%U' ${folder}.temp) | |
GROUP=$(stat -c '%G' ${folder}.temp) | |
chown ${USER}.${GROUP} ${folder} | |
cp -a --reflink=always ${folder}.temp/. ${folder}/ | |
echo "Delete ${folder}.temp/ if happy with ${folder}/" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment