04b694454a
[sonic-cfggen] Remove machine.conf info and add get_system_mac support
210 lines
7.7 KiB
Bash
Executable File
210 lines
7.7 KiB
Bash
Executable File
#!/bin/sh -x
|
|
#
|
|
# rc.local
|
|
#
|
|
# This script is executed at the end of each multiuser runlevel.
|
|
# Make sure that the script will "exit 0" on success or any other
|
|
# value on error.
|
|
#
|
|
# In order to enable or disable this script just change the execution
|
|
# bits.
|
|
#
|
|
# By default this script does nothing.
|
|
|
|
# If the machine.conf is absent, it indicates that the unit booted
|
|
# into SONiC from another NOS. Extract the machine.conf from ONIE.
|
|
if [ ! -e /host/machine.conf ]; then
|
|
onie_dev=$(blkid | grep ONIE-BOOT | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
|
|
mkdir -p /mnt/onie-boot
|
|
mount $onie_dev /mnt/onie-boot
|
|
onie_grub_cfg=/mnt/onie-boot/onie/grub/grub-machine.cfg
|
|
|
|
if [ ! -e $onie_grub_cfg ]; then
|
|
echo "$onie_grub_cfg not found" >> /etc/migration.log
|
|
else
|
|
. ./$onie_grub_cfg
|
|
grep = $onie_grub_cfg | sed -e 's/onie_//' -e 's/=.*$//' | while read var ; do
|
|
eval val='$'onie_$var
|
|
echo "onie_${var}=${val}" >> /host/machine.conf
|
|
done
|
|
fi
|
|
|
|
migration="TRUE"
|
|
umount /mnt/onie-boot
|
|
fi
|
|
|
|
. /host/machine.conf
|
|
|
|
echo "install platform dependent packages at the first boot time"
|
|
|
|
firsttime_exit()
|
|
{
|
|
rm /host/image-$sonic_version/platform/firsttime
|
|
exit 0
|
|
}
|
|
|
|
test_config()
|
|
{
|
|
if [ -d /host/old_config ] && ( [ -f /host/old_config/minigraph.xml ] || [ -f /host/old_config/config_db.json ] ); then
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
# Given a string of tuples of the form field=value, extract the value for a field
|
|
# In : $string, $field
|
|
# Out: $value
|
|
value_extract()
|
|
{
|
|
set -- $string
|
|
for x in "$@"; do
|
|
case "$x" in
|
|
$field=*)
|
|
value="${x#$field=}"
|
|
esac
|
|
done
|
|
}
|
|
|
|
sonic_version=$(cat /etc/sonic/sonic_version.yml | grep build_version | cut -f2 -d" ")
|
|
|
|
if [ -f /host/image-$sonic_version/platform/firsttime ]; then
|
|
|
|
if [ -n "$aboot_platform" ]; then
|
|
platform=$aboot_platform
|
|
elif [ -n "$onie_platform" ]; then
|
|
platform=$onie_platform
|
|
else
|
|
echo "Unknown sonic platform"
|
|
firsttime_exit
|
|
fi
|
|
|
|
if [ ! -f /etc/sonic/init_cfg.json ]; then
|
|
# Generate an empty init_cfg.json
|
|
echo '{}' > /etc/sonic/init_cfg.json
|
|
fi
|
|
|
|
# Try to take old configuration saved during installation
|
|
if test_config; then
|
|
rm -f /host/old_config/sonic_version.yml
|
|
mv -f /host/old_config/* /etc/sonic/
|
|
if [ ! -f /etc/sonic/config_db.json ]; then
|
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
|
fi
|
|
elif [ -f /host/minigraph.xml ]; then
|
|
mv /host/minigraph.xml /etc/sonic/
|
|
# Combine information in minigraph and init_cfg.json to form initiate config DB dump file.
|
|
# TODO: After moving all information from minigraph to DB, sample config DB dump should be provide
|
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
|
else
|
|
# Use default minigraph.xml
|
|
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/
|
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
|
fi
|
|
|
|
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v DEVICE_METADATA.localhost.hwsku`
|
|
if [ -f /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 ]; then
|
|
# generate and merge buffers configuration into config file
|
|
sonic-cfggen -m -t /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 > /tmp/buffers.json
|
|
sonic-cfggen -j /etc/sonic/config_db.json -j /tmp/buffers.json --print-data > /tmp/config_db.json
|
|
mv /tmp/config_db.json /etc/sonic/config_db.json
|
|
|
|
# Only apply qos.json when buffer configuration is available.
|
|
if [ -f /usr/share/sonic/device/$platform/$HWSKU/qos.json ]; then
|
|
# merge qos configuration into init config file
|
|
sonic-cfggen -j /etc/sonic/config_db.json -j /usr/share/sonic/device/$platform/$HWSKU/qos.json --print-data > /tmp/config_db.json
|
|
mv /tmp/config_db.json /etc/sonic/config_db.json
|
|
fi
|
|
fi
|
|
|
|
if [ -d /host/image-$sonic_version/platform/$platform ]; then
|
|
dpkg -i /host/image-$sonic_version/platform/$platform/*.deb
|
|
fi
|
|
|
|
# If the unit booted into SONiC from another NOS's grub,
|
|
# we now install a grub for SONiC.
|
|
if [ -n "$onie_platform" ] && [ -n "$migration" ]; then
|
|
|
|
grub_bin=$(ls /host/image-$sonic_version/platform/x86_64-grub/grub-pc-bin*.deb 2> /dev/null)
|
|
if [ -z "$grub_bin" ]; then
|
|
echo "Unable to locate grub package !" >> /etc/migration.log
|
|
firsttime_exit
|
|
fi
|
|
|
|
dpkg -i $grub_bin > /dev/null 2>&1
|
|
if [ $? != 0 ]; then
|
|
echo "Unable to install grub package !" >> /etc/migration.log
|
|
firsttime_exit
|
|
fi
|
|
|
|
# Determine the block device to install grub
|
|
sonic_dev=$(blkid | grep SONiC-OS | head -n 1 | awk '{print $1}' | sed -e 's/[0-9]:.*$//')
|
|
if [ -z "$sonic_dev" ]; then
|
|
echo "Unable to determine sonic partition !" >> /etc/migration.log
|
|
firsttime_exit
|
|
fi
|
|
|
|
grub-install --boot-directory=/host --recheck $sonic_dev 2>/dev/null
|
|
if [ $? != 0 ]; then
|
|
echo "grub install failed !" >> /etc/migration.log
|
|
firsttime_exit
|
|
fi
|
|
|
|
# The SONiC "raw" build mode has already generated a proto grub.cfg
|
|
# as part of the migration. Platform specific constants need to be
|
|
# retrieved from installer.conf (if present) and assigned.
|
|
. /usr/share/sonic/device/$platform/installer.conf
|
|
|
|
if [ ! -z "$CONSOLE_PORT" ]; then
|
|
field="\-\-port"
|
|
string=$(grep $field /host/grub.cfg)
|
|
value_extract $string $field
|
|
console_port=$value
|
|
if [ ! -z "$console_port" ] && [ "$console_port" != "$CONSOLE_PORT" ]; then
|
|
sed -i -e "s/\-\-port=$console_port/\-\-port=$CONSOLE_PORT/g" /host/grub.cfg
|
|
fi
|
|
echo "grub.cfg console port=$console_port & installer.conf CONSOLE_PORT=$CONSOLE_PORT" >> /etc/migration.log
|
|
fi
|
|
|
|
if [ ! -z "$CONSOLE_DEV" ]; then
|
|
field="console"
|
|
string=$(grep $field /host/grub.cfg)
|
|
value_extract $string $field
|
|
console_dev_name=$(echo $value | sed -e "s/^.*=//" -e "s/,.*//")
|
|
console_dev="${console_dev_name#ttyS}"
|
|
if [ "$console_dev" != "$CONSOLE_DEV" ]; then
|
|
sed -i -e "s/console=ttyS$console_dev/console=ttyS$CONSOLE_DEV/g" /host/grub.cfg
|
|
fi
|
|
echo "grub.cfg console dev=$console_dev & installer.conf CONSOLE_DEV=$CONSOLE_DEV" >> /etc/migration.log
|
|
fi
|
|
|
|
if [ ! -z "$VAR_LOG_SIZE" ]; then
|
|
field="var_log_size"
|
|
string=$(grep $field /host/grub.cfg)
|
|
value_extract $string $field
|
|
var_log_size=$value
|
|
if [ ! -z "$var_log_size" ] && [ "$var_log_size" != "$VAR_LOG_SIZE" ]; then
|
|
sed -i -e "s/var_log_size=$var_log_size/var_log_size=$VAR_LOG_SIZE/g" /host/grub.cfg
|
|
fi
|
|
echo "grub.cfg var_log_size=$var_log_size & installer.conf VAR_LOG_SIZE=$VAR_LOG_SIZE" >> /etc/migration.log
|
|
fi
|
|
|
|
# Set the root based on the label
|
|
sonic_root=$(blkid | grep SONiC-OS | head -n 1 | awk '{print $1}' | sed -e 's/:.*$//')
|
|
sonic_root=$(echo "$sonic_root" | sed 's/\//\\\//g')
|
|
sed -i -e "s/%%SONIC_ROOT%%/$sonic_root/g" /host/grub.cfg
|
|
|
|
# Add the Diag and ONIE entries
|
|
mount $onie_dev /mnt/onie-boot
|
|
. /mnt/onie-boot/onie/grub.d/50_onie_grub >> /host/grub.cfg
|
|
umount /mnt/onie-boot
|
|
|
|
# Initialize the SONiC's grub config
|
|
mv /host/grub.cfg /host/grub/grub.cfg
|
|
fi
|
|
|
|
rm /host/image-$sonic_version/platform/firsttime
|
|
fi
|
|
|
|
exit 0
|