-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_sd.sh
executable file
·48 lines (36 loc) · 888 Bytes
/
copy_sd.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
#! /bin/sh
DEVICE=$1
FILES_PATH='.'
usage() { echo "usage: $0 <device> [<path>]"; }
if [ -d "$2" ]; then
FILES_PATH=$2
else
echo "Error: $2 is not a valid path."
usage
exit 2
fi
if [ -z "$DEVICE" ]; then
echo "Error: No device specified."
usage
exit 2
fi
if [ ! -b "$DEVICE" ]; then
echo "Error: $DEVICE is not a valid device."
usage
exit 2
fi
cleanup() {
mountpoint -q $TEMP_MOUNT && umount "$TEMP_MOUNT"
[ -d $TEMP_MOUNT ] && rm -rf $TEMP_MOUNT
}
TEMP_MOUNT=$(mktemp -d -t opizero-alpine-XXXXXXXX)
trap 'cleanup' EXIT
echo "Mounting device.."
mount "$DEVICE"1 $TEMP_MOUNT \
|| { echo "Error: failed to mount ${DEVICE}1"; exit 1; }
echo "Copying files.."
{ cp -r $FILES_PATH/apks "$TEMP_MOUNT"/; cp -r $FILES_PATH/boot "$TEMP_MOUNT"/; } \
|| { echo "Error: failed to copy from $FILES_PATH"; exit 1; }
echo "Ejecting device.."
eject $DEVICE || true
echo "Done!"