2017-01-29 13:33:33 -06:00
|
|
|
#!/bin/bash
|
|
|
|
## This script is to automate loading of vendor specific docker images
|
|
|
|
## and instalation of configuration files and vendor specific packages
|
|
|
|
## to debian file system.
|
|
|
|
##
|
|
|
|
## USAGE:
|
2017-02-27 15:08:41 -06:00
|
|
|
## ./sonic_debian_extension.sh FILESYSTEM_ROOT PLATFORM_DIR
|
2017-01-29 13:33:33 -06:00
|
|
|
## PARAMETERS:
|
|
|
|
## FILESYSTEM_ROOT
|
|
|
|
## Path to debian file system root directory
|
|
|
|
|
|
|
|
FILESYSTEM_ROOT=$1
|
|
|
|
[ -n "$FILESYSTEM_ROOT" ] || {
|
|
|
|
echo "Error: no or empty FILESYSTEM_ROOT argument"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2017-02-27 15:08:41 -06:00
|
|
|
PLATFORM_DIR=$2
|
|
|
|
[ -n "$PLATFORM_DIR" ] || {
|
|
|
|
echo "Error: no or empty PLATFORM_DIR argument"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
## Enable debug output for script
|
|
|
|
set -x -e
|
|
|
|
|
|
|
|
. functions.sh
|
|
|
|
BUILD_TEMPLATES=files/build_templates
|
|
|
|
IMAGE_CONFIGS=files/image_config
|
|
|
|
|
|
|
|
clean_sys() {
|
|
|
|
sudo umount $FILESYSTEM_ROOT/sys/fs/cgroup/* \
|
|
|
|
$FILESYSTEM_ROOT/sys/fs/cgroup \
|
|
|
|
$FILESYSTEM_ROOT/sys || true
|
|
|
|
}
|
|
|
|
trap_push clean_sys
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT mount sysfs /sys -t sysfs
|
|
|
|
|
|
|
|
sudo chroot $FILESYSTEM_ROOT service docker start
|
|
|
|
sudo chroot $FILESYSTEM_ROOT docker version
|
|
|
|
|
|
|
|
# Apply apt configuration files
|
|
|
|
sudo cp $IMAGE_CONFIGS/apt/sources.list $FILESYSTEM_ROOT/etc/apt/
|
|
|
|
sudo cp -R $IMAGE_CONFIGS/apt/sources.list.d/ $FILESYSTEM_ROOT/etc/apt/
|
|
|
|
cat $IMAGE_CONFIGS/apt/sonic-dev.gpg.key | sudo LANG=C chroot $FILESYSTEM_ROOT apt-key add -
|
|
|
|
|
2017-02-27 02:13:36 -06:00
|
|
|
# Update apt's snapshot of its repos
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get update
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
# Apply environtment configuration files
|
|
|
|
sudo cp $IMAGE_CONFIGS/environment/environment $FILESYSTEM_ROOT/etc/
|
|
|
|
sudo cp $IMAGE_CONFIGS/environment/motd $FILESYSTEM_ROOT/etc/
|
|
|
|
|
2017-02-27 02:13:36 -06:00
|
|
|
# Create all needed directories
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic/
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/usr/share/sonic/templates/
|
|
|
|
|
|
|
|
# Install dependencies for SONiC config engine
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install \
|
|
|
|
python-lxml \
|
|
|
|
python-jinja2 \
|
|
|
|
python-netaddr \
|
|
|
|
python-ipaddr \
|
|
|
|
python-yaml
|
|
|
|
|
|
|
|
# Install SONiC config engine
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i {{config_engine}}
|
|
|
|
|
|
|
|
# Install SONiC Utilities (and its dependencies via 'apt-get -y install -f')
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/python-sonic-utilities_*.deb || \
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
|
|
|
|
|
|
|
|
# Install SONiC Device Data (and its dependencies via 'apt-get -y install -f')
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/sonic-device-data_*.deb || \
|
|
|
|
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
# Copy NTP configuration files and templates
|
|
|
|
sudo cp $IMAGE_CONFIGS/ntp/ntp-config.service $FILESYSTEM_ROOT/etc/systemd/system/
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable ntp-config.service
|
|
|
|
sudo cp $IMAGE_CONFIGS/ntp/ntp-config.sh $FILESYSTEM_ROOT/usr/bin/
|
2017-02-18 19:50:29 -06:00
|
|
|
sudo cp $IMAGE_CONFIGS/ntp/ntp.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/
|
2017-01-29 13:33:33 -06:00
|
|
|
sudo cp $IMAGE_CONFIGS/ntp/ntp.yml $FILESYSTEM_ROOT/etc/sonic/
|
|
|
|
|
|
|
|
# Copy rsyslog configuration files and templates
|
|
|
|
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable rsyslog-config.service
|
|
|
|
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/
|
2017-02-18 19:50:29 -06:00
|
|
|
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/
|
2017-01-29 13:33:33 -06:00
|
|
|
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.yml $FILESYSTEM_ROOT/etc/sonic/
|
|
|
|
sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/
|
|
|
|
|
|
|
|
# Copy interfaces configuration files and templates
|
|
|
|
sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.service $FILESYSTEM_ROOT/etc/systemd/system/
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable interfaces-config.service
|
|
|
|
sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/
|
2017-02-18 19:50:29 -06:00
|
|
|
sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/
|
2017-01-29 13:33:33 -06:00
|
|
|
|
2017-02-17 15:47:01 -06:00
|
|
|
# Copy initial interfaces configuration file, will be overwritten on first boot
|
|
|
|
sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network
|
|
|
|
|
|
|
|
# Copy updategraph script and service file
|
|
|
|
sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service
|
|
|
|
sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/
|
|
|
|
{% if enable_dhcp_graph_service == "y" %}
|
|
|
|
sudo bash -c "echo enabled=true > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
|
|
|
sudo bash -c "echo src=dhcp >> $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
|
|
|
sudo bash -c "echo dhcp_as_static=true >> $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
|
|
|
{% else %}
|
|
|
|
sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
|
|
|
{% endif %}
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
# Copy SNMP configuration files
|
|
|
|
sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/
|
|
|
|
|
2017-02-02 22:34:34 -06:00
|
|
|
# Generate build version file
|
2017-01-29 13:33:33 -06:00
|
|
|
export git_revision=$(git rev-parse --short HEAD)
|
|
|
|
export debian_version=`cat $FILESYSTEM_ROOT/etc/debian_version`
|
|
|
|
export kernel_version={{kversion}}
|
2017-02-02 22:34:34 -06:00
|
|
|
j2 $BUILD_TEMPLATES/sonic_version.yml.j2 > sonic_version.yml
|
|
|
|
sudo mv sonic_version.yml $FILESYSTEM_ROOT/etc/sonic/
|
2017-01-29 13:33:33 -06:00
|
|
|
|
|
|
|
# Copy sudoers configuration file
|
|
|
|
sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/
|
|
|
|
|
2017-02-10 09:39:05 -06:00
|
|
|
## Install package without starting service
|
|
|
|
## ref: https://wiki.debian.org/chroot
|
|
|
|
sudo tee -a $FILESYSTEM_ROOT/usr/sbin/policy-rc.d > /dev/null <<EOF
|
|
|
|
#!/bin/sh
|
|
|
|
exit 101
|
|
|
|
EOF
|
|
|
|
sudo chmod a+x $FILESYSTEM_ROOT/usr/sbin/policy-rc.d
|
|
|
|
|
2017-02-27 15:08:41 -06:00
|
|
|
{% if installer_debs.strip() -%}
|
2017-01-29 13:33:33 -06:00
|
|
|
{% for deb in installer_debs.strip().split(' ') -%}
|
2017-02-10 09:39:05 -06:00
|
|
|
if [ $sonic_asic_platform == "mellanox" ]; then
|
2017-01-29 13:33:33 -06:00
|
|
|
sudo dpkg --extract {{deb}} $FILESYSTEM_ROOT
|
2017-02-10 09:39:05 -06:00
|
|
|
else
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i {{deb}} || sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f
|
|
|
|
fi
|
2017-01-29 13:33:33 -06:00
|
|
|
{% endfor %}
|
2017-02-27 15:08:41 -06:00
|
|
|
{% endif %}
|
2017-02-10 09:39:05 -06:00
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
## Run depmod command for target kernel modules
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT depmod -a {{kversion}}
|
2017-02-27 15:08:41 -06:00
|
|
|
|
|
|
|
## download all dependency packages for platform debian packages
|
|
|
|
{% if lazy_installer_debs.strip() -%}
|
|
|
|
{% for file in lazy_installer_debs.strip().split(' ') -%}
|
|
|
|
|
|
|
|
{% set dev = file.split('@')[0] -%}
|
|
|
|
{% set deb = file.split('@')[1] -%}
|
|
|
|
{% set debfilename = deb.split('/')|last -%}
|
|
|
|
{% set debname = debfilename.split('_')|first -%}
|
|
|
|
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -i {{deb}} || sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f --download-only
|
|
|
|
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}
|
|
|
|
sudo cp {{ deb }} $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/
|
|
|
|
for f in `find $FILESYSTEM_ROOT/var/cache/apt/archives -name "*.deb"`; do
|
|
|
|
sudo mv $f $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/
|
|
|
|
done
|
|
|
|
|
|
|
|
sudo dpkg --root=$FILESYSTEM_ROOT -P {{ debname }}
|
|
|
|
|
|
|
|
{% endfor %}
|
2017-01-29 13:33:33 -06:00
|
|
|
{% endif %}
|
2017-02-27 15:08:41 -06:00
|
|
|
|
|
|
|
sudo rm -f $FILESYSTEM_ROOT/usr/sbin/policy-rc.d
|
|
|
|
|
|
|
|
## copy platform rc.local
|
|
|
|
sudo cp $IMAGE_CONFIGS/platform/rc.local $FILESYSTEM_ROOT/etc/
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
{% if installer_images.strip() -%}
|
|
|
|
{% for image in installer_images.strip().split(' ') -%}
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT docker load < {{image}}
|
|
|
|
{% endfor %}
|
|
|
|
sudo chroot $FILESYSTEM_ROOT service docker stop
|
|
|
|
{% for script in installer_start_scrips.split(' ') -%}
|
|
|
|
sudo cp {{script}} $FILESYSTEM_ROOT/usr/bin/
|
|
|
|
{% endfor %}
|
|
|
|
{% for service in installer_services.split(' ') -%}
|
2017-03-01 12:57:35 -06:00
|
|
|
if [ -f {{service}} ]; then
|
|
|
|
sudo cp {{service}} $FILESYSTEM_ROOT/etc/systemd/system/
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable {{service}}
|
|
|
|
fi
|
2017-01-29 13:33:33 -06:00
|
|
|
{% endfor %}
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys
|
|
|
|
{% endif %}
|
|
|
|
|
2017-02-07 02:33:20 -06:00
|
|
|
{% for file in installer_extra_files.split(' ') -%}
|
|
|
|
{% if file.strip() -%}
|
|
|
|
{% set src = file.split(':')[0] -%}
|
|
|
|
{% set dst = file.split(':')[1] -%}
|
|
|
|
sudo cp {{src}} $FILESYSTEM_ROOT/{{dst}}
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor -%}
|
|
|
|
|