metal/bsp-files/pxeboot_setup.sh
Sun Austin fedb95ba79 Fix linters issues and enable tox/zuul linters job as gate
Fix below linters issues
 E001 Trailing Whitespace
 E003 Indent not multiple of 4
 E006 Line too long
 E011 Then keyword is not on same line as if or elif keyword
 E020 Function declaration not in format ^function name {$
 E040 Syntax error: syntax error near unexpected token `;'

ignore cases are added in tox setup
 E006 Line too long
 E010: do not on the same line as for

Story: 2003368
Task: 24427

Change-Id: I6acf64271a4e608be8bc8fa965cac4fa31e0c05b
Signed-off-by: Sun Austin <austin.sun@intel.com>
2018-09-05 09:02:25 +08:00

112 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
OPTIND=1
BASE_URL=""
TFTP_DIR=""
WORKING_DIR=""
COPY_DIR=""
ISODIR=$(dirname `readlink -f $0`)
usage() {
echo "Usage: $0 -u <http base URL> [-t <tftp pxeboot directory>] or [-w <working directory>]" 1>&2;
exit 0;
}
while getopts ":u:t:w:" opt; do
case "$opt" in
u)
BASE_URL=${OPTARG}
;;
t)
TFTP_DIR=${OPTARG}
;;
w)
WORKING_DIR=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "$BASE_URL" ]; then
echo "HTTP base URL is required: -u <http base URL>"
exit 0
fi
if [ -z "$TFTP_DIR" ] && [ -z "$WORKING_DIR" ]; then
echo "Either tftp pxeboot directory or working directory has to be specified:"
echo "-t <tftp pxeboot directory> or -w <working directory>"
exit 0
elif [ -n "$TFTP_DIR" ]; then
if [ -n "$WORKING_DIR" ]; then
echo "tftp pxeboot directory is supplied, working directory will be ignored."
fi
COPY_DIR=$TFTP_DIR
elif [ -n "$WORKING_DIR" ]; then
COPY_DIR=$WORKING_DIR
fi
if [ ! -d ${COPY_DIR} ] ; then
if [ -w "$(dirname $COPY_DIR)" ]; then
echo "Create ${COPY_DIR}"
mkdir ${COPY_DIR}
chmod +w ${COPY_DIR}
if [ $? -ne 0 ]; then
echo "Can't create ${COPY_DIR}"
exit 1
fi
else
echo "$COPY_DIR parent directory is not writeable."
exit 0
fi
else
echo "$COPY_DIR already exists"
exit 0
fi
#Copy the vmlinuz and initrd files to the destination directory
cp ${ISODIR}/vmlinuz ${COPY_DIR}/
cp ${ISODIR}/initrd.img ${COPY_DIR}/
#Copy the contents of distribution to the destination directory
cp -r ${ISODIR}/* ${COPY_DIR}/
#Find the number of directories in the URL
dirpath=$(echo ${BASE_URL#"http://"})
DIRS=$(grep -o "/" <<< "$dirpath" | wc -l)
#Escape path for sed
BASE_URL="${BASE_URL//\//\\/}"
#Copy pxeboot files
mkdir -p ${COPY_DIR}/EFI/centos/x86_64-efi/
cp -Rf ${COPY_DIR}/pxeboot/* ${COPY_DIR}/
#Rename the UEFI grub config
mv ${COPY_DIR}/pxeboot_grub.cfg ${COPY_DIR}/grub.cfg
#Variable replacement
sed -i "s#xxxHTTP_URLxxx#${BASE_URL}#g;
s#xxxHTTP_URL_PATCHESxxx#${BASE_URL}/patches#g;
s#NUM_DIRS#${DIRS}#g" \
${COPY_DIR}/pxeboot.cfg \
${COPY_DIR}/grub.cfg \
${COPY_DIR}/pxeboot_controller.cfg \
${COPY_DIR}/pxeboot_smallsystem.cfg \
${COPY_DIR}/pxeboot_smallsystem_lowlatency.cfg
# Delete unnecessary files
rm -Rf ${COPY_DIR}/EFI/BOOT
rm -Rf ${COPY_DIR}/pxeboot
if [ -n "$TFTP_DIR" ]; then
#Create pxelinux.cfg directory and default link
mkdir ${TFTP_DIR}/pxelinux.cfg
chmod 755 ${TFTP_DIR}/pxelinux.cfg
ln -s ../pxeboot.cfg ${TFTP_DIR}/pxelinux.cfg/default
fi