-
Notifications
You must be signed in to change notification settings - Fork 11
/
03_sync_bootdirs.sh
executable file
·49 lines (44 loc) · 1.3 KB
/
03_sync_bootdirs.sh
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
#!/bin/bash
set -eu
# Import some helpful functions, prefixed 'L_'
. ./Library.sh
USB_DEVICE=$1
L_banner_begin "SYNC BOOTDIRS"
DIR="$(pwd)"
if [[ $( L_mnt_detect "$USB_DEVICE" ) ]]; then
MNTPOINT="$( L_mnt_detect "$USB_DEVICE" | cut -d' ' -f3 )"
else
MNTPOINT="$( L_mktemp_dir_pwd )"
echo "Create work directory [$MNTPOINT]"
L_sig_ok
L_mnt_mount_vfat "$USB_DEVICE" "$MNTPOINT"
fi
echo "Device $USB_DEVICE mounted on $MNTPOINT"
L_sig_ok
SRC_BOOT="$DIR/boot"
MNTPOINT_BOOT="$MNTPOINT/boot"
SRC_CFG="$SRC_BOOT/grub/grub.cfg"
if [[ -d $MNTPOINT_BOOT/grub2 ]]; then
MNTPOINT_GRUB="$MNTPOINT_BOOT/grub2"
rmdir $MNTPOINT_BOOT/grub
else
MNTPOINT_GRUB="$MNTPOINT_BOOT/grub"
fi
MNT_CFG="$MNTPOINT_GRUB/grub.cfg"
if [[ -f $MNT_CFG ]]; then
echo "Backup $MNT_CFG"
L_bak_file $MNT_CFG
L_sig_ok
fi
echo "Copy $SRC_CFG --> $MNT_CFG"
cp "$SRC_CFG" "$MNT_CFG"
L_sig_ok
# Read the 'RSYNC_OPT' property from '.config'
RSYNC_OPT="$( grep -i ^RSYNC_OPT .config | cut -f2- -d'=' )"
# Read the 'RSYNC_EXCLUDE' property from '.config'
RSYNC_EXCLUDE="$( grep -i ^RSYNC_EXCLUDE .config |
cut -f2- -d'=' | cut -f1- -d',' --output-delimiter=' --exclude ' )"
rsync $RSYNC_OPT --exclude $RSYNC_EXCLUDE $SRC_BOOT/ $MNTPOINT_BOOT/
echo "Rsync $SRC_BOOT/ ---> $MNTPOINT_BOOT/"
L_sig_ok
L_banner_end "SYNC BOOTDIRS"