Skip to content

Commit 89bd082

Browse files
authored
rpi: Fix shellcheck warnings for build script (elementary#462)
1 parent 9d924c9 commit 89bd082

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

build-rpi.sh

+41-40
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ apt-get install -y --no-install-recommends ubuntu-keyring ca-certificates deboot
99
# Make sure cross-running ARM ELF executables is enabled
1010
update-binfmts --enable
1111

12-
rootdir=`pwd`
13-
basedir=`pwd`/artifacts/elementary-rpi
12+
rootdir=$(pwd)
13+
basedir=$(pwd)/artifacts/elementary-rpi
1414

1515
# Free space on rootfs in MiB
1616
free_space="500"
@@ -24,8 +24,8 @@ version=6.0
2424
YYYYMMDD="$(date +%Y%m%d)"
2525
imagename=elementaryos-$version-$channel-rpi-$YYYYMMDD
2626

27-
mkdir -p ${basedir}
28-
cd ${basedir}
27+
mkdir -p "${basedir}"
28+
cd "${basedir}"
2929

3030
# Bootstrap an ubuntu minimal system
3131
debootstrap --foreign --arch $architecture $codename elementary-$architecture http://ports.ubuntu.com/ubuntu-ports
@@ -37,7 +37,7 @@ cp /usr/bin/qemu-arm-static elementary-$architecture/usr/bin/
3737
LANG=C chroot elementary-$architecture /debootstrap/debootstrap --second-stage
3838

3939
# Copy Raspberry Pi specific files
40-
cp -r ${rootdir}/rpi/rootfs/writable/* elementary-${architecture}/
40+
cp -r "${rootdir}"/rpi/rootfs/writable/* elementary-${architecture}/
4141

4242
# Add the rest of the ubuntu repos
4343
cat << EOF > elementary-$architecture/etc/apt/sources.list
@@ -46,9 +46,9 @@ deb http://ports.ubuntu.com/ubuntu-ports $codename-updates main restricted unive
4646
EOF
4747

4848
# Copy in the elementary PPAs/keys/apt config
49-
for f in ${rootdir}/etc/config/archives/*.list; do cp -- "$f" "elementary-$architecture/etc/apt/sources.list.d/$(basename -- $f)"; done
50-
for f in ${rootdir}/etc/config/archives/*.key; do cp -- "$f" "elementary-$architecture/etc/apt/trusted.gpg.d/$(basename -- $f).asc"; done
51-
for f in ${rootdir}/etc/config/archives/*.pref; do cp -- "$f" "elementary-$architecture/etc/apt/preferences.d/$(basename -- $f)"; done
49+
for f in "${rootdir}"/etc/config/archives/*.list; do cp -- "$f" "elementary-$architecture/etc/apt/sources.list.d/$(basename -- "$f")"; done
50+
for f in "${rootdir}"/etc/config/archives/*.key; do cp -- "$f" "elementary-$architecture/etc/apt/trusted.gpg.d/$(basename -- "$f").asc"; done
51+
for f in "${rootdir}"/etc/config/archives/*.pref; do cp -- "$f" "elementary-$architecture/etc/apt/preferences.d/$(basename -- "$f")"; done
5252

5353
# Set codename/channel in added repos
5454
sed -i "s/@CHANNEL/$channel/" elementary-$architecture/etc/apt/sources.list.d/*.list*
@@ -121,22 +121,23 @@ chmod +x elementary-$architecture/hardware
121121
LANG=C chroot elementary-$architecture /hardware
122122

123123
# Copy in any file overrides
124-
cp -r ${rootdir}/etc/config/includes.chroot/* elementary-$architecture/
124+
cp -r "${rootdir}"/etc/config/includes.chroot/* elementary-$architecture/
125125

126126
mkdir elementary-$architecture/hooks
127-
cp ${rootdir}/etc/config/hooks/live/*.chroot elementary-$architecture/hooks
127+
cp "${rootdir}"/etc/config/hooks/live/*.chroot elementary-$architecture/hooks
128128

129-
for f in elementary-$architecture/hooks/*
129+
hook_files="elementary-$architecture/hooks/*"
130+
for f in $hook_files
130131
do
131-
base=`basename ${f}`
132+
base=$(basename "${f}")
132133
LANG=C chroot elementary-$architecture "/hooks/${base}"
133134
done
134135

135136
rm -r "elementary-$architecture/hooks"
136137

137138
# Add a oneshot service to grow the rootfs on first boot
138-
install -m 755 -o root -g root ${rootdir}/rpi/files/resizerootfs "elementary-$architecture/usr/sbin/resizerootfs"
139-
install -m 644 -o root -g root ${rootdir}/pinebookpro/files/resizerootfs.service "elementary-$architecture/etc/systemd/system"
139+
install -m 755 -o root -g root "${rootdir}/rpi/files/resizerootfs" "elementary-$architecture/usr/sbin/resizerootfs"
140+
install -m 644 -o root -g root "${rootdir}/pinebookpro/files/resizerootfs.service" "elementary-$architecture/etc/systemd/system"
140141
mkdir -p "elementary-$architecture/etc/systemd/system/systemd-remount-fs.service.requires/"
141142
ln -s /etc/systemd/system/resizerootfs.service "elementary-$architecture/etc/systemd/system/systemd-remount-fs.service.requires/resizerootfs.service"
142143

@@ -154,42 +155,42 @@ EOF
154155

155156
# Calculate the space to create the image.
156157
root_size=$(du -s -B1K elementary-$architecture | cut -f1)
157-
raw_size=$(($((${free_space}*1024))+${root_size}))
158+
raw_size=$(($((free_space*1024))+root_size))
158159

159160
# Create the disk and partition it
160161
echo "Creating image file"
161162

162163
# Sometimes fallocate fails if the filesystem or location doesn't support it, fallback to slower dd in this case
163-
if ! fallocate -l $(echo ${raw_size}Ki | numfmt --from=iec-i --to=si --format=%.1f) ${basedir}/${imagename}.img
164+
if ! fallocate -l "$(echo ${raw_size}Ki | numfmt --from=iec-i --to=si --format=%.1f)" "${basedir}/${imagename}.img"
164165
then
165-
dd if=/dev/zero of=${basedir}/${imagename}.img bs=1024 count=${raw_size}
166+
dd if=/dev/zero of="${basedir}/${imagename}.img" bs=1024 count=${raw_size}
166167
fi
167168

168-
parted ${imagename}.img --script -- mklabel msdos
169-
parted ${imagename}.img --script -- mkpart primary fat32 0 256
170-
parted ${imagename}.img --script -- mkpart primary ext4 256 -1
169+
parted "${imagename}.img" --script -- mklabel msdos
170+
parted "${imagename}.img" --script -- mkpart primary fat32 0 256
171+
parted "${imagename}.img" --script -- mkpart primary ext4 256 -1
171172

172173
# Set the partition variables
173-
loopdevice=`losetup -f --show ${basedir}/${imagename}.img`
174-
device=`kpartx -va $loopdevice| sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
174+
loopdevice=$(losetup -f --show "${basedir}/${imagename}.img")
175+
device=$(kpartx -va "$loopdevice" | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1)
175176
device="/dev/mapper/${device}"
176177
bootp=${device}p1
177178
rootp=${device}p2
178179

179180
# Create file systems
180-
mkfs.vfat -n system-boot $bootp
181-
mkfs.ext4 -L writable $rootp
181+
mkfs.vfat -n system-boot "$bootp"
182+
mkfs.ext4 -L writable "$rootp"
182183

183184
# Create the dirs for the partitions and mount them
184-
mkdir -p ${basedir}/bootp ${basedir}/root
185-
mount -t vfat $bootp ${basedir}/bootp
186-
mount $rootp ${basedir}/root
185+
mkdir -p "${basedir}/bootp" "${basedir}/root"
186+
mount -t vfat "$bootp" "${basedir}/bootp"
187+
mount "$rootp" "${basedir}/root"
187188

188189
mkdir -p elementary-$architecture/boot/firmware
189-
mount -o bind ${basedir}/bootp/ elementary-$architecture/boot/firmware
190+
mount -o bind "${basedir}/bootp/" elementary-$architecture/boot/firmware
190191

191192
# Copy Raspberry Pi specific files
192-
cp -r ${rootdir}/rpi/rootfs/system-boot/* elementary-${architecture}/boot/firmware/
193+
cp -r "${rootdir}"/rpi/rootfs/system-boot/* elementary-${architecture}/boot/firmware/
193194

194195
# Copy kernels and firemware to boot partition
195196
cat << EOF > elementary-$architecture/hardware
@@ -210,31 +211,31 @@ LANG=C chroot elementary-$architecture /hardware
210211

211212
# Grab some updated firmware from the Raspberry Pi foundation
212213
git clone -b '1.20201022' --single-branch --depth 1 https://github.com/raspberrypi/firmware raspi-firmware
213-
cp raspi-firmware/boot/*.elf ${basedir}/bootp/
214-
cp raspi-firmware/boot/*.dat ${basedir}/bootp/
215-
cp raspi-firmware/boot/bootcode.bin ${basedir}/bootp/
214+
cp raspi-firmware/boot/*.elf "${basedir}/bootp/"
215+
cp raspi-firmware/boot/*.dat "${basedir}/bootp/"
216+
cp raspi-firmware/boot/bootcode.bin "${basedir}/bootp/"
216217

217218
umount elementary-$architecture/dev/pts
218219
umount elementary-$architecture/dev/
219220
umount elementary-$architecture/proc
220221
umount elementary-$architecture/boot/firmware
221222

222223
echo "Rsyncing rootfs into image file"
223-
rsync -HPavz -q ${basedir}/elementary-$architecture/ ${basedir}/root/
224+
rsync -HPavz -q "${basedir}/elementary-$architecture/" "${basedir}/root/"
224225

225226
# Unmount partitions
226-
umount $bootp
227-
umount $rootp
228-
kpartx -dv $loopdevice
229-
losetup -d $loopdevice
227+
umount "$bootp"
228+
umount "$rootp"
229+
kpartx -dv "$loopdevice"
230+
losetup -d "$loopdevice"
230231

231232
echo "Compressing ${imagename}.img"
232-
xz -T0 -z ${basedir}/${imagename}.img
233+
xz -T0 -z "${basedir}/${imagename}.img"
233234

234235
cd "${basedir}"
235236

236-
md5sum ${imagename}.img.xz > ${imagename}.md5.txt
237-
sha256sum ${imagename}.img.xz > ${imagename}.sha256.txt
237+
md5sum "${imagename}.img.xz" > "${imagename}.md5.txt"
238+
sha256sum "${imagename}.img.xz" > "${imagename}.sha256.txt"
238239

239240
cd "${rootdir}"
240241

0 commit comments

Comments
 (0)