-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkretro
executable file
·102 lines (76 loc) · 2.88 KB
/
mkretro
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
#!/bin/bash
TARGET=$1
RETROPIE_IMAGE=$2
RETROPIE_VERSION=$(echo $RETROPIE_IMAGE | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
KERNEL=(packages/kernel_*.tgz)
KERNEL=${KERNEL[0]}
KERNEL_VERSION=$(echo $KERNEL | grep -Eo "kernel_[0-9]+\.[0-9]+\.[0-9]+" | tr '_' '-')
KERNEL_COMPILER=$(echo $KERNEL | grep -Eo "gcc[0-9]+\.[0-9]+\.[0-9]+")
OUTPUT_IMAGE="retropie-pip_retropie-${RETROPIE_VERSION}_${KERNEL_VERSION}-${KERNEL_COMPILER/gcc/gcc-}.img.gz"
echo "retropie: $RETROPIE_IMAGE"
echo "kernel: $KERNEL"
echo "output image: $OUTPUT_IMAGE"
# RetroPie default root partition size + 400MiB
ROOT_SIZE=3519021055
function mount_all {
mount ${TARGET}2 tmp/root
mount ${TARGET}1 tmp/root/boot
}
function unmount_all {
umount tmp/root/boot >/dev/null 2>&1
umount tmp/root >/dev/null 2>&1
}
# Unmount target if mounted from previous failed run
unmount_all
mkdir -p tmp/root
set -e
# Flash RetroPie image to target device
echo "Flashing image"
gzip -d -c $RETROPIE_IMAGE | dd of=$TARGET bs=8M
sleep 2
echo "Resizing partition"
parted --script $TARGET unit B resizepart 2 $ROOT_SIZE
echo "Partition resized, waiting 3s..."
sleep 3
echo "Resizing filesystem"
e2fsck -f ${TARGET}2
resize2fs ${TARGET}2
echo "Mounting SD card"
mount_all
sleep 2
pushd pip-build/src/imager/boot
make
popd
rm -rf tmp/root/boot/*.{dtb,img}
rm -rf tmp/root/boot/overlays
tar -xf $KERNEL -C tmp/root/
cp pip-build/src/imager/boot/overlays/*.dtbo tmp/root/boot/overlays
cp pip-build/src/imager/boot/dt-blob.bin tmp/root/boot
cp files/config.txt tmp/root/boot
cp files/cmdline.txt tmp/root/boot
# Set up kernel module dir
rm -rf tmp/root/lib/modules/*
mv tmp/root/usr/lib/modules/* tmp/root/lib/modules
# Install sid + deps
cp /etc/resolv.conf tmp/root/etc/resolv.conf
chroot tmp/root sh -c "apt-get install -y libusb-1.0 libuv1 libasound2"
cp packages/sid.tgz tmp/root/sid.tgz
chroot tmp/root sh -c "tar xvf sid.tgz && rm -f sid.tgz && systemctl enable pip-sid.service"
cp files/sid.ini tmp/root/opt/pip/etc/sid.ini
# Remove WiFi adapter from blacklist and enable wlan0
rm -f tmp/root/etc/modprobe.d/blacklist-8192cu.conf
rm -f tmp/root/etc/modprobe.d/blacklist-rtl8xxxu.conf
install -m 644 -o root -g root files/interfaces tmp/root/etc/network/interfaces
# Copy alsa config
echo snd-soc-pip-dac >> tmp/root/etc/modules
install -m 644 -o root -g root files/asound.state "tmp/root/var/lib/alsa/asound.state"
# Copy retropie config
cp files/es_input.cfg tmp/root/opt/retropie/configs/all/emulationstation/es_input.cfg
cp files/retroarch.cfg tmp/root/opt/retropie/configs/all/retroarch.cfg
cp files/Pip\ Virtual\ Gamepad.cfg tmp/root/opt/retropie/configs/all/retroarch/autoconfig/Pip\ Virtual\ Gamepad.cfg
echo "Unmounting SD card"
unmount_all
END=$(sudo parted /dev/sda -m 'unit MiB print' | tail -n 1 | cut -d ':' -f 3 | sed 's/[^0-9]*//g')
echo "Cloning image"
dd if=${TARGET} bs=1M count="$(($END+2))" | gzip > $OUTPUT_IMAGE
echo "Image written to $OUTPUT_IMAGE"