forked from openSUSE/sdbootutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-sdbootutil.snapper
executable file
·76 lines (58 loc) · 1.4 KB
/
10-sdbootutil.snapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
shopt -s extglob nullglob
set -e
# check whether it's a transactional system
is_transactional()
{
[ "$(stat -f -c %T /etc)" = "overlayfs" ]
}
# when creating a snapshot we fetch all bls configs from previous snapshot dir,
# mangle them to contain current snapshot number, then install to efi partition.
create_snapshot()
{
path="$1"
fs="$2"
num="$3"
[ "$fs" = btrfs ] || return 1
is_transactional && return 0
/usr/bin/sdbootutil add-all-kernels "$num" || :
}
delete_snapshot()
{
local path="$1"
local fs="$2"
local num="$3"
[ "$fs" = btrfs ] || return 1
/usr/bin/sdbootutil remove-all-kernels "$num" || :
}
set_default_snapshot()
{
local path="$1"
local fs="$2"
local num="$3"
[ "$fs" = btrfs ] || return 1
if is_transactional; then
/usr/bin/sdbootutil add-all-kernels "$num" || :
/usr/bin/sdbootutil update "$num" || :
if [ -e /usr/lib/module-init-tools/regenerate-initrd-posttrans ]; then
/usr/lib/module-init-tools/regenerate-initrd-posttrans
fi
fi
/usr/bin/sdbootutil set-default-snapshot "$num" || :
}
h()
{
echo "Available commands:"
echo "${!commands[@]}"
}
declare -A commands
commands['create-snapshot-post']=create_snapshot
commands['delete-snapshot-pre']=delete_snapshot
commands['set-default-snapshot-post']=set_default_snapshot
commands['help']=h
cmd="$1"
shift
[ -n "$cmd" ] || cmd=help
if [ "${#commands[$cmd]}" -gt 0 ]; then
${commands[$cmd]} "$@"
fi