-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopy_to_img.sh
More file actions
executable file
·68 lines (60 loc) · 1.18 KB
/
copy_to_img.sh
File metadata and controls
executable file
·68 lines (60 loc) · 1.18 KB
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
#! /bin/bash
# exit immediately if any command fails
set -e
usage() {
U=""
if [[ -n "$1" ]]; then
U="${U}$1\n\n"
fi
U="${U}Usage: $0 [options]\n\n"
U="${U}Options:\n"
U="$U -i | --image <img>: disk image\n"
U="$U -f | --file <file>: file to copy into the disk image\n"
echo -e "$U" >&2
}
while :
do
case "$1" in
-i | --image)
IMAGE="$2"
shift 2
;;
-f | --file)
FILE="$2"
shift 2
;;
-h | --help)
usage ""
exit 1
;;
--) # End of all options
shift
break
;;
-*) # Unknown option
echo "Error: Unknown option: $1" >&2
exit 1
;;
*)
break
;;
esac
done
if [[ -z "$IMAGE" ]]; then
echo "Please supply disk image" >&2
usage ""
exit 1
fi
if [[ -z "$FILE" ]]; then
echo "Please supply file to copy into the disk image" >&2
usage ""
exit 1
fi
# create temp directory for mounting
TMP_DIR=$(mktemp -d --tmpdir=.)
sudo mount ${IMAGE} ${TMP_DIR}
sudo cp -r ${FILE} ${TMP_DIR}/root
sudo sync
sudo umount ${TMP_DIR}
# remove the temp directory
rm -rf ${TMP_DIR}