-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass_storage.sh
executable file
·43 lines (37 loc) · 1.01 KB
/
mass_storage.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
#!/usr/bin/env bash
#
# The library for g_mass_storage.
#
# Note that the USB drive image file is created at the first boot (by setup_system.sh). Thus, it
# could be absent.
#
set -e
USB_DRIVE_IMG=/root/usb_drive.img
USB_DRIVE_FOLDER=/media/
TESLA_CAM_FOLDER="${USB_DRIVE_FOLDER}/TeslaCam/"
RECENT_CLIPS="${TESLA_CAM_FOLDER}/RecentClips/"
SAVED_CLIPS="${TESLA_CAM_FOLDER}/SavedClips/"
MARKED_CLIPS="/root/MarkedClips/"
mount_ro_media() {
# mount USB image onto system.
if true; then
mount -o ro "$USB_DRIVE_IMG" "${USB_DRIVE_FOLDER}" || true
else
LOOP_DEV=$(losetup --show -Pf "${USB_DRIVE_IMG}") || true
mount -o loop,ro "${LOOP_DEV}"p1 "${USB_DRIVE_FOLDER}" || true
fi
}
mount_rw_media() {
mount -o rw "$USB_DRIVE_IMG" "${USB_DRIVE_FOLDER}" || true
}
umount_media() {
umount -f "${USB_DRIVE_FOLDER}"
}
mass_storage_start() {
# Load modules
modprobe dwc2 || true
modprobe g_mass_storage file="${USB_DRIVE_IMG}" stall=1 removable=1 || true
}
mass_storage_stop() {
rmmod g_mass_storage
}