-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopy_files.sh
executable file
·73 lines (61 loc) · 1.46 KB
/
copy_files.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/sh
# multiboot usb drive
# by Markus Færevaag
# github.com/mfaerevaag/multibootusb
# use absolute path to cp to sirucumcent
# aliases which can stop from overwriting
cp=/usr/bin/cp
# files to copy
files="grub.cfg
multiboot.6U4YzT
grub.d
themes"
# error func
function err
{
echo "$1"
exit 1
}
# parse args
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
err "usage: $0 [--force] PATH_TO_GRUB_DIR"
fi
for arg in $@; do
if [ "$arg" == "--force" ] || [ "$arg" == "-f" ]; then
force=true
else
target=${arg%/} # remove trailing slash
fi
done
# check args
if [ ! "$target" ]; then # check target given
err "no target given (e.g. /mnt/boot/grub/)"
elif [ ! -d "$target" ]; then # check target exist
err "target does not exist"
elif [ ! -f "$target/grubenv" ]; then # check sane target
err "not a grub folder"
fi
echo "copying from $PWD to $target..."
# copy files
for file in $files; do
echo -ne " * $PWD/$file -> $target/$file"
if [ -e "$PWD/$file" ]; then
if [ "$force" ]; then
echo " [FORCE]"
/usr/bin/cp -rf $PWD/$file $target/
else
# read yes or no
read -p " [y/N] " yn
case $yn in
[Yy]* ) ;;
"" ) ;;
[Nn]* ) continue;;
* ) continue;;
esac
/usr/bin/cp -rf $PWD/$file $target/
fi
else
err "$PWD/$file not found"
fi
done
echo "done"