-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpbp-install-boot
executable file
·116 lines (102 loc) · 3.26 KB
/
pbp-install-boot
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
108
109
110
111
112
113
114
115
116
#!/bin/sh
### Package: pbp-install-boot
### Version: v20200630.2300
### Author: Michael Gan "xmixahlx" [email protected]
### License: GPLv3
### Script Dependencies: linux
### Usage: Provide DEVTARGET and BLKDEV with command
## PBPTOOLSDIR
if [ -z $PBPTOOLSDIR ]; then
PBPTOOLSDIR="`pwd`"
fi
## VARS
DATE=`date +%Y%m%d%H%M%S`
RESDIR=$PBPTOOLSDIR/resources
DEVDIR=$PBPTOOLSDIR/upstream
GITBRANCH=v2.0
PKGDIR=pbp-install-boot_$GITBRANCH
## OVERRIDES
# You MUST provide a DEVTARGET, either partitions or device.
if [ -z $DEVTARGET ]; then
echo "\n*** You MUST specify a DEVTARGET. Either partitions or device.\n"
exit
fi
echo "\n*** DEVTARGET selected is $DEVTARGET.\n"
# You MUST provide a BLKDEV, such as /dev/mmcblk2, /dev/nvme0n1, etc.
if [ -z $BLKDEV ]; then
echo "\n*** You MUST specify a BLKDEV. i.e. /dev/mmcblk2, /dev/nvme0n1, etc..\n"
exit
fi
echo "\n*** BLKDEV selected is $BLKDEV.\n"
## CHECKS
# Check if provided DEVTARGET is partitions or device.
if [ $DEVTARGET ]; then
if [ $DEVTARGET != device -a $DEVTARGET != partitions ]; then
echo "\n*** DEVTARGET MUST be partitions or device. Exiting.\n"
exit
else
echo "\n*** DEVTARGET $DEVTARGET checked.\n"
fi
fi
# Check if provided BLKDEV actually exists.
if [ $BLKDEV ]; then
if [ ! -b $BLKDEV ]; then
echo "\n*** BLKDEV $BLKDEV NOT found. Exiting.\n"
exit
else
echo "\n*** BLKDEV $BLKDEV found.\n"
fi
fi
## DEPS
# Provide INSTALLDEPS=debian to install dependencies.
if [ $INSTALLDEPS ]; then
if [ $INSTALLDEPS = debian ]; then
sudo apt-get -y install util-linux coreutils wget
fi
fi
## DISPLAY BLKDEV
echo "\n*** Displaying block devices to help confirm.\n"
lsblk -a
## CONFIRM BLKDEV
echo "\n*** Continue to write to $BLKDEV $DEVTARGET ?\n"
read -p "Yes or No: " CONTINUE
case $CONTINUE in
[Yy]* ) echo "\n*** YES selected. Continuing.\n" ;;
[Nn]* ) echo "\n*** NO selected. Exiting.\n" && exit ;;
* ) echo "\n***Select YES or NO. Exiting.\n" && exit ;;
esac
## PREP
set -e
mkdir -p $DEVDIR
cd $DEVDIR
## GET
mkdir -p $PKGDIR
cd $PKGDIR
[ -f idbloader.img ] || wget https://github.com/mrfixit2001/updates_repo/raw/$GITBRANCH/pinebook/filesystem/idbloader.img
[ -f trust.img ] || wget https://github.com/mrfixit2001/updates_repo/raw/$GITBRANCH/pinebook/filesystem/trust.img
[ -f uboot.img ] || wget https://github.com/mrfixit2001/updates_repo/raw/$GITBRANCH/pinebook/filesystem/uboot.img
## CHECK
if md5sum -c $RESDIR/boot/$GITBRANCH.md5 --quiet; then
# Check passed. Write.
if [ $DEVTARGET = partitions ]; then
echo "\n*** MD5 checksum passed. Writing to $BLKDEV partitions.\n"
sudo dd if=idbloader.img of=${BLKDEV}p1 bs=4096
sudo dd if=uboot.img of=${BLKDEV}p2 bs=4096
sudo dd if=trust.img of=${BLKDEV}p3 bs=4096
echo "\n*** Wrote images to $BLKDEV $DEVTARGET. Done. Exiting.\n"
fi
if [ $DEVTARGET = device ]; then
echo "\n*** MD5 checksum passed. Writing to $BLKDEV device.\n"
sudo dd if=idbloader.img of=${BLKDEV} seek=64 conv=notrunc
sudo dd if=uboot.img of=${BLKDEV} seek=16384 conv=notrunc
sudo dd if=trust.img of=${BLKDEV} seek=24576 conv=notrunc
echo "\n*** Wrote images to $BLKDEV device. Done. Exiting.\n"
fi
else
# Check failed. Exit.
echo "\n*** MD5 failed. Did NOT write images to device $BLKDEV. Deleting IMG files and exiting.\n"
rm idbloader.img trust.img uboot.img
fi
## EXIT
exit
## ENJOY