Script error in gitlab

Hi Team,

I am facing error as “deploy9.sh: line 55: Syntax error: unexpected end of file” while executing script through gitlab. but same script executes fine on linux server but not on gitlab ci. below is the yml file and script.

error

script:

#!/bin/bash

replacing BOOT files

echo “replacing the original files…”
cp -r /apps/iso/Rocky9/grub.cfg_orig /apps/iso/Rocky9/dir9/EFI/BOOT/grub.cfg
cp -r /apps/iso/Rocky9/isolinux.cfg_orig /apps/iso/Rocky9/dir9/isolinux/isolinux.cfg
rm -rf /apps/iso/Rocky9/dir9/ks9full.cfg
rm -rf /apps/iso/Rocky9/dir9/isolinux/ks9full.cfg
echo “all files modified…”

Set the paths for your input ISO, output ISO, and Kickstart file

INPUT_ISO=“/tmp/Rocky-9-latest-x86_64-dvd.iso”
OUTPUT_ISO=“/apps/iso/Rocky9/Rocky9-ASMS.iso”
KICKSTART_FILE=“/apps/iso/Rocky9/ks9full.cfg”
ISO_DIR=“/apps/iso/Rocky9/dir9”

Create a directory to store the Kickstart file in the ISO

cp -pr /apps/iso/Rocky9/ks9full.cfg /apps/iso/Rocky9/dir9
cp -pr /apps/iso/Rocky9/ks9full.cfg /apps/iso/Rocky9/dir9/isolinux

Modify the isolinux.cfg to use the Kickstart file

ISOLINUX_CFG=“$ISO_DIR/isolinux/isolinux.cfg”
if [ -f “$ISOLINUX_CFG” ];then
echo “Modifying isolinux.cfg to use Kickstart file”
sed -i ‘/append/ s/$/ inst.ks=hd:LABEL=Rocky-9-5-x86_64-dvd:/ks9full.cfg inst.kdump_addon=off/’ /apps/iso/Rocky9/dir9/isolinux/isolinux.cfg
else
echo “isolinux.cfg not found!”
fi

Modify the grub.cfg to use the Kickstart file

GRUB_CFG=“$ISO_DIR/EFI/BOOT/grub.cfg”
if [ -f “$GRUB_CFG” ]; then
echo “Modifying grub.cfg to use Kickstart file”
sed -i ‘/linuxefi/ s/$/ inst.ks=hd:LABEL=Rocky-9-5-x86_64-dvd:/ks9full.cfg inst.kdump_addon=off/’ $GRUB_CFG
else
echo “grub.cfg not found!”
fi

Path to your isolinux.cfg file

CONFIG_FILE=“/apps/iso/Rocky9/dir9/isolinux/isolinux.cfg”

Add “menu default” below “menu label ^Install Rocky Linux 9.5”

sed -i ‘/menu label ^Install Rocky Linux 9.5/a\menu default’ “$CONFIG_FILE”

Remove “menu default” after the line “menu label Test this ^media & install Rocky Linux 9.5”

sed -i ‘/menu label Test this ^media & install Rocky Linux 9.5/,+1{/menu default/d}’ “$CONFIG_FILE”

echo “Changes made successfully.”

Create the custom ISO using the specified xorriso command

echo “Creating custom ISO with xorriso”
/usr/bin/xorriso -indev /tmp/Rocky-9-latest-x86_64-dvd.iso -outdev Rocky9-ASMS.iso -boot_image any replay -joliet on -system_id LINUX -compliance joliet_long_names -volid Rocky-9-5-x86_64-dvd -map $KICKSTART_FILE /ks9full.cfg -map $ISO_DIR/EFI/BOOT/grub.cfg EFI/BOOT/grub.cfg -map $ISO_DIR/isolinux/ks9full.cfg isolinux/ks9full.cfg -map $ISO_DIR/isolinux/isolinux.cfg isolinux/isolinux.cfg
echo “Custom ISO created: $OUTPUT_ISO”

Implanting MD5 Checksum

echo “Implanting MD5 Checksum…”
implantisomd5 /packer/builds/UHXjvc-FZ/0/charter/cde/cloud-engineering/golden-image-team/packer-iso/Rocky9-ASMS.iso
echo “Operation complete!”

same script works on linux server but not on gitlab ci.

please help in resolving this issue.

Thanks in advance.

Hi,

What executor is used to run the job?
If it’s a docker executor, which docker image is being used?

In general, I’d advice checking your bash script if it uses CRLF or LF endings → make sure it uses LF endings and commit it that way, making sure git does not change it.

Hi Paula,

Thanks for the response.

No it’s not docker image but it’s Rocky Linux 9 image.

i used vscode and set LF endings and pasted in gitlab and committed. still getting same error.

is there any other way to check in gitlab as it is working fine in linux server.

Okay. But do you use self-hosted runners, or SaaS runners? If so, which executor? You are using golden-image-creation tag, so you must know which kind of runner is it?

If the script works on Rocky Linux, it should work the same in GitLab CI, if you use the exact same OS and shell type.

Also, try executing the script just like this:
./deploy9.sh

I would also help to post the exact content of deploy9.sh in a properly formatted post here on the forum using the tools available in the post window. At least that way we would be able to determine what is on line 55 or 57. Because your first post here is such a mess with info just posted and not using the formatting tools to make it more legible and easier to read. Eg:

#!/bin/bash
#

rest of script

would help.

Hi iwalker, it is erroring on extreme last line that does not exists. suspecting there must be some syntax issue but not getting to the exact point. here is the script.

#!/bin/bash
# replacing BOOT files
echo "replacing the original files..."
cp -r /apps/iso/Rocky9/grub.cfg_orig /apps/iso/Rocky9/dir9/EFI/BOOT/grub.cfg
cp -r /apps/iso/Rocky9/isolinux.cfg_orig /apps/iso/Rocky9/dir9/isolinux/isolinux.cfg
rm -rf /apps/iso/Rocky9/dir9/ks9.cfg
rm -rf /apps/iso/Rocky9/dir9/isolinux/ks9.cfg
echo "all files modified..."
# Set the paths for your input ISO, output ISO, and Kickstart file
INPUT_ISO="/tmp/Rocky-9-latest-x86_64-dvd.iso"
OUTPUT_ISO="/apps/iso/Rocky9/Rocky9-ASMS.iso"
KICKSTART_FILE="/apps/iso/Rocky9/ks9.cfg"
ISO_DIR="/apps/iso/Rocky9/dir9"
# Store the Kickstart file in the ISO
cp -p /apps/iso/Rocky9/ks9.cfg /apps/iso/Rocky9/dir9
cp -p /apps/iso/Rocky9/ks9.cfg /apps/iso/Rocky9/dir9/isolinux
# Modify the isolinux.cfg to use the Kickstart file
ISOLINUX_CFG="$ISO_DIR/isolinux/isolinux.cfg"
if [ -f "$ISOLINUX_CFG" ]; then
  echo "Modifying isolinux.cfg to use Kickstart file"
  sed -i '/append/ s/$/ inst.ks=hd:LABEL=Rocky-9-5-x86_64-dvd:\/ks9.cfg inst.kdump_addon=off/' $ISOLINUX_CFG
else
  echo "isolinux.cfg not found!"
fi
# Modify the grub.cfg to use the Kickstart file
GRUB_CFG="$ISO_DIR/EFI/BOOT/grub.cfg"
if [ -f "$GRUB_CFG" ]; then
  echo "Modifying grub.cfg to use Kickstart file"
  sed -i '/linuxefi/ s/$/ inst.ks=hd:LABEL=Rocky-9-5-x86_64-dvd:\/ks9.cfg inst.kdump_addon=off/' $GRUB_CFG
else
  echo "grub.cfg not found!"
fi
# Path to your isolinux.cfg file
CONFIG_FILE="/apps/iso/Rocky9/dir9/isolinux/isolinux.cfg"
# Add "menu default" below "menu label ^Install Rocky Linux 9.5"
sed -i '/menu label \^Install Rocky Linux 9.5/a\menu default' "$CONFIG_FILE"
# Remove "menu default" after the line "menu label Test this ^media & install Rocky Linux 9.5"
sed -i '/menu label Test this \^media & install Rocky Linux 9.5/,+1{/menu default/d}' "$CONFIG_FILE"
echo "Changes made successfully."
# Create the custom ISO using the specified xorriso command
echo "Creating custom ISO with xorriso"
/usr/bin/xorriso -indev /tmp/Rocky-9-latest-x86_64-dvd.iso -outdev Rocky9-ASMS.iso -boot_image any replay -joliet on -system_id LINUX -compliance joliet_long_names -volid Rocky-9-5-x86_64-dvd -map $KICKSTART_FILE /ks9.cfg -map $ISO_DIR/EFI/BOOT/grub.cfg EFI/BOOT/grub.cfg -map $ISO_DIR/isolinux/ks9.cfg isolinux/ks9.cfg -map $ISO_DIR/isolinux/isolinux.cfg isolinux/isolinux.cfg
echo "Custom ISO created: $OUTPUT_ISO"
# Implanting MD5 Checksum
echo "Implanting MD5 Checksum..."
implantisomd5 /apps/iso/Rocky9/Rocky9-ASMS.iso
echo "Operation complete!"

I don’t see any syntax errors in that, but in case there is some weird hidden character in it, you can do this:

dos2unix deploy9.sh

About the only thing is on line 10 you set INPUT_ISO but then never use it, although it could have been used on line 42 where you use xorriso.

Hi All,

I removed everything and reconfigured .gitlab-ci.yml file and deploy9 script through vscode and set to LF. now it is working fine.

Thank you very much for your valuable assistance.

I don’t see anything obvious, like mismatched quotes or parenthesis. By any chance, are you developing this script in a Windows environment, saving it to GitLab and executing on a windows GitLab Runner? This can cause a problem with the line endings in the script that can be corrected by using either dos2unix or unix2dos (on a *nix machine) to fix the line ending issues.