From 2cfa289d3e70376b67d8911219f4292d3a6836f1 Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Fri, 12 May 2017 10:56:50 -0700 Subject: [PATCH] Image version safely treats slash in branch name (#596) --- build_debian.sh | 3 --- functions.sh | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index 5b58358e01..d2eaa43b3c 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -116,11 +116,8 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/linux-image-3.16.0-4-amd64_*.de ## Update initramfs for booting with squashfs+aufs cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null -IMAGE_VERSION=$(. functions.sh && sonic_get_version) - ## Hook into initramfs: change fs type from vfat to ext4 on arista switches sudo mkdir -p $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/ -sed -i -e "s/%%IMAGE_VERSION%%/$IMAGE_VERSION/g" files/initramfs-tools/arista-convertfs sudo cp files/initramfs-tools/arista-convertfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-convertfs sudo cp files/initramfs-tools/mke2fs $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/mke2fs diff --git a/functions.sh b/functions.sh index 8ca3d54223..c73aeb45d6 100644 --- a/functions.sh +++ b/functions.sh @@ -59,9 +59,10 @@ sonic_get_version() { fi BUILD_NUMBER=${BUILD_NUMBER:-0} ## Check if we are on tagged commit + ## Note: escape the version string by sed: / -> _ if [ "$describe" == "$latest_tag" ]; then - echo "${latest_tag}${dirty}" + echo "${latest_tag}${dirty}" | sed 's/\//_/g' else - echo "${branch_name}.${BUILD_NUMBER}${dirty:--$(git rev-parse --short HEAD)}" + echo "${branch_name}.${BUILD_NUMBER}${dirty:--$(git rev-parse --short HEAD)}" | sed 's/\//_/g' fi }