]> git.somenet.org - root/pub/somesible.git/blob - roles/base/btrfs-helpers/files/default/btrfs-regen-snaphot-homelinks.sh
[roles/util/letsencrypt-cert] request letsencrypt-cert helper role
[root/pub/somesible.git] / roles / base / btrfs-helpers / files / default / btrfs-regen-snaphot-homelinks.sh
1 #!/bin/bash
2 ################################################
3 ### Managed by someone's ansible provisioner ###
4 ################################################
5 # Part of: https://git.somenet.org/root/pub/somesible.git
6 # 2017-2024 by someone <someone@somenet.org>
7 #
8
9 # Copyright 2018 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
10 #
11 #       This program is free software: you can redistribute it and/or modify
12 #       it under the terms of the GNU General Public License as published by
13 #       the Free Software Foundation, version 3 of the License.
14 #
15 #       This program is distributed in the hope that it will be useful,
16 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
18 #       GNU General Public License for more details.
19 #
20 #       You should have received a copy of the GNU General Public License
21 #       along with this program.        If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 #
25 # Regenerate /home/$user/.btrfs-snapshots/ symlinks
26 # we use relative symlinking in order to break infinite recursions.
27 #
28
29 cd /home/
30 for home in $(find . -xdev -mindepth 1 -maxdepth 1 -type d); do
31     echo "HOME: /home/${home}"
32     rm -rf "/home/${home}/.btrfs-snapshots"
33     mkdir "/home/${home}/.btrfs-snapshots"
34
35     cd "/btrfs/"
36     for snap in $(find . -mindepth 2 -maxdepth 2 -type d -iname 'home.*.snap'); do
37         snap_name=$(echo -n $snap | sed -E -e 's#/#-#2g')
38         ln -snf "../../../btrfs/${snap}/${home}" "/home/${home}/.btrfs-snapshots/$snap_name"
39         touch -ahm -r "/btrfs/${snap}" "/home/${home}/.btrfs-snapshots/$snap_name"
40     done
41
42     rename -v 's/home\.(.*)\.snap/$1/' /home/${home}/.btrfs-snapshots/*
43 done