forked from omgmog/archarm-usb-hp-chromebook-11
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
222 lines (191 loc) · 6.51 KB
/
install.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
trap onexit 1 2 3 15 ERR EXIT
#--- onexit() -----------------------------------------------------
# @param $1 integer (optional) Exit status. If not set, use `$?'
onexit() {
# any items needed for cleanup here.
local exit_status=${1:-$?}
if [ ${exit_status} == 0 ]
then
exit
fi
exit $exit_status
}
log() {
printf "\n\033[32m$*\033[00m\n"
read -p "Press [enter] to continue." KEY
}
EMMC="/dev/mmcblk0"
DEFAULT_USB="/dev/sda"
DEVICE=${1:-$DEFAULT_USB}
if [ "$DEVICE" = "$EMMC" ]; then
P1="${DEVICE}p1"
P2="${DEVICE}p2"
P3="${DEVICE}p3"
P12="${DEVICE}p12"
else
P1="${DEVICE}1"
P2="${DEVICE}2"
fi
OSHOST="http://archlinuxarm.org/os/"
OSFILE="ArchLinuxARM-peach-latest.tar.gz"
BOOTFILE="boot.scr.uimg"
UBOOTHOST="https://github.com/omgmog/nv_uboot-spring/raw/master/"
UBOOTFILE="nv_uboot-spring.kpart.gz"
GITHUBUSER="omgmog"
REPOFILES="https://raw.githubusercontent.com/${GITHUBUSER}/archarm-usb-hp-chromebook-11"
echo "Getting working cgpt binary"
mkdir -p /usr/local/bin
wget ${REPOFILES}/master/deps/cgpt --output-document=/usr/local/bin/cgpt
chmod +x /usr/local/bin/cgpt
if [ $DEVICE = $EMMC ]; then
if [ -L /usr/sbin ]; then
rm -f /usr/sbin
fi
# for eMMC we need to get some things before we can partition
pacman -Syu --needed packer devtools-alarm base-devel git libyaml parted dosfstools parted
pacman -S --needed --noconfirm vboot-utils
log "When prompted to modify PKGBUILD for trousers, set arch to armv7h"
useradd -c 'Build user' -m build
su -c "packer -S trousers" build
userdel -r build > /dev/null 2>&1
if [ ! -L /usr/sbin ] && [ ! -d /usr/sbin ]; then
ln -s /usr/bin /usr/sbin
fi
else
log "Ensuring the proper paritioning tools are availible"
if (which parted > /dev/null 2>&1 ); then
echo "parted is installed. Installation can proceed"
else
echo "parted must be downloaded !"
log "When prompted to install virtual/target-os-dev press N"
dev_install
emerge parted
fi
fi
log "Creating volumes on ${DEVICE}"
for mnt in `mount | grep ${DEVICE} | awk '{print $1}'`;do
umount ${mnt}
done
parted ${DEVICE} mklabel gpt
/usr/local/bin/cgpt create -z ${DEVICE}
/usr/local/bin/cgpt create ${DEVICE}
if [ $DEVICE = $EMMC ]; then
/usr/local/bin/cgpt add -i 1 -t kernel -b 8192 -s 32768 -l U-Boot -S 1 -T 5 -P 10 ${DEVICE}
/usr/local/bin/cgpt add -i 2 -t data -b 40960 -s 32768 -l Kernel ${DEVICE}
/usr/local/bin/cgpt add -i 12 -t data -b 73728 -s 32768 -l Script ${DEVICE}
PARTSIZE=`/usr/local/bin/cgpt show ${DEVICE} | grep 'Sec GPT table' | egrep -o '[0-9]+' | head -n 1`
/usr/local/bin/cgpt add -i 3 -t data -b 106496 -s `expr ${PARTSIZE} - 106496` -l Root ${DEVICE}
partprobe ${DEVICE}
mkfs.ext2 $P2
mkfs.ext4 $P3
mkfs.vfat -F 16 $P12
else
# USB uses only 2 partitions
/usr/local/bin/cgpt add -i 1 -t kernel -b 8192 -s 32768 -l Kernel -S 1 -T 5 -P 10 ${DEVICE}
PARTSIZE=`/usr/local/bin/cgpt show ${DEVICE} | grep 'Sec GPT table' | egrep -o '[0-9]+' | head -n 1`
/usr/local/bin/cgpt add -i 2 -t data -b 40960 -s `expr ${PARTSIZE} - 40960` -l Root ${DEVICE}
sfdisk -R /dev/sda
mkfs.ext4 $P2
fi
cd /tmp
if [ ! -f "${OSFILE}" ]; then
log "Downloading ${OSFILE}"
wget ${OSHOST}${OSFILE}
else
log "Looks like you already have ${OSFILE}"
fi
if [ $DEVICE = $EMMC ]; then
log "Installing Arch to ${P3} (this will take a moment...)"
else
log "Installing Arch to ${P2} (this will take a moment...)"
fi
for mnt in `mount | grep ${DEVICE} | awk '{print $1}'`;do
umount ${mnt}
done
mkdir -p root
if [ $DEVICE = $EMMC ]; then
mount -o exec $P3 root
else
mount -o exec $P2 root
fi
tar -xf ${OSFILE} -C root > /dev/null 2>&1
log "Copying crossystem and mosys from ChromeOS"
if [ $DEVICE != $EMMC ]; then
mkdir root/CrOStools
cp /usr/bin/crossystem root/CrOStools/crossystem
cp /usr/sbin/mosys root/CrOStools/mosys
cp install.sh root/install.sh
fi
log "Preparing system for chroot"
if [ $DEVICE != $EMMC ]; then
cp install.sh root/install.sh
fi
if [ $DEVICE = $EMMC ]; then
rm root/etc/resolv.conf
cp /etc/resolv.conf root/etc/resolv.conf
mount -t proc proc root/proc/
mount --rbind /sys root/sys/
mount --rbind /dev root/dev/
log "downloading old version of systemd and pacman.conf"
rm root/etc/pacman.conf
wget ${REPOFILES}/master/deps/systemd-212-3-armv7h.pkg.tar.xz --output-document=root/systemd-212-3-armv7h.pkg.tar.xz
wget ${REPOFILES}/master/deps/pacman.conf --output-document=root/etc/pacman.conf
wget ${REPOFILES}/master/post-install.sh --output-document=root/post-install.sh
log "downloading systemd fix script"
wget ${REPOFILES}/master/fix-systemd.sh --output-document=root/fix-systemd.sh
chmod +x root/fix-systemd.sh
chroot root/ /bin/bash -c "/fix-systemd.sh"
fi
if [ ! -f "root/boot/${BOOTFILE}" ]; then
log "Downloading ${BOOTFILE}"
wget -O "root/boot/${BOOTFILE}" "${OSHOST}exynos/${BOOTFILE}"
else
log "Looks like we already have boot.scr.uimg"
fi
mkdir -p mnt
if [ $DEVICE = $EMMC ]; then
mount $P2 mnt
cp root/boot/vmlinux.uimg mnt
umount mnt
fi
# for usb we only copy the Kernel below and use U-Boot from eMMC
if [ $DEVICE = $EMMC ]; then
mount $P12 mnt
mkdir -p mnt/u-boot
cp root/boot/boot.scr.uimg mnt/u-boot
umount mnt
fi
# for usb we only copy the Kernel below and use U-Boot from eMMC
log "Moving CrOS-Tools in place"
if [ $DEVICE != $EMMC ]; then
cp root/CrOStools/crossystem /tmp/root/usr/bin/crossystem
cp root/CrOStools/mosys /tmp/root/usr/sbin/mosys
fi
# TODO: proper location for eMMC-install
if [ $DEVICE != $EMMC ]; then
log "Copying over devkeys (to generate kernel later)"
mkdir -p /tmp/root/usr/share/vboot/devkeys
cp -r /usr/share/vboot/devkeys/ /tmp/root/usr/share/vboot/
fi
if [ $DEVICE = $EMMC ]; then
echo "root=${P3} rootwait rw quiet lsm.module_locking=0" >config.txt
/usr/sbin/vbutil_kernel \
--pack arch-eMMC.kpart \
--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
--config config.txt \
--vmlinuz /boot/vmlinux.uimg \
--arch arm \
--version 1
dd if=arch-eMMC.kpart of=$P1
sync
log "All done! Reboot and press ctrl + D to boot Arch"
else
dd if=root/boot/vmlinux.kpart of=$P1
#make sure USB stays enabled for boot
crossystem dev_boot_usb=1 dev_boot_signed_only=0
umount root
sync
log "All done! Reboot and press ctrl + U to boot Arch from ${DEVICE}"
fi