|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Build Architecture Debian 32bit |
| 4 | +ARCH="armv7" |
| 5 | + |
| 6 | +while getopts ":v:p:a:" opt; do |
| 7 | + case $opt in |
| 8 | + v) |
| 9 | + VERSION=$OPTARG |
| 10 | + ;; |
| 11 | + p) |
| 12 | + PATCH=$OPTARG |
| 13 | + ;; |
| 14 | + a) |
| 15 | + ARCH=$OPTARG |
| 16 | + ;; |
| 17 | + esac |
| 18 | +done |
| 19 | + |
| 20 | +BUILDDATE=$(date -I) |
| 21 | +IMG_FILE="Volumio${VERSION}-${BUILDDATE}-nanopineo3.img" |
| 22 | + |
| 23 | +if [ "$ARCH" = arm ]; then |
| 24 | + DISTRO="Raspbian" |
| 25 | +else |
| 26 | + DISTRO="Debian 32bit" |
| 27 | +fi |
| 28 | + |
| 29 | +echo "Creating Image File ${IMG_FILE} with ${DISTRO} rootfs" |
| 30 | + |
| 31 | +dd if=/dev/zero of=${IMG_FILE} bs=1M count=2800 |
| 32 | + |
| 33 | +echo "Creating Image Bed" |
| 34 | +LOOP_DEV=`losetup -f --show ${IMG_FILE}` |
| 35 | +# Note: leave the first 20Mb free for the firmware (effectively needs ~16Mb) |
| 36 | +parted -s "${LOOP_DEV}" mklabel msdos |
| 37 | +parted -s "${LOOP_DEV}" mkpart primary fat32 20 84 |
| 38 | +parted -s "${LOOP_DEV}" mkpart primary ext3 84 2500 |
| 39 | +parted -s "${LOOP_DEV}" mkpart primary ext3 2500 100% |
| 40 | +parted -s "${LOOP_DEV}" set 1 boot on |
| 41 | +parted -s "${LOOP_DEV}" print |
| 42 | +partprobe "${LOOP_DEV}" |
| 43 | +kpartx -s -a "${LOOP_DEV}" |
| 44 | + |
| 45 | +BOOT_PART=`echo /dev/mapper/"$( echo ${LOOP_DEV} | sed -e 's/.*\/\(\w*\)/\1/' )"p1` |
| 46 | +SYS_PART=`echo /dev/mapper/"$( echo ${LOOP_DEV} | sed -e 's/.*\/\(\w*\)/\1/' )"p2` |
| 47 | +DATA_PART=`echo /dev/mapper/"$( echo ${LOOP_DEV} | sed -e 's/.*\/\(\w*\)/\1/' )"p3` |
| 48 | +echo "Using: " ${BOOT_PART} |
| 49 | +echo "Using: " ${SYS_PART} |
| 50 | +echo "Using: " ${DATA_PART} |
| 51 | +if [ ! -b "${BOOT_PART}" ] |
| 52 | +then |
| 53 | + echo "${BOOT_PART} doesn't exist" |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +echo "Creating boot and rootfs filesystems" |
| 58 | +mkfs -t vfat -n BOOT "${BOOT_PART}" |
| 59 | +mkfs -F -t ext4 -O ^metadata_csum,^64bit -L volumio "${SYS_PART}" || mkfs -F -t ext4 -L volumio "${SYS_PART}" |
| 60 | +mkfs -F -t ext4 -O ^metadata_csum,^64bit -L volumio_data "${DATA_PART}" || mkfs -F -t ext4 -L volumio_data "${DATA_PART}" |
| 61 | +sync |
| 62 | + |
| 63 | +echo "Preparing for the nanopi-neo3 kernel/ platform files" |
| 64 | +if [ -d platform-nanopi/nanopi-neo3 ] |
| 65 | +then |
| 66 | + echo "Platform folder already exists - keeping it" |
| 67 | + # if you really want to re-clone from the repo, then delete the platform-nanopi folder |
| 68 | + # that will refresh the platform files, see below |
| 69 | + cd platform-nanopi |
| 70 | + if [ -f nanopi-neo3.tar.xz ]; then |
| 71 | + echo "Found a new tarball, unpacking..." |
| 72 | + rm -r nanopi-neo3 |
| 73 | + tar xfJ nanopi-neo3.tar.xz |
| 74 | + rm nanopi-neo3.tar.xz |
| 75 | + fi |
| 76 | + cd .. |
| 77 | +else |
| 78 | + if [ ! -d platform-nanopi ]; then |
| 79 | + mkdir platform-nanopi |
| 80 | + fi |
| 81 | + cd platform-nanopi |
| 82 | + [ ! -f nanopi-neo3.tar.xz ] || rm nanopi-neo3.tar.xz |
| 83 | + wget https://github.com/volumio/platform-nanopi/raw/master/nanopi-neo3.tar.xz |
| 84 | + echo "Unpacking the Neo3 platform files" |
| 85 | + tar xfJ nanopi-neo3.tar.xz |
| 86 | + rm nanopi-neo3.tar.xz |
| 87 | + cd .. |
| 88 | +fi |
| 89 | + |
| 90 | +echo "Copying the bootloader" |
| 91 | +dd if=platform-nanopi/nanopi-neo3/u-boot/idbloader.bin of=${LOOP_DEV} seek=64 conv=notrunc |
| 92 | +dd if=platform-nanopi/nanopi-neo3/u-boot/uboot.img of=${LOOP_DEV} seek=16384 conv=notrunc |
| 93 | +dd if=platform-nanopi/nanopi-neo3/u-boot/trust.bin of=${LOOP_DEV} seek=24576 conv=notrunc |
| 94 | +sync |
| 95 | + |
| 96 | +echo "Preparing for Volumio rootfs" |
| 97 | +if [ -d /mnt ] |
| 98 | +then |
| 99 | + echo "/mount folder exist" |
| 100 | +else |
| 101 | + mkdir /mnt |
| 102 | +fi |
| 103 | +if [ -d /mnt/volumio ] |
| 104 | +then |
| 105 | + echo "Volumio Temp Directory Exists - Cleaning it" |
| 106 | + rm -rf /mnt/volumio/* |
| 107 | +else |
| 108 | + echo "Creating Volumio Temp Directory" |
| 109 | + mkdir /mnt/volumio |
| 110 | +fi |
| 111 | + |
| 112 | +echo "Creating mount point for the images partition" |
| 113 | +mkdir /mnt/volumio/images |
| 114 | +mount -t ext4 "${SYS_PART}" /mnt/volumio/images |
| 115 | +mkdir /mnt/volumio/rootfs |
| 116 | +mkdir /mnt/volumio/rootfs/boot |
| 117 | +mount -t vfat "${BOOT_PART}" /mnt/volumio/rootfs/boot |
| 118 | + |
| 119 | +echo "Copying Volumio RootFs" |
| 120 | +cp -pdR build/$ARCH/root/* /mnt/volumio/rootfs |
| 121 | + |
| 122 | +echo "Copying nanopineo3 boot files" |
| 123 | +cp -R platform-nanopi/nanopi-neo3/boot/* /mnt/volumio/rootfs/boot |
| 124 | + |
| 125 | +echo "Copying nanopineo3 modules and firmware" |
| 126 | +cp -pdR platform-nanopi/nanopi-neo3/lib/modules /mnt/volumio/rootfs/lib/ |
| 127 | +cp -R platform-nanopi/nanopi-neo3/firmware/* /mnt/volumio/rootfs/lib/firmware |
| 128 | + |
| 129 | +echo "Preparing to run chroot for more nanopineo3 configuration" |
| 130 | +cp scripts/nanopineo3config.sh /mnt/volumio/rootfs |
| 131 | +cp scripts/initramfs/init.nextarm /mnt/volumio/rootfs/root/init |
| 132 | +cp scripts/initramfs/mkinitramfs-custom.sh /mnt/volumio/rootfs/usr/local/sbin |
| 133 | +#copy the scripts for updating from usb |
| 134 | +wget -P /mnt/volumio/rootfs/root http://repo.volumio.org/Volumio2/Binaries/volumio-init-updater |
| 135 | + |
| 136 | +mount /dev /mnt/volumio/rootfs/dev -o bind |
| 137 | +mount /proc /mnt/volumio/rootfs/proc -t proc |
| 138 | +mount /sys /mnt/volumio/rootfs/sys -t sysfs |
| 139 | +echo $PATCH > /mnt/volumio/rootfs/patch |
| 140 | + |
| 141 | +echo "UUID_DATA=$(blkid -s UUID -o value ${DATA_PART}) |
| 142 | +UUID_IMG=$(blkid -s UUID -o value ${SYS_PART}) |
| 143 | +UUID_BOOT=$(blkid -s UUID -o value ${BOOT_PART}) |
| 144 | +" > /mnt/volumio/rootfs/root/init.sh |
| 145 | +chmod +x /mnt/volumio/rootfs/root/init.sh |
| 146 | + |
| 147 | +if [ -f "/mnt/volumio/rootfs/$PATCH/patch.sh" ] && [ -f "config.js" ]; then |
| 148 | + if [ -f "UIVARIANT" ] && [ -f "variant.js" ]; then |
| 149 | + UIVARIANT=$(cat "UIVARIANT") |
| 150 | + echo "Configuring variant $UIVARIANT" |
| 151 | + echo "Starting config.js for variant $UIVARIANT" |
| 152 | + node config.js $PATCH $UIVARIANT |
| 153 | + echo $UIVARIANT > /mnt/volumio/rootfs/UIVARIANT |
| 154 | + else |
| 155 | + echo "Starting config.js" |
| 156 | + node config.js $PATCH |
| 157 | + fi |
| 158 | +fi |
| 159 | + |
| 160 | +chroot /mnt/volumio/rootfs /bin/bash -x <<'EOF' |
| 161 | +su - |
| 162 | +/nanopineo3config.sh |
| 163 | +EOF |
| 164 | + |
| 165 | +UIVARIANT_FILE=/mnt/volumio/rootfs/UIVARIANT |
| 166 | +if [ -f "${UIVARIANT_FILE}" ]; then |
| 167 | + echo "Starting variant.js" |
| 168 | + node variant.js |
| 169 | + rm $UIVARIANT_FILE |
| 170 | +fi |
| 171 | + |
| 172 | +#cleanup |
| 173 | +rm /mnt/volumio/rootfs/root/init.sh /mnt/volumio/rootfs/nanopineo3config.sh /mnt/volumio/rootfs/root/init |
| 174 | + |
| 175 | +echo "Unmounting Temp devices" |
| 176 | +umount -l /mnt/volumio/rootfs/dev |
| 177 | +umount -l /mnt/volumio/rootfs/proc |
| 178 | +umount -l /mnt/volumio/rootfs/sys |
| 179 | + |
| 180 | +echo "==> nanopineo3 device installed" |
| 181 | + |
| 182 | +sync |
| 183 | + |
| 184 | +echo "Finalizing Rootfs creation" |
| 185 | +sh scripts/finalize.sh |
| 186 | + |
| 187 | +echo "Preparing rootfs base for SquashFS" |
| 188 | + |
| 189 | +if [ -d /mnt/squash ]; then |
| 190 | + echo "Volumio SquashFS Temp Dir Exists - Cleaning it" |
| 191 | + rm -rf /mnt/squash/* |
| 192 | +else |
| 193 | + echo "Creating Volumio SquashFS Temp Dir" |
| 194 | + mkdir /mnt/squash |
| 195 | +fi |
| 196 | + |
| 197 | +echo "Copying Volumio rootfs to Temp Dir" |
| 198 | +cp -rp /mnt/volumio/rootfs/* /mnt/squash/ |
| 199 | + |
| 200 | +if [ -e /mnt/kernel_current.tar ]; then |
| 201 | + echo "Volumio Kernel Partition Archive exists - Cleaning it" |
| 202 | + rm -rf /mnt/kernel_current.tar |
| 203 | +fi |
| 204 | + |
| 205 | +echo "Creating Kernel Partition Archive" |
| 206 | +tar cf /mnt/kernel_current.tar --exclude='resize-volumio-datapart' -C /mnt/squash/boot/ . |
| 207 | + |
| 208 | +echo "Removing the Kernel" |
| 209 | +rm -rf /mnt/squash/boot/* |
| 210 | + |
| 211 | +echo "Creating SquashFS, removing any previous one" |
| 212 | +rm -r Volumio.sqsh |
| 213 | +mksquashfs /mnt/squash/* Volumio.sqsh |
| 214 | + |
| 215 | +echo "Squash filesystem created" |
| 216 | +echo "Cleaning squash environment" |
| 217 | +rm -rf /mnt/squash |
| 218 | + |
| 219 | +#copy the squash image inside the boot partition |
| 220 | +cp Volumio.sqsh /mnt/volumio/images/volumio_current.sqsh |
| 221 | +sync |
| 222 | +echo "Unmounting Temp Devices" |
| 223 | +umount -l /mnt/volumio/images |
| 224 | +umount -l /mnt/volumio/rootfs/boot |
| 225 | + |
| 226 | +dmsetup remove_all |
| 227 | +losetup -d ${LOOP_DEV} |
| 228 | +sync |
| 229 | + |
| 230 | +md5sum "$IMG_FILE" > "${IMG_FILE}.md5" |
0 commit comments