~aleteoryx/muditaos

ref: eeafb5f1be091a34446b842dbde1b7d54cc029a7 muditaos/config/apply_update.sh -rwxr-xr-x 2.1 KiB
eeafb5f1 — Lefucjusz [MOS-783] Moved battery config file to '/user/data' 3 years ago
                                                                                
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#
# It works when the phone is in USB-MSC mode, it will apply the .tar
# file provided as the -u parameter to the script, as the "current
# version on the Pure phone.
#
# Works on Linux and MacOS
#

UPDATE_FILE=""
PHONE_PARTITION_NAME="MUDITAOS"
CLEAN_PHONE=0
TMPDIR="flashmac"
OS=`uname -s`
PHONE_DEV=""
LINUX_DEV_FILE="usb-NXP_SEMI_NXP_MASS_STORAGE_0123456789ABCDEF-0:0-part1"

function get_phone_dev() {
	if [ "$OS" == "Darwin" ]; then
		diskutil list | grep $PHONE_PARTITION_NAME | awk '{print $6}'
	else
		readlink -f /dev/disk/by-id/$LINUX_DEV_FILE		
	fi
}

function eject_phone() {
	if [ "$OS" == "Darwin" ]; then
		diskutil eject $PHONE_DEV
	else
		udisksctl unmount -b $PHONE_DEV
		timeout --signal=SIGINT 1 udisksctl power-off -b $PHONE_DEV
	fi
}

print_help() {
	echo "Usage: $0 [OPTION]"
	echo "  -h print help"
	echo "  -u update file"
	echo "  -c clean before update"
	echo
	exit 1
}

while getopts ":hu:c" arg; do
	case "${arg}" in
		h)
			print_help
			;;
		u)
			UPDATE_FILE=$OPTARG
			;;
		c)
			CLEAN_PHONE=1
			;;
		*)
			print_help
			;;
	esac
done

if [ $OPTIND -eq 1 ]; then
	print_help
fi

shift $((OPTIND-1))
PHONE_DEV=$(get_phone_dev)

if [ "$PHONE_DEV" == "" ]; then
	echo "Can't find $PHONE_PARTITION_NAME device via diskutil, make sure that the phone is in USB-MSC mode"
	exit 1
fi

PHONE_MOUNT=`df -P | grep $PHONE_DEV | awk '{print $6}'`

if [ "$PHONE_MOUNT" == "" ]; then
	echo dev: $PHONE_DEV not mounted, do that yorself and re-run
	exit 1
fi

if [ ! -e $UPDATE_FILE ]; then
	echo "Update file $UPDATE_FILE does not exist"
	exit 1
fi

rm -rf $TMPDIR
mkdir $TMPDIR
tar -C $TMPDIR -xpf $UPDATE_FILE

if [ $CLEAN_PHONE == 1 ]; then
	echo "Clean phone requested"
	rm -rf $PHONE_MOUNT/current
	mkdir -p $PHONE_MOUNT/current
	sync
fi

echo "Copyind data"
cp $TMPDIR/boot.bin $PHONE_MOUNT/current/
cp $TMPDIR/Luts.bin $PHONE_MOUNT/current/
cp $TMPDIR/version.json $PHONE_MOUNT/current/
cp -r $TMPDIR/assets $PHONE_MOUNT/current/

echo "Ejecting phone from OS..."
eject_phone