Skip to content

Commit 8d01893

Browse files
authored
Quote variables in destructive commands (#9400 P0) (#9401)
* extensions: image-output-abl: quote variables in destructive commands (#9400 P0) Quote all variable expansions passed to rm, mount, umount, losetup, mkfs, sed -i, cp, truncate, blkid, gzip, cat, e2fsck, resize2fs, and source to prevent word splitting. Replace `[ ! -z ]` with `[[ -n ]]`. * extensions: uwe5622-allwinner: quote variables in destructive commands (#9400 P0) Quote $SDCARD in chroot calls and $destination, $SRC, ${ARCH} in cp, mkdir, and install commands to prevent word splitting. * extensions: cloud-init: quote variables in destructive commands (#9400 P0) Quote ${config_src}, $config_dst, ${defaults_src}, $defaults_dst in cp commands and ${SDCARD} in rm -f commands to prevent word splitting. * extensions: lvm: quote variables in destructive commands (#9400 P0) Quote ${SDCARD}.raw, ${rootdevice}, ${LVM_VG_NAME}, ${volsize} in parted, pvcreate, vgcreate, lvcreate, e2label, blkid, and vgchange commands to prevent word splitting. * extensions: allwinner-kernel-bump: quote variables in destructive commands (#9400 P0) Quote ${patch_dir_base}, ${patch_dir_megous}, ${patch_dir_tmp}, ${kernel_work_dir}, ${bundle_file}, ${PREV_KERNEL_PATCH_DIR} in rm, cp, mv, mkdir, git, grep, sed -i, and cat commands. Fix unquoted array expansion: ${megous_trees[@]} → "${megous_trees[@]}". * lib: partitioning: quote variables in destructive commands (#9400 P0) Quote $SDCARD, $MOUNT, $rootdevice, ${LOOP}p${rootpart}, $bootscript_dst and other variables in rm, mount, umount, mkdir, sed -i, echo >>, mkfs, blkid, grep, and cat commands to prevent word splitting. Replace `[ -z ]` with `[[ -z ]]` on line guarding boot script output. Heredoc blocks inside call_extension_method are left unchanged. * extensions: image-output-abl: remove redundant cat before recovery image build The cat command creating Image.gz-${dtb_name} (where dtb_name holds the last loop value) was unnecessary: Image.gz-${ABL_DTB_LIST[0]} is already created by the for loop, and mkbootimg for the recovery image uses exactly that file. Fix per #9401 (comment)
1 parent d7caa68 commit 8d01893

6 files changed

Lines changed: 117 additions & 115 deletions

File tree

extensions/allwinner-kernel-bump.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ function extension_finish_config__prepare_megous_patches() {
3535
patch_dir_megous="${patch_dir_base}/patches.megous"
3636
patch_dir_tmp="${patch_dir_base}/patches.megi"
3737

38-
if [[ -d ${patch_dir_base} ]]; then
38+
if [[ -d "${patch_dir_base}" ]]; then
3939
display_alert "allwinner-kernel-bump" "Found existing kernel patch directory" "info"
4040
if [[ "${OVERWRITE_PATCHDIR:-no}" == "yes" ]]; then
4141
display_alert "allwinner-kernel-bump" "Removing as requested. Any manual changes will get overwritten" "info"
42-
rm -rf ${patch_dir_base}
42+
rm -rf "${patch_dir_base}"
4343
else
4444
display_alert "allwinner-kernel-bump" "Skipping kernel patch directory creation" "info"
4545
return 0
@@ -59,38 +59,38 @@ function extension_finish_config__prepare_megous_patches() {
5959
run_host_command_logged mkdir -pv "${git_bundles_dir}"
6060
run_host_command_logged rm "${bundle_file}" || true
6161
do_with_retries 5 axel "--output=${bundle_file}" "${bundle_url}"
62-
run_host_command_logged git -C ${kernel_work_dir} fetch ${bundle_file} '+refs/heads/*:refs/remotes/megous/*'
62+
run_host_command_logged git -C "${kernel_work_dir}" fetch "${bundle_file}" '+refs/heads/*:refs/remotes/megous/*'
6363

6464
display_alert "allwinner-kernel-bump" "Initializing kernel patch directory using previous kernel patch dir" "info"
65-
run_host_command_logged cp -aR ${PREV_KERNEL_PATCH_DIR} ${patch_dir_base}
65+
run_host_command_logged cp -aR "${PREV_KERNEL_PATCH_DIR}" "${patch_dir_base}"
6666

6767
# Removing older copy of megous patches and series.conf file
68-
run_host_command_logged rm -rf ${patch_dir_base}/patches.megous/*
69-
run_host_command_logged rm -f ${patch_dir_base}/series.{conf,megous}
68+
run_host_command_logged rm -rf "${patch_dir_base}"/patches.megous/*
69+
run_host_command_logged rm -f "${patch_dir_base}"/series.{conf,megous}
7070

7171
display_alert "allwinner-kernel-bump" "Extracting latest Megous patches" "info"
7272
megous_trees=("a83t-suspend" "af8133j" "anx" "audio" "axp" "cam" "drm"
7373
"err" "fixes" "mbus" "modem" "opi3" "pb" "pinetab" "pp" "ppkb" "samuel"
7474
"speed" "tbs-a711" "ths")
7575

76-
run_host_command_logged mkdir -p ${patch_dir_megous} ${patch_dir_tmp}
76+
run_host_command_logged mkdir -p "${patch_dir_megous}" "${patch_dir_tmp}"
7777

78-
for tree in ${megous_trees[@]}; do
79-
run_host_command_logged "${SRC}"/tools/mk_format_patch ${kernel_work_dir} master..megous/${tree}-${KERNEL_MAJOR_MINOR} ${patch_dir_megous} sufix=megi
80-
run_host_command_logged cp ${patch_dir_megous}/* ${patch_dir_tmp}
81-
run_host_command_logged cat ${patch_dir_base}/series.megous ">>" ${patch_dir_base}/series.megi
78+
for tree in "${megous_trees[@]}"; do
79+
run_host_command_logged "${SRC}"/tools/mk_format_patch "${kernel_work_dir}" "master..megous/${tree}-${KERNEL_MAJOR_MINOR}" "${patch_dir_megous}" sufix=megi
80+
run_host_command_logged cp "${patch_dir_megous}"/* "${patch_dir_tmp}"
81+
run_host_command_logged cat "${patch_dir_base}/series.megous" ">>" "${patch_dir_base}/series.megi"
8282
done
8383

84-
run_host_command_logged cp ${patch_dir_tmp}/* ${patch_dir_megous}
85-
run_host_command_logged mv ${patch_dir_base}/series.megi ${patch_dir_base}/series.megous
86-
run_host_command_logged rm -rf ${patch_dir_tmp} ${patch_dir_base}/series.megi
84+
run_host_command_logged cp "${patch_dir_tmp}"/* "${patch_dir_megous}"
85+
run_host_command_logged mv "${patch_dir_base}/series.megi" "${patch_dir_base}/series.megous"
86+
run_host_command_logged rm -rf "${patch_dir_tmp}" "${patch_dir_base}/series.megi"
8787

8888
# Disable previously disabled patches
89-
grep '^-' ${PREV_KERNEL_PATCH_DIR}/series.megous | awk -F / '{print $NF}' | xargs -I {} sed -i "/\/{}/s/^/-/g" ${patch_dir_base}/series.megous
89+
grep '^-' "${PREV_KERNEL_PATCH_DIR}/series.megous" | awk -F / '{print $NF}' | xargs -I {} sed -i "/\/{}/s/^/-/g" "${patch_dir_base}/series.megous"
9090

9191
display_alert "allwinner-kernel-bump" "Generating series.conf file" "info"
92-
run_host_command_logged cat ${patch_dir_base}/series.megous ">>" ${patch_dir_base}/series.conf
93-
run_host_command_logged cat ${patch_dir_base}/series.fixes ">>" ${patch_dir_base}/series.conf
94-
run_host_command_logged cat ${patch_dir_base}/series.armbian ">>" ${patch_dir_base}/series.conf
92+
run_host_command_logged cat "${patch_dir_base}/series.megous" ">>" "${patch_dir_base}/series.conf"
93+
run_host_command_logged cat "${patch_dir_base}/series.fixes" ">>" "${patch_dir_base}/series.conf"
94+
run_host_command_logged cat "${patch_dir_base}/series.armbian" ">>" "${patch_dir_base}/series.conf"
9595
fi
9696
}

extensions/cloud-init/cloud-init.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ function pre_customize_image__inject_cloud_init_config() {
4444
display_alert "Extension: ${EXTENSION}: Configuring" "cloud-init" "info"
4545
local config_src="${EXTENSION_DIR}/config"
4646
local config_dst="${SDCARD}/etc/cloud/cloud.cfg.d"
47-
run_host_command_logged cp ${config_src}/* $config_dst
47+
run_host_command_logged cp "${config_src}"/* "${config_dst}"
4848

4949
# Provide default cloud-init files
5050
display_alert "Extension: ${EXTENSION}: Defaults" "cloud-init" "info"
5151
local defaults_src="${EXTENSION_DIR}/defaults"
5252
local defaults_dst="${SDCARD}/boot"
53-
run_host_command_logged cp ${defaults_src}/* $defaults_dst
53+
run_host_command_logged cp "${defaults_src}"/* "${defaults_dst}"
5454
return 0
5555
}
5656

@@ -59,8 +59,8 @@ function pre_customize_image__disable_armbian_first_run() {
5959
display_alert "Extension: ${EXTENSION}: Disabling" "armbian firstrun" "info"
6060

6161
# Clean up default profile and network
62-
rm -f ${SDCARD}/etc/profile.d/armbian-check-first-*
63-
rm -f ${SDCARD}/etc/netplan/armbian-*
62+
rm -f "${SDCARD}"/etc/profile.d/armbian-check-first-*
63+
rm -f "${SDCARD}"/etc/netplan/armbian-*
6464

6565
# remove any networkd config leftover from armbian build
6666
rm -f "${SDCARD}"/etc/systemd/network/*.network || true

extensions/image-output-abl.sh

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,72 @@ function add_host_dependencies__abl_host_deps() {
55
function post_build_image__900_convert_to_abl_img() {
66
[[ -z $version ]] && exit_with_error "version is not set"
77

8-
if [ ! -z "$UEFI_GRUB_TARGET" ]; then
8+
if [[ -n "$UEFI_GRUB_TARGET" ]]; then
99
display_alert "Ignore" "${EXTENSION}" "info"
1010
return 0
1111
fi
1212

13-
if [ ! -z "$BOOTFS_TYPE" ]; then
13+
if [[ -n "$BOOTFS_TYPE" ]]; then
1414
return 0
1515
fi
1616

1717
display_alert "Converting image $version to rootfs" "${EXTENSION}" "info"
1818
declare -g ROOTFS_IMAGE_FILE="${DESTIMG}/${version}.rootfs.img"
19-
rootfs_start_sector=$(gdisk -l ${DESTIMG}/${version}.img | grep rootfs | awk '{print $2}')
20-
rootfs_end_sector=$(gdisk -l ${DESTIMG}/${version}.img | grep rootfs | awk '{print $3}')
19+
rootfs_start_sector=$(gdisk -l "${DESTIMG}/${version}.img" | grep rootfs | awk '{print $2}')
20+
rootfs_end_sector=$(gdisk -l "${DESTIMG}/${version}.img" | grep rootfs | awk '{print $3}')
2121
old_rootfs_image_mount_dir=${DESTIMG}/rootfs-old
2222
new_rootfs_image_mount_dir=${DESTIMG}/rootfs-new
23-
mkdir -p ${old_rootfs_image_mount_dir} ${new_rootfs_image_mount_dir}
24-
truncate --size=9728M ${ROOTFS_IMAGE_FILE}
25-
mkfs.ext4 -F ${ROOTFS_IMAGE_FILE}
26-
new_rootfs_image_uuid=$(blkid -s UUID -o value ${ROOTFS_IMAGE_FILE})
27-
old_image_loop_device=$(losetup -f -P --show ${DESTIMG}/${version}.img)
28-
old_rootfs_image_uuid=$(blkid -s UUID -o value ${old_image_loop_device}p1)
29-
mount ${old_image_loop_device}p1 ${old_rootfs_image_mount_dir}
30-
mount ${ROOTFS_IMAGE_FILE} ${new_rootfs_image_mount_dir}
31-
cp -rfp ${old_rootfs_image_mount_dir}/* ${new_rootfs_image_mount_dir}/
32-
umount ${old_rootfs_image_mount_dir}
33-
losetup -d ${old_image_loop_device}
34-
rm ${DESTIMG}/${version}.img
23+
mkdir -p "${old_rootfs_image_mount_dir}" "${new_rootfs_image_mount_dir}"
24+
truncate --size=9728M "${ROOTFS_IMAGE_FILE}"
25+
mkfs.ext4 -F "${ROOTFS_IMAGE_FILE}"
26+
new_rootfs_image_uuid=$(blkid -s UUID -o value "${ROOTFS_IMAGE_FILE}")
27+
old_image_loop_device=$(losetup -f -P --show "${DESTIMG}/${version}.img")
28+
old_rootfs_image_uuid=$(blkid -s UUID -o value "${old_image_loop_device}p1")
29+
mount "${old_image_loop_device}p1" "${old_rootfs_image_mount_dir}"
30+
mount "${ROOTFS_IMAGE_FILE}" "${new_rootfs_image_mount_dir}"
31+
cp -rfp "${old_rootfs_image_mount_dir}"/* "${new_rootfs_image_mount_dir}"/
32+
umount "${old_rootfs_image_mount_dir}"
33+
losetup -d "${old_image_loop_device}"
34+
rm "${DESTIMG}/${version}.img"
3535
display_alert "Replace root partition uuid from ${old_rootfs_image_uuid} to ${new_rootfs_image_uuid} in /etc/fstab" "${EXTENSION}" "info"
36-
sed -i "s|${old_rootfs_image_uuid}|${new_rootfs_image_uuid}|g" ${new_rootfs_image_mount_dir}/etc/fstab
37-
source ${new_rootfs_image_mount_dir}/boot/armbianEnv.txt
36+
sed -i "s|${old_rootfs_image_uuid}|${new_rootfs_image_uuid}|g" "${new_rootfs_image_mount_dir}/etc/fstab"
37+
source "${new_rootfs_image_mount_dir}/boot/armbianEnv.txt"
3838
declare -g bootimg_cmdline="${BOOTIMG_CMDLINE_EXTRA} root=UUID=${new_rootfs_image_uuid} slot_suffix=${abl_boot_partition_label#boot} ${extraargs}"
3939

40-
if [ ${#ABL_DTB_LIST[@]} -ne 0 ]; then
40+
if [[ ${#ABL_DTB_LIST[@]} -ne 0 ]]; then
4141
display_alert "Going to create abl kernel boot image" "${EXTENSION}" "info"
42-
gzip -c ${new_rootfs_image_mount_dir}/boot/vmlinuz-*-* > ${DESTIMG}/Image.gz
42+
gzip -c "${new_rootfs_image_mount_dir}"/boot/vmlinuz-*-* > "${DESTIMG}/Image.gz"
4343
for dtb_name in "${ABL_DTB_LIST[@]}"; do
4444
display_alert "Creatng abl kernel boot image with dtb ${dtb_name} and cmdline ${bootimg_cmdline} " "${EXTENSION}" "info"
45-
cat ${DESTIMG}/Image.gz ${new_rootfs_image_mount_dir}/usr/lib/linux-image-*/qcom/${dtb_name}.dtb > ${DESTIMG}/Image.gz-${dtb_name}
45+
cat "${DESTIMG}/Image.gz" "${new_rootfs_image_mount_dir}"/usr/lib/linux-image-*/qcom/"${dtb_name}.dtb" > "${DESTIMG}/Image.gz-${dtb_name}"
4646
/usr/bin/mkbootimg \
47-
--kernel ${DESTIMG}/Image.gz-${dtb_name} \
48-
--ramdisk ${new_rootfs_image_mount_dir}/boot/initrd.img-*-* \
47+
--kernel "${DESTIMG}/Image.gz-${dtb_name}" \
48+
--ramdisk "${new_rootfs_image_mount_dir}"/boot/initrd.img-*-* \
4949
--base 0x0 \
5050
--second_offset 0x00f00000 \
5151
--cmdline "${bootimg_cmdline}" \
5252
--kernel_offset 0x8000 \
5353
--ramdisk_offset 0x1000000 \
5454
--tags_offset 0x100 \
5555
--pagesize 4096 \
56-
-o ${DESTIMG}/${version}.boot_${dtb_name}.img
56+
-o "${DESTIMG}/${version}.boot_${dtb_name}.img"
5757
done
5858
display_alert "Creatng abl kernel boot recovery image with dtb ${ABL_DTB_LIST[0]}" "${EXTENSION}" "info"
59-
cat ${DESTIMG}/Image.gz ${new_rootfs_image_mount_dir}/usr/lib/linux-image-*/qcom/${dtb_name}.dtb > ${DESTIMG}/Image.gz-${dtb_name}
6059
/usr/bin/mkbootimg \
61-
--kernel ${DESTIMG}/Image.gz-${ABL_DTB_LIST[0]} \
62-
--ramdisk ${new_rootfs_image_mount_dir}/boot/initrd.img-*-* \
60+
--kernel "${DESTIMG}/Image.gz-${ABL_DTB_LIST[0]}" \
61+
--ramdisk "${new_rootfs_image_mount_dir}"/boot/initrd.img-*-* \
6362
--base 0x0 \
6463
--second_offset 0x00f00000 \
6564
--kernel_offset 0x8000 \
6665
--ramdisk_offset 0x1000000 \
6766
--tags_offset 0x100 \
6867
--pagesize 4096 \
69-
-o ${DESTIMG}/${version}.boot_recovery.img
68+
-o "${DESTIMG}/${version}.boot_recovery.img"
7069
fi
7170

72-
umount ${new_rootfs_image_mount_dir}
73-
rm -rf ${new_rootfs_image_mount_dir}
74-
e2fsck -p -f ${ROOTFS_IMAGE_FILE}
75-
resize2fs -M ${ROOTFS_IMAGE_FILE}
71+
umount "${new_rootfs_image_mount_dir}"
72+
rm -rf "${new_rootfs_image_mount_dir}"
73+
e2fsck -p -f "${ROOTFS_IMAGE_FILE}"
74+
resize2fs -M "${ROOTFS_IMAGE_FILE}"
7675
return 0
7776
}

extensions/lvm.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function extension_prepare_config__prepare_lvm() {
3333

3434
function post_create_partitions__setup_lvm() {
3535
# Setup LVM on the partition, ROOTFS
36-
parted -s ${SDCARD}.raw -- set ${rootpart} lvm on
36+
parted -s "${SDCARD}.raw" -- set "${rootpart}" lvm on
3737
display_alert "LVM Partition table created" "${EXTENSION}" "info"
38-
parted -s ${SDCARD}.raw -- print >> "${DEST}"/${LOG_SUBPATH}/lvm.log 2>&1
38+
parted -s "${SDCARD}.raw" -- print >> "${DEST}/${LOG_SUBPATH}/lvm.log" 2>&1
3939
}
4040

4141
function prepare_root_device__create_volume_group() {
@@ -52,25 +52,25 @@ function prepare_root_device__create_volume_group() {
5252

5353
# Create the PV VG and VOL
5454
display_alert "LVM Creating VG" "${rootdevice}" "info"
55-
check_loop_device ${rootdevice}
56-
pvcreate ${rootdevice}
55+
check_loop_device "${rootdevice}"
56+
pvcreate "${rootdevice}"
5757
wait_for_disk_sync "wait for pvcreate to sync"
58-
vgcreate ${LVM_VG_NAME} ${rootdevice}
58+
vgcreate "${LVM_VG_NAME}" "${rootdevice}"
5959
add_cleanup_handler cleanup_lvm
6060
wait_for_disk_sync "wait for vgcreate to sync"
6161
# Note that devices wont come up automatically inside docker
62-
lvcreate -Zn --name root --size ${volsize}M ${LVM_VG_NAME}
62+
lvcreate -Zn --name root --size "${volsize}M" "${LVM_VG_NAME}"
6363
vgmknodes
64-
lvs >> "${DEST}"/${LOG_SUBPATH}/lvm.log 2>&1
65-
66-
rootdevice=/dev/mapper/${LVM_VG_NAME}-root
64+
lvs >> "${DEST}/${LOG_SUBPATH}/lvm.log" 2>&1
65+
66+
rootdevice="/dev/mapper/${LVM_VG_NAME}-root"
6767
display_alert "LVM created volume group - root device ${rootdevice}" "${EXTENSION}" "info"
6868
}
6969

7070
function format_partitions__format_lvm() {
7171
# Label the root volume
72-
e2label /dev/mapper/${LVM_VG_NAME}-root armbi_root
73-
blkid | grep ${LVM_VG_NAME} >> "${DEST}"/${LOG_SUBPATH}/lvm.log 2>&1
72+
e2label "/dev/mapper/${LVM_VG_NAME}-root" armbi_root
73+
blkid | grep "${LVM_VG_NAME}" >> "${DEST}/${LOG_SUBPATH}/lvm.log" 2>&1
7474
display_alert "LVM labeled partitions" "${EXTENSION}" "info"
7575
}
7676

@@ -79,6 +79,6 @@ function post_umount_final_image__cleanup_lvm(){
7979
}
8080

8181
function cleanup_lvm() {
82-
vgchange -a n ${LVM_VG_NAME} >> "${DEST}"/${LOG_SUBPATH}/lvm.log 2>&1 || true
82+
vgchange -a n "${LVM_VG_NAME}" >> "${DEST}/${LOG_SUBPATH}/lvm.log" 2>&1 || true
8383
display_alert "LVM deactivated volume group" "${EXTENSION}" "info"
8484
}

extensions/uwe5622-allwinner.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function post_family_config__add_uwe5622_modules() {
1111

1212
function post_family_tweaks__enable_uwe5622_services() {
1313
# install and enable Bluetooth
14-
chroot $SDCARD /bin/bash -c "systemctl --no-reload enable aw859a-bluetooth.service >/dev/null 2>&1"
15-
chroot $SDCARD /bin/bash -c "systemctl --no-reload enable aw859a-wifi.service >/dev/null 2>&1"
14+
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable aw859a-bluetooth.service >/dev/null 2>&1"
15+
chroot "${SDCARD}" /bin/bash -c "systemctl --no-reload enable aw859a-wifi.service >/dev/null 2>&1"
1616
}
1717

1818
function post_family_tweaks_bsp__add_uwe5622_services() {
19-
run_host_command_logged mkdir -p $destination/lib/systemd/system/
20-
run_host_command_logged cp $SRC/packages/bsp/sunxi/aw859a-bluetooth.service $destination/lib/systemd/system/
21-
run_host_command_logged cp $SRC/packages/bsp/sunxi/aw859a-wifi.service $destination/lib/systemd/system/
22-
run_host_command_logged install -m 755 $SRC/packages/blobs/bt/hciattach/hciattach_opi_${ARCH} $destination/usr/bin/hciattach_opi
19+
run_host_command_logged mkdir -p "${destination}/lib/systemd/system/"
20+
run_host_command_logged cp "${SRC}/packages/bsp/sunxi/aw859a-bluetooth.service" "${destination}/lib/systemd/system/"
21+
run_host_command_logged cp "${SRC}/packages/bsp/sunxi/aw859a-wifi.service" "${destination}/lib/systemd/system/"
22+
run_host_command_logged install -m 755 "${SRC}/packages/blobs/bt/hciattach/hciattach_opi_${ARCH}" "${destination}/usr/bin/hciattach_opi"
2323
}

0 commit comments

Comments
 (0)