forked from Antynea/grub-btrfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path41_snapshots-btrfs
110 lines (102 loc) · 4.36 KB
/
41_snapshots-btrfs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /bin/sh
set -e
. /usr/share/grub/grub-mkconfig_lib
. /etc/default/grub
### variables modifiable ###
## fr: nom du sous-menu
## en: Name of the submenu
submenuname="ArchLinux Snapshots"
## fr: préfixe de l'entrée
## en: Prefix entry
prefixentry="Snapshot"
## fr: nom(s) du ou des kernel(s)
## en: Name(s) of the kernel(s)
nkernel=("vmlinuz-linux")
## fr: nom(s) de(s) l'init
## en: Name(s) of the init(s)
ninit=("initramfs-linux.img" "initramfs-linux-fallback.img")
###########################
### fr: DÉBUT DU SCRIPT ###
### en: NAME OF SCRIPT ###
### fr: NE PAS TOUCHER ###
### en: DO NOT TOUCH ###
###########################
## fr: paramêtre des chaînes --hint
## en: Parameter of the chains --hint (Translation unclear)
pboot=$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null)
## fr: uuid de la partition root
## en: UUID of the root partition
uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
## fr: uuid de la partition boot
## en: UUID of the boot partition
buuid=$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)
## fr: paramêtre passé au kernel
## en: Parameters passed to the kernel
params="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
# fr: on affiche le menu
# en: Display the menu
echo "submenu '$submenuname' {"
# fr: on traite la variable kernel
# en: Treat the kernel variables (Translation unclear)
for kernel in ${nkernel[@]}; do
# fr: on test si le(s) nom(s) du(des) kernel existe(nt), autrement on affiche une erreur et on sort
# en: Check the specified kernel(s) exist, if it/they don't display an error and exit
if [ ! -f /boot/$kernel ]; then echo "/boot/$kernel: fr: Fichier inexistant en: File does not exist" >&2; exit 1; fi
# fr: on vérifie le nombre de kernel présent, si >1 on crée un menu
# en: If there are >1 kernels, create a menu
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '$kernel' {
submenu '---> Kernel: $kernel <---' { echo }"; fi
# fr: On liste les snapshots présent sur le système de fichier
# en: List filesystem snapshots
for item in $($bindir/btrfs subvolume list -s / --sort=-ogen | $bindir/awk '{print $NF}'); do
# fr: On écarte les snapshots avec un statut de suppression
# en: Discard deleted snapshots
if [ $item = "DELETED" ]; then continue; fi
# fr: on crée un menu pour chaque snapshot présent
# en: Create a menu for remaining snapshots
date_time=$($bindir/btrfs subvolume list -s / | $bindir/grep $item | $bindir/cut -d" " -f 11-12)
echo " submenu '$prefixentry $item [$date_time]' {"
# fr: si plusieurs kernel on été trouvé, on affiche un titre indicatif
# en: Display message if more than one kernel is found
if [ ${#nkernel[*]} != 1 ]; then echo " submenu '---> Kernel: $kernel <---' { echo }"; fi
# fr: on traite la variable de l'initframs
# en: Treat the initramfs variables (Translation unclear)
for init in ${ninit[@]}; do
# fr: on test si le(s) nom(s) du(des) initframs existe(nt), autrement on affiche une erreur et on sort
# en: Check the specified initramfs(es) exist, if it/they don't display an error and exit
if [ ! -f /boot/$init ]; then echo "/boot/$init: Fichier inexistant" >&2; exit 1; fi
# fr: on traite chaque entrée des snapshots avec leurs kernel et initframs respectifs
# en: Specify a kernel and initramfs for every snapshot
echo "\
menuentry '$item $init' --class arch --class gnu-linux --class gnu --class os "\$menuentry_id_option" 'gnulinux-snapshots-$uuid'{
load_video
set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
if [ x"\$feature_platform_search_hint" = xy ]; then
search --no-floppy --fs-uuid --set=root $pboot $buuid
else
search --no-floppy --fs-uuid --set=root $buuid
fi
echo 'Loading Linux snapshot ...'"
# fr: on vérifie l'emplacement de la partition /boot
# en: Check the location of the /boot partition
if [ $uuid = $buuid ]; then
echo "\
linux /$item/boot/$kernel root=UUID=$uuid rw rootflags=subvol=$item $params
echo 'Loading initial ramdisk ...'
initrd /$item/boot/$init"
else
echo "\
linux /$kernel root=UUID=$uuid rw rootflags=subvol=$item $params
echo 'Loading initial ramdisk ...'
initrd /$init"
fi
echo "\
}"
done
echo " }"
done
# fr: on oubli pas de fermer le menu si plusieurs kernels ont été trouvé
# en: Don't forget to close menus if more than one kernel is found
if [ ${#nkernel[*]} != 1 ]; then echo " }"; fi
done
echo "}"